]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Fix line endings per .gitattributes
authorTravis Cross <tc@traviscross.com>
Fri, 8 Aug 2014 15:24:42 +0000 (15:24 +0000)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 8 Aug 2014 21:13:22 +0000 (02:13 +0500)
199 files changed:
htdocs/license.txt
libs/esl/managed/esl_wrap.2010.cpp
libs/freetdm/src/isdn/5ESSStateNT.c
libs/freetdm/src/isdn/5ESSStateTE.c
libs/freetdm/src/isdn/5ESSmes.c
libs/ilbc/localtests/iLBC_test.txt
libs/libzrtp/include/zrtp_config_win.h
libs/libzrtp/projects/symbian/DelayRuner.cpp
libs/libzrtp/projects/symbian/DelayRuner.h
libs/libzrtp/projects/symbian/zrtp_iface_symb.cpp
libs/libzrtp/third_party/bnlib/bntest16.c
libs/libzrtp/third_party/bnlib/bntest32.c
libs/libzrtp/third_party/bnlib/bntest64.c
libs/silk/interface/SKP_Silk_SDK_API.h
libs/silk/interface/SKP_Silk_control.h
libs/silk/interface/SKP_Silk_errors.h
libs/silk/interface/SKP_Silk_typedef.h
libs/silk/readme.txt
libs/silk/src/SKP_Silk_A2NLSF.c
libs/silk/src/SKP_Silk_CNG.c
libs/silk/src/SKP_Silk_HP_variable_cutoff_FIX.c
libs/silk/src/SKP_Silk_Inlines.h
libs/silk/src/SKP_Silk_LBRR_reset.c
libs/silk/src/SKP_Silk_LPC_inv_pred_gain.c
libs/silk/src/SKP_Silk_LPC_synthesis_filter.c
libs/silk/src/SKP_Silk_LPC_synthesis_order16.c
libs/silk/src/SKP_Silk_LP_variable_cutoff.c
libs/silk/src/SKP_Silk_LSF_cos_table.c
libs/silk/src/SKP_Silk_LTP_analysis_filter_FIX.c
libs/silk/src/SKP_Silk_LTP_scale_ctrl_FIX.c
libs/silk/src/SKP_Silk_MA.c
libs/silk/src/SKP_Silk_NLSF2A.c
libs/silk/src/SKP_Silk_NLSF2A_stable.c
libs/silk/src/SKP_Silk_NLSF_MSVQ_decode.c
libs/silk/src/SKP_Silk_NLSF_MSVQ_encode_FIX.c
libs/silk/src/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c
libs/silk/src/SKP_Silk_NLSF_VQ_sum_error_FIX.c
libs/silk/src/SKP_Silk_NLSF_VQ_weights_laroia.c
libs/silk/src/SKP_Silk_NLSF_stabilize.c
libs/silk/src/SKP_Silk_NSQ.c
libs/silk/src/SKP_Silk_NSQ_del_dec.c
libs/silk/src/SKP_Silk_PLC.c
libs/silk/src/SKP_Silk_PLC.h
libs/silk/src/SKP_Silk_SigProc_FIX.h
libs/silk/src/SKP_Silk_VAD.c
libs/silk/src/SKP_Silk_VQ_nearest_neighbor_FIX.c
libs/silk/src/SKP_Silk_ana_filt_bank_1.c
libs/silk/src/SKP_Silk_apply_sine_window_new.c
libs/silk/src/SKP_Silk_array_maxabs.c
libs/silk/src/SKP_Silk_autocorr.c
libs/silk/src/SKP_Silk_biquad.c
libs/silk/src/SKP_Silk_biquad_alt.c
libs/silk/src/SKP_Silk_burg_modified.c
libs/silk/src/SKP_Silk_bwexpander.c
libs/silk/src/SKP_Silk_bwexpander_32.c
libs/silk/src/SKP_Silk_code_signs.c
libs/silk/src/SKP_Silk_common_pitch_est_defines.h
libs/silk/src/SKP_Silk_control_audio_bandwidth.c
libs/silk/src/SKP_Silk_control_codec_FIX.c
libs/silk/src/SKP_Silk_corrMatrix_FIX.c
libs/silk/src/SKP_Silk_create_init_destroy.c
libs/silk/src/SKP_Silk_dec_API.c
libs/silk/src/SKP_Silk_decode_core.c
libs/silk/src/SKP_Silk_decode_frame.c
libs/silk/src/SKP_Silk_decode_parameters.c
libs/silk/src/SKP_Silk_decode_pitch.c
libs/silk/src/SKP_Silk_decode_pulses.c
libs/silk/src/SKP_Silk_decoder_set_fs.c
libs/silk/src/SKP_Silk_define.h
libs/silk/src/SKP_Silk_detect_SWB_input.c
libs/silk/src/SKP_Silk_enc_API.c
libs/silk/src/SKP_Silk_encode_frame_FIX.c
libs/silk/src/SKP_Silk_encode_parameters.c
libs/silk/src/SKP_Silk_encode_pulses.c
libs/silk/src/SKP_Silk_find_LPC_FIX.c
libs/silk/src/SKP_Silk_find_LTP_FIX.c
libs/silk/src/SKP_Silk_find_pitch_lags_FIX.c
libs/silk/src/SKP_Silk_find_pred_coefs_FIX.c
libs/silk/src/SKP_Silk_gain_quant.c
libs/silk/src/SKP_Silk_init_encoder_FIX.c
libs/silk/src/SKP_Silk_inner_prod_aligned.c
libs/silk/src/SKP_Silk_interpolate.c
libs/silk/src/SKP_Silk_k2a.c
libs/silk/src/SKP_Silk_k2a_Q16.c
libs/silk/src/SKP_Silk_lin2log.c
libs/silk/src/SKP_Silk_log2lin.c
libs/silk/src/SKP_Silk_macros.h
libs/silk/src/SKP_Silk_main.h
libs/silk/src/SKP_Silk_main_FIX.h
libs/silk/src/SKP_Silk_noise_shape_analysis_FIX.c
libs/silk/src/SKP_Silk_pitch_analysis_core.c
libs/silk/src/SKP_Silk_pitch_est_defines.h
libs/silk/src/SKP_Silk_pitch_est_tables.c
libs/silk/src/SKP_Silk_prefilter_FIX.c
libs/silk/src/SKP_Silk_process_NLSFs_FIX.c
libs/silk/src/SKP_Silk_process_gains_FIX.c
libs/silk/src/SKP_Silk_quant_LTP_gains_FIX.c
libs/silk/src/SKP_Silk_range_coder.c
libs/silk/src/SKP_Silk_regularize_correlations_FIX.c
libs/silk/src/SKP_Silk_resampler.c
libs/silk/src/SKP_Silk_resampler_down2.c
libs/silk/src/SKP_Silk_resampler_down2_3.c
libs/silk/src/SKP_Silk_resampler_down3.c
libs/silk/src/SKP_Silk_resampler_private.h
libs/silk/src/SKP_Silk_resampler_private_AR2.c
libs/silk/src/SKP_Silk_resampler_private_ARMA4.c
libs/silk/src/SKP_Silk_resampler_private_IIR_FIR.c
libs/silk/src/SKP_Silk_resampler_private_copy.c
libs/silk/src/SKP_Silk_resampler_private_down4.c
libs/silk/src/SKP_Silk_resampler_private_down_FIR.c
libs/silk/src/SKP_Silk_resampler_private_up2_HQ.c
libs/silk/src/SKP_Silk_resampler_private_up4.c
libs/silk/src/SKP_Silk_resampler_rom.c
libs/silk/src/SKP_Silk_resampler_rom.h
libs/silk/src/SKP_Silk_resampler_structs.h
libs/silk/src/SKP_Silk_resampler_up2.c
libs/silk/src/SKP_Silk_residual_energy16_FIX.c
libs/silk/src/SKP_Silk_residual_energy_FIX.c
libs/silk/src/SKP_Silk_scale_copy_vector16.c
libs/silk/src/SKP_Silk_scale_vector.c
libs/silk/src/SKP_Silk_schur.c
libs/silk/src/SKP_Silk_schur64.c
libs/silk/src/SKP_Silk_setup_complexity.h
libs/silk/src/SKP_Silk_shell_coder.c
libs/silk/src/SKP_Silk_sigm_Q15.c
libs/silk/src/SKP_Silk_solve_LS_FIX.c
libs/silk/src/SKP_Silk_sort.c
libs/silk/src/SKP_Silk_structs.h
libs/silk/src/SKP_Silk_structs_FIX.h
libs/silk/src/SKP_Silk_sum_sqr_shift.c
libs/silk/src/SKP_Silk_tables.h
libs/silk/src/SKP_Silk_tables_LTP.c
libs/silk/src/SKP_Silk_tables_NLSF_CB0_10.c
libs/silk/src/SKP_Silk_tables_NLSF_CB0_10.h
libs/silk/src/SKP_Silk_tables_NLSF_CB0_16.c
libs/silk/src/SKP_Silk_tables_NLSF_CB0_16.h
libs/silk/src/SKP_Silk_tables_NLSF_CB1_10.c
libs/silk/src/SKP_Silk_tables_NLSF_CB1_10.h
libs/silk/src/SKP_Silk_tables_NLSF_CB1_16.c
libs/silk/src/SKP_Silk_tables_NLSF_CB1_16.h
libs/silk/src/SKP_Silk_tables_gain.c
libs/silk/src/SKP_Silk_tables_other.c
libs/silk/src/SKP_Silk_tables_pitch_lag.c
libs/silk/src/SKP_Silk_tables_pulses_per_block.c
libs/silk/src/SKP_Silk_tables_sign.c
libs/silk/src/SKP_Silk_tables_type_offset.c
libs/silk/src/SKP_Silk_tuning_parameters.h
libs/silk/src/SKP_Silk_warped_autocorrelation_FIX.c
libs/silk/test/Decoder.c
libs/silk/test/Encoder.c
libs/silk/test/signalCompare.c
libs/silk/test_vectors/How to use the test vectors.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/10052.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/own0.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/own5.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/own6.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/own8.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test1.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test12.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test1a.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test21.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test22.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test23.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test24.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test25.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test26.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test27.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test28.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test29.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test3.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test30.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test31.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test32.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test33.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test34.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test35.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test36.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test37.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test38.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test39.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test40.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test41.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test42.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test5.txt
libs/sofia-sip/libsofia-sip-ua/sip/tests/test8.txt
libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_errno.h
libs/sofia-sip/open_c/config.h.in
libs/win32/celt/config.h
libs/win32/celt/float_cast.h
libs/win32/libshout/compat.h
libs/win32/libshout/shout/shout.h
libs/win32/openssl/buildinf.h
libs/win32/openssl/opensslconf.h
libs/xmlrpc-c/Windows/ReadMeOld.txt
libs/xmlrpc-c/Windows/UsingCURLinWin32.txt
libs/xmlrpc-c/Windows/UsingProxyDSP.txt
libs/xmlrpc-c/src/test/http-req-simple.txt
src/mod/applications/mod_expr/license.txt
src/mod/applications/mod_expr/readme.txt

index 12d609e122fcffd7da65e119c167535e03b81cd9..2111a50a1f4caf353aa96ac23017afdaffc54e31 100644 (file)
@@ -1,10 +1,10 @@
-Copyright (c) 2005, Fabricio Zuardi\r
-All rights reserved.\r
-\r
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\r
-\r
-    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\r
-    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\r
-    * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\r
-\r
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+Copyright (c) 2005, Fabricio Zuardi
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+    * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
index 64536d6987198a7f044d3a1308fbe9303297c7e8..ae06c6ea5704e5a73e6d53e917a457ea5051ac05 100644 (file)
-/* ----------------------------------------------------------------------------\r
- * This file was automatically generated by SWIG (http://www.swig.org).\r
- * Version 2.0.1\r
- * \r
- * This file is not intended to be easily readable and contains a number of \r
- * coding conventions designed to improve portability and efficiency. Do not make\r
- * changes to this file unless you know what you are doing--modify the SWIG \r
- * interface file instead. \r
- * ----------------------------------------------------------------------------- */\r
-\r
-#define SWIGCSHARP\r
-\r
-\r
-#ifdef __cplusplus\r
-/* SwigValueWrapper is described in swig.swg */\r
-template<typename T> class SwigValueWrapper {\r
-  struct SwigMovePointer {\r
-    T *ptr;\r
-    SwigMovePointer(T *p) : ptr(p) { }\r
-    ~SwigMovePointer() { delete ptr; }\r
-    SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }\r
-  } pointer;\r
-  SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);\r
-  SwigValueWrapper(const SwigValueWrapper<T>& rhs);\r
-public:\r
-  SwigValueWrapper() : pointer(0) { }\r
-  SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }\r
-  operator T&() const { return *pointer.ptr; }\r
-  T *operator&() { return pointer.ptr; }\r
-};\r
-\r
-template <typename T> T SwigValueInit() {\r
-  return T();\r
-}\r
-#endif\r
-\r
-/* -----------------------------------------------------------------------------\r
- *  This section contains generic SWIG labels for method/variable\r
- *  declarations/attributes, and other compiler dependent labels.\r
- * ----------------------------------------------------------------------------- */\r
-\r
-/* template workaround for compilers that cannot correctly implement the C++ standard */\r
-#ifndef SWIGTEMPLATEDISAMBIGUATOR\r
-# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)\r
-#  define SWIGTEMPLATEDISAMBIGUATOR template\r
-# elif defined(__HP_aCC)\r
-/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */\r
-/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */\r
-#  define SWIGTEMPLATEDISAMBIGUATOR template\r
-# else\r
-#  define SWIGTEMPLATEDISAMBIGUATOR\r
-# endif\r
-#endif\r
-\r
-/* inline attribute */\r
-#ifndef SWIGINLINE\r
-# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))\r
-#   define SWIGINLINE inline\r
-# else\r
-#   define SWIGINLINE\r
-# endif\r
-#endif\r
-\r
-/* attribute recognised by some compilers to avoid 'unused' warnings */\r
-#ifndef SWIGUNUSED\r
-# if defined(__GNUC__)\r
-#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))\r
-#     define SWIGUNUSED __attribute__ ((__unused__)) \r
-#   else\r
-#     define SWIGUNUSED\r
-#   endif\r
-# elif defined(__ICC)\r
-#   define SWIGUNUSED __attribute__ ((__unused__)) \r
-# else\r
-#   define SWIGUNUSED \r
-# endif\r
-#endif\r
-\r
-#ifndef SWIG_MSC_UNSUPPRESS_4505\r
-# if defined(_MSC_VER)\r
-#   pragma warning(disable : 4505) /* unreferenced local function has been removed */\r
-# endif \r
-#endif\r
-\r
-#ifndef SWIGUNUSEDPARM\r
-# ifdef __cplusplus\r
-#   define SWIGUNUSEDPARM(p)\r
-# else\r
-#   define SWIGUNUSEDPARM(p) p SWIGUNUSED \r
-# endif\r
-#endif\r
-\r
-/* internal SWIG method */\r
-#ifndef SWIGINTERN\r
-# define SWIGINTERN static SWIGUNUSED\r
-#endif\r
-\r
-/* internal inline SWIG method */\r
-#ifndef SWIGINTERNINLINE\r
-# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE\r
-#endif\r
-\r
-/* exporting methods */\r
-#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)\r
-#  ifndef GCC_HASCLASSVISIBILITY\r
-#    define GCC_HASCLASSVISIBILITY\r
-#  endif\r
-#endif\r
-\r
-#ifndef SWIGEXPORT\r
-# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)\r
-#   if defined(STATIC_LINKED)\r
-#     define SWIGEXPORT\r
-#   else\r
-#     define SWIGEXPORT __declspec(dllexport)\r
-#   endif\r
-# else\r
-#   if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)\r
-#     define SWIGEXPORT __attribute__ ((visibility("default")))\r
-#   else\r
-#     define SWIGEXPORT\r
-#   endif\r
-# endif\r
-#endif\r
-\r
-/* calling conventions for Windows */\r
-#ifndef SWIGSTDCALL\r
-# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)\r
-#   define SWIGSTDCALL __stdcall\r
-# else\r
-#   define SWIGSTDCALL\r
-# endif \r
-#endif\r
-\r
-/* Deal with Microsoft's attempt at deprecating C standard runtime functions */\r
-#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)\r
-# define _CRT_SECURE_NO_DEPRECATE\r
-#endif\r
-\r
-/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */\r
-#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)\r
-# define _SCL_SECURE_NO_DEPRECATE\r
-#endif\r
-\r
-\r
-\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <stdio.h>\r
-\r
-\r
-/* Support for throwing C# exceptions from C/C++. There are two types: \r
- * Exceptions that take a message and ArgumentExceptions that take a message and a parameter name. */\r
-typedef enum {\r
-  SWIG_CSharpApplicationException,\r
-  SWIG_CSharpArithmeticException,\r
-  SWIG_CSharpDivideByZeroException,\r
-  SWIG_CSharpIndexOutOfRangeException,\r
-  SWIG_CSharpInvalidCastException,\r
-  SWIG_CSharpInvalidOperationException,\r
-  SWIG_CSharpIOException,\r
-  SWIG_CSharpNullReferenceException,\r
-  SWIG_CSharpOutOfMemoryException,\r
-  SWIG_CSharpOverflowException,\r
-  SWIG_CSharpSystemException\r
-} SWIG_CSharpExceptionCodes;\r
-\r
-typedef enum {\r
-  SWIG_CSharpArgumentException,\r
-  SWIG_CSharpArgumentNullException,\r
-  SWIG_CSharpArgumentOutOfRangeException\r
-} SWIG_CSharpExceptionArgumentCodes;\r
-\r
-typedef void (SWIGSTDCALL* SWIG_CSharpExceptionCallback_t)(const char *);\r
-typedef void (SWIGSTDCALL* SWIG_CSharpExceptionArgumentCallback_t)(const char *, const char *);\r
-\r
-typedef struct {\r
-  SWIG_CSharpExceptionCodes code;\r
-  SWIG_CSharpExceptionCallback_t callback;\r
-} SWIG_CSharpException_t;\r
-\r
-typedef struct {\r
-  SWIG_CSharpExceptionArgumentCodes code;\r
-  SWIG_CSharpExceptionArgumentCallback_t callback;\r
-} SWIG_CSharpExceptionArgument_t;\r
-\r
-static SWIG_CSharpException_t SWIG_csharp_exceptions[] = {\r
-  { SWIG_CSharpApplicationException, NULL },\r
-  { SWIG_CSharpArithmeticException, NULL },\r
-  { SWIG_CSharpDivideByZeroException, NULL },\r
-  { SWIG_CSharpIndexOutOfRangeException, NULL },\r
-  { SWIG_CSharpInvalidCastException, NULL },\r
-  { SWIG_CSharpInvalidOperationException, NULL },\r
-  { SWIG_CSharpIOException, NULL },\r
-  { SWIG_CSharpNullReferenceException, NULL },\r
-  { SWIG_CSharpOutOfMemoryException, NULL },\r
-  { SWIG_CSharpOverflowException, NULL },\r
-  { SWIG_CSharpSystemException, NULL }\r
-};\r
-\r
-static SWIG_CSharpExceptionArgument_t SWIG_csharp_exceptions_argument[] = {\r
-  { SWIG_CSharpArgumentException, NULL },\r
-  { SWIG_CSharpArgumentNullException, NULL },\r
-  { SWIG_CSharpArgumentOutOfRangeException, NULL }\r
-};\r
-\r
-static void SWIGUNUSED SWIG_CSharpSetPendingException(SWIG_CSharpExceptionCodes code, const char *msg) {\r
-  SWIG_CSharpExceptionCallback_t callback = SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback;\r
-  if ((size_t)code < sizeof(SWIG_csharp_exceptions)/sizeof(SWIG_CSharpException_t)) {\r
-    callback = SWIG_csharp_exceptions[code].callback;\r
-  }\r
-  callback(msg);\r
-}\r
-\r
-static void SWIGUNUSED SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpExceptionArgumentCodes code, const char *msg, const char *param_name) {\r
-  SWIG_CSharpExceptionArgumentCallback_t callback = SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback;\r
-  if ((size_t)code < sizeof(SWIG_csharp_exceptions_argument)/sizeof(SWIG_CSharpExceptionArgument_t)) {\r
-    callback = SWIG_csharp_exceptions_argument[code].callback;\r
-  }\r
-  callback(msg, param_name);\r
-}\r
-\r
-\r
-#ifdef __cplusplus\r
-extern "C" \r
-#endif\r
-SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionCallbacks_ESL(\r
-                                                SWIG_CSharpExceptionCallback_t applicationCallback,\r
-                                                SWIG_CSharpExceptionCallback_t arithmeticCallback,\r
-                                                SWIG_CSharpExceptionCallback_t divideByZeroCallback, \r
-                                                SWIG_CSharpExceptionCallback_t indexOutOfRangeCallback, \r
-                                                SWIG_CSharpExceptionCallback_t invalidCastCallback,\r
-                                                SWIG_CSharpExceptionCallback_t invalidOperationCallback,\r
-                                                SWIG_CSharpExceptionCallback_t ioCallback,\r
-                                                SWIG_CSharpExceptionCallback_t nullReferenceCallback,\r
-                                                SWIG_CSharpExceptionCallback_t outOfMemoryCallback, \r
-                                                SWIG_CSharpExceptionCallback_t overflowCallback, \r
-                                                SWIG_CSharpExceptionCallback_t systemCallback) {\r
-  SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback = applicationCallback;\r
-  SWIG_csharp_exceptions[SWIG_CSharpArithmeticException].callback = arithmeticCallback;\r
-  SWIG_csharp_exceptions[SWIG_CSharpDivideByZeroException].callback = divideByZeroCallback;\r
-  SWIG_csharp_exceptions[SWIG_CSharpIndexOutOfRangeException].callback = indexOutOfRangeCallback;\r
-  SWIG_csharp_exceptions[SWIG_CSharpInvalidCastException].callback = invalidCastCallback;\r
-  SWIG_csharp_exceptions[SWIG_CSharpInvalidOperationException].callback = invalidOperationCallback;\r
-  SWIG_csharp_exceptions[SWIG_CSharpIOException].callback = ioCallback;\r
-  SWIG_csharp_exceptions[SWIG_CSharpNullReferenceException].callback = nullReferenceCallback;\r
-  SWIG_csharp_exceptions[SWIG_CSharpOutOfMemoryException].callback = outOfMemoryCallback;\r
-  SWIG_csharp_exceptions[SWIG_CSharpOverflowException].callback = overflowCallback;\r
-  SWIG_csharp_exceptions[SWIG_CSharpSystemException].callback = systemCallback;\r
-}\r
-\r
-#ifdef __cplusplus\r
-extern "C" \r
-#endif\r
-SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_ESL(\r
-                                                SWIG_CSharpExceptionArgumentCallback_t argumentCallback,\r
-                                                SWIG_CSharpExceptionArgumentCallback_t argumentNullCallback,\r
-                                                SWIG_CSharpExceptionArgumentCallback_t argumentOutOfRangeCallback) {\r
-  SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback = argumentCallback;\r
-  SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentNullException].callback = argumentNullCallback;\r
-  SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentOutOfRangeException].callback = argumentOutOfRangeCallback;\r
-}\r
-\r
-\r
-/* Callback for returning strings to C# without leaking memory */\r
-typedef char * (SWIGSTDCALL* SWIG_CSharpStringHelperCallback)(const char *);\r
-static SWIG_CSharpStringHelperCallback SWIG_csharp_string_callback = NULL;\r
-\r
-\r
-#ifdef __cplusplus\r
-extern "C" \r
-#endif\r
-SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_ESL(SWIG_CSharpStringHelperCallback callback) {\r
-  SWIG_csharp_string_callback = callback;\r
-}\r
-\r
-\r
-/* Contract support */\r
-\r
-#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, msg, ""); return nullreturn; } else\r
-\r
-\r
-#include "esl.h"\r
-#include "esl_oop.h"\r
-\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-SWIGEXPORT void SWIGSTDCALL CSharp_ESLevent_Event_set(void * jarg1, void * jarg2) {\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  esl_event_t *arg2 = (esl_event_t *) 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  arg2 = (esl_event_t *)jarg2; \r
-  if (arg1) (arg1)->event = arg2;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLevent_Event_get(void * jarg1) {\r
-  void * jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  esl_event_t *result = 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  result = (esl_event_t *) ((arg1)->event);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void SWIGSTDCALL CSharp_ESLevent_SerializedString_set(void * jarg1, char * jarg2) {\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  {\r
-    if (arg1->serialized_string) delete [] arg1->serialized_string;\r
-    if (arg2) {\r
-      arg1->serialized_string = (char *) (new char[strlen((const char *)arg2)+1]);\r
-      strcpy((char *)arg1->serialized_string, (const char *)arg2);\r
-    } else {\r
-      arg1->serialized_string = 0;\r
-    }\r
-  }\r
-}\r
-\r
-\r
-SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_SerializedString_get(void * jarg1) {\r
-  char * jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *result = 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  result = (char *) ((arg1)->serialized_string);\r
-  jresult = SWIG_csharp_string_callback((const char *)result); \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void SWIGSTDCALL CSharp_ESLevent_Mine_set(void * jarg1, int jarg2) {\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  int arg2 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  arg2 = (int)jarg2; \r
-  if (arg1) (arg1)->mine = arg2;\r
-}\r
-\r
-\r
-SWIGEXPORT int SWIGSTDCALL CSharp_ESLevent_Mine_get(void * jarg1) {\r
-  int jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  int result;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  result = (int) ((arg1)->mine);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLevent__SWIG_0(char * jarg1, char * jarg2) {\r
-  void * jresult ;\r
-  char *arg1 = (char *) 0 ;\r
-  char *arg2 = (char *) NULL ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (char *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  result = (ESLevent *)new ESLevent((char const *)arg1,(char const *)arg2);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLevent__SWIG_1(void * jarg1, int jarg2) {\r
-  void * jresult ;\r
-  esl_event_t *arg1 = (esl_event_t *) 0 ;\r
-  int arg2 = (int) 0 ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (esl_event_t *)jarg1; \r
-  arg2 = (int)jarg2; \r
-  result = (ESLevent *)new ESLevent(arg1,arg2);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLevent__SWIG_2(void * jarg1) {\r
-  void * jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  result = (ESLevent *)new ESLevent(arg1);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void SWIGSTDCALL CSharp_delete_ESLevent(void * jarg1) {\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  delete arg1;\r
-}\r
-\r
-\r
-SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_Serialize(void * jarg1, char * jarg2) {\r
-  char * jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *arg2 = (char *) NULL ;\r
-  char *result = 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  result = (char *)(arg1)->serialize((char const *)arg2);\r
-  jresult = SWIG_csharp_string_callback((const char *)result); \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_SetPriority(void * jarg1, void * jarg2) {\r
-  unsigned int jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  esl_priority_t arg2 = (esl_priority_t) ESL_PRIORITY_NORMAL ;\r
-  esl_priority_t *argp2 ;\r
-  bool result;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  argp2 = (esl_priority_t *)jarg2; \r
-  if (!argp2) {\r
-    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null esl_priority_t", 0);\r
-    return 0;\r
-  }\r
-  arg2 = *argp2; \r
-  result = (bool)(arg1)->setPriority(arg2);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_GetHeader(void * jarg1, char * jarg2, int jarg3) {\r
-  char * jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  int arg3 = (int) -1 ;\r
-  char *result = 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (int)jarg3; \r
-  result = (char *)(arg1)->getHeader((char const *)arg2,arg3);\r
-  jresult = SWIG_csharp_string_callback((const char *)result); \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_GetBody(void * jarg1) {\r
-  char * jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *result = 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  result = (char *)(arg1)->getBody();\r
-  jresult = SWIG_csharp_string_callback((const char *)result); \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_getType(void * jarg1) {\r
-  char * jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *result = 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  result = (char *)(arg1)->getType();\r
-  jresult = SWIG_csharp_string_callback((const char *)result); \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_AddBody(void * jarg1, char * jarg2) {\r
-  unsigned int jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  bool result;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  result = (bool)(arg1)->addBody((char const *)arg2);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_AddHeader(void * jarg1, char * jarg2, char * jarg3) {\r
-  unsigned int jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) 0 ;\r
-  bool result;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  result = (bool)(arg1)->addHeader((char const *)arg2,(char const *)arg3);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_pushHeader(void * jarg1, char * jarg2, char * jarg3) {\r
-  unsigned int jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) 0 ;\r
-  bool result;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  result = (bool)(arg1)->pushHeader((char const *)arg2,(char const *)arg3);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_unshiftHeader(void * jarg1, char * jarg2, char * jarg3) {\r
-  unsigned int jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) 0 ;\r
-  bool result;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  result = (bool)(arg1)->unshiftHeader((char const *)arg2,(char const *)arg3);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_DelHeader(void * jarg1, char * jarg2) {\r
-  unsigned int jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  bool result;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  result = (bool)(arg1)->delHeader((char const *)arg2);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_FirstHeader(void * jarg1) {\r
-  char * jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *result = 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  result = (char *)(arg1)->firstHeader();\r
-  jresult = SWIG_csharp_string_callback((const char *)result); \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_NextHeader(void * jarg1) {\r
-  char * jresult ;\r
-  ESLevent *arg1 = (ESLevent *) 0 ;\r
-  char *result = 0 ;\r
-  \r
-  arg1 = (ESLevent *)jarg1; \r
-  result = (char *)(arg1)->nextHeader();\r
-  jresult = SWIG_csharp_string_callback((const char *)result); \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_0(char * jarg1, int jarg2, char * jarg3, char * jarg4) {\r
-  void * jresult ;\r
-  char *arg1 = (char *) 0 ;\r
-  int arg2 ;\r
-  char *arg3 = (char *) 0 ;\r
-  char *arg4 = (char *) 0 ;\r
-  ESLconnection *result = 0 ;\r
-  \r
-  arg1 = (char *)jarg1; \r
-  arg2 = (int)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  arg4 = (char *)jarg4; \r
-  result = (ESLconnection *)new ESLconnection((char const *)arg1,arg2,(char const *)arg3,(char const *)arg4);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_1(char * jarg1, int jarg2, char * jarg3) {\r
-  void * jresult ;\r
-  char *arg1 = (char *) 0 ;\r
-  int arg2 ;\r
-  char *arg3 = (char *) 0 ;\r
-  ESLconnection *result = 0 ;\r
-  \r
-  arg1 = (char *)jarg1; \r
-  arg2 = (int)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  result = (ESLconnection *)new ESLconnection((char const *)arg1,arg2,(char const *)arg3);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_2(char * jarg1, char * jarg2, char * jarg3, char * jarg4) {\r
-  void * jresult ;\r
-  char *arg1 = (char *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) 0 ;\r
-  char *arg4 = (char *) 0 ;\r
-  ESLconnection *result = 0 ;\r
-  \r
-  arg1 = (char *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  arg4 = (char *)jarg4; \r
-  result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_3(char * jarg1, char * jarg2, char * jarg3) {\r
-  void * jresult ;\r
-  char *arg1 = (char *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) 0 ;\r
-  ESLconnection *result = 0 ;\r
-  \r
-  arg1 = (char *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_4(int jarg1) {\r
-  void * jresult ;\r
-  int arg1 ;\r
-  ESLconnection *result = 0 ;\r
-  \r
-  arg1 = (int)jarg1; \r
-  result = (ESLconnection *)new ESLconnection(arg1);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void SWIGSTDCALL CSharp_delete_ESLconnection(void * jarg1) {\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  delete arg1;\r
-}\r
-\r
-\r
-SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_SocketDescriptor(void * jarg1) {\r
-  int jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  int result;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  result = (int)(arg1)->socketDescriptor();\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_Connected(void * jarg1) {\r
-  int jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  int result;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  result = (int)(arg1)->connected();\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_GetInfo(void * jarg1) {\r
-  void * jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  result = (ESLevent *)(arg1)->getInfo();\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_Send(void * jarg1, char * jarg2) {\r
-  int jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  int result;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  result = (int)(arg1)->send((char const *)arg2);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_SendRecv(void * jarg1, char * jarg2) {\r
-  void * jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  result = (ESLevent *)(arg1)->sendRecv((char const *)arg2);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_Api(void * jarg1, char * jarg2, char * jarg3) {\r
-  void * jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) NULL ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  result = (ESLevent *)(arg1)->api((char const *)arg2,(char const *)arg3);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_Bgapi(void * jarg1, char * jarg2, char * jarg3, char * jarg4) {\r
-  void * jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) NULL ;\r
-  char *arg4 = (char *) NULL ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  arg4 = (char *)jarg4; \r
-  result = (ESLevent *)(arg1)->bgapi((char const *)arg2,(char const *)arg3,(char const *)arg4);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_SendEvent(void * jarg1, void * jarg2) {\r
-  void * jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  ESLevent *arg2 = (ESLevent *) 0 ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (ESLevent *)jarg2; \r
-  result = (ESLevent *)(arg1)->sendEvent(arg2);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_sendMSG(void * jarg1, void * jarg2, char * jarg3) {\r
-  int jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  ESLevent *arg2 = (ESLevent *) 0 ;\r
-  char *arg3 = (char *) NULL ;\r
-  int result;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (ESLevent *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  result = (int)(arg1)->sendMSG(arg2,(char const *)arg3);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_RecvEvent(void * jarg1) {\r
-  void * jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  result = (ESLevent *)(arg1)->recvEvent();\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_RecvEventTimed(void * jarg1, int jarg2) {\r
-  void * jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  int arg2 ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (int)jarg2; \r
-  result = (ESLevent *)(arg1)->recvEventTimed(arg2);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_Filter(void * jarg1, char * jarg2, char * jarg3) {\r
-  void * jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) 0 ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  result = (ESLevent *)(arg1)->filter((char const *)arg2,(char const *)arg3);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_Events(void * jarg1, char * jarg2, char * jarg3) {\r
-  int jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) 0 ;\r
-  int result;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  result = (int)(arg1)->events((char const *)arg2,(char const *)arg3);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_Execute(void * jarg1, char * jarg2, char * jarg3, char * jarg4) {\r
-  void * jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) NULL ;\r
-  char *arg4 = (char *) NULL ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  arg4 = (char *)jarg4; \r
-  result = (ESLevent *)(arg1)->execute((char const *)arg2,(char const *)arg3,(char const *)arg4);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_ExecuteAsync(void * jarg1, char * jarg2, char * jarg3, char * jarg4) {\r
-  void * jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  char *arg3 = (char *) NULL ;\r
-  char *arg4 = (char *) NULL ;\r
-  ESLevent *result = 0 ;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  arg3 = (char *)jarg3; \r
-  arg4 = (char *)jarg4; \r
-  result = (ESLevent *)(arg1)->executeAsync((char const *)arg2,(char const *)arg3,(char const *)arg4);\r
-  jresult = (void *)result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_SetAsyncExecute(void * jarg1, char * jarg2) {\r
-  int jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  int result;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  result = (int)(arg1)->setAsyncExecute((char const *)arg2);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_SetEventLock(void * jarg1, char * jarg2) {\r
-  int jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  char *arg2 = (char *) 0 ;\r
-  int result;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  arg2 = (char *)jarg2; \r
-  result = (int)(arg1)->setEventLock((char const *)arg2);\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_Disconnect(void * jarg1) {\r
-  int jresult ;\r
-  ESLconnection *arg1 = (ESLconnection *) 0 ;\r
-  int result;\r
-  \r
-  arg1 = (ESLconnection *)jarg1; \r
-  result = (int)(arg1)->disconnect();\r
-  jresult = result; \r
-  return jresult;\r
-}\r
-\r
-\r
-SWIGEXPORT void SWIGSTDCALL CSharp_eslSetLogLevel(int jarg1) {\r
-  int arg1 ;\r
-  \r
-  arg1 = (int)jarg1; \r
-  eslSetLogLevel(arg1);\r
-}\r
-\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.1
+ * 
+ * This file is not intended to be easily readable and contains a number of 
+ * coding conventions designed to improve portability and efficiency. Do not make
+ * changes to this file unless you know what you are doing--modify the SWIG 
+ * interface file instead. 
+ * ----------------------------------------------------------------------------- */
+
+#define SWIGCSHARP
+
+
+#ifdef __cplusplus
+/* SwigValueWrapper is described in swig.swg */
+template<typename T> class SwigValueWrapper {
+  struct SwigMovePointer {
+    T *ptr;
+    SwigMovePointer(T *p) : ptr(p) { }
+    ~SwigMovePointer() { delete ptr; }
+    SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
+  } pointer;
+  SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
+  SwigValueWrapper(const SwigValueWrapper<T>& rhs);
+public:
+  SwigValueWrapper() : pointer(0) { }
+  SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
+  operator T&() const { return *pointer.ptr; }
+  T *operator&() { return pointer.ptr; }
+};
+
+template <typename T> T SwigValueInit() {
+  return T();
+}
+#endif
+
+/* -----------------------------------------------------------------------------
+ *  This section contains generic SWIG labels for method/variable
+ *  declarations/attributes, and other compiler dependent labels.
+ * ----------------------------------------------------------------------------- */
+
+/* template workaround for compilers that cannot correctly implement the C++ standard */
+#ifndef SWIGTEMPLATEDISAMBIGUATOR
+# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
+#  define SWIGTEMPLATEDISAMBIGUATOR template
+# elif defined(__HP_aCC)
+/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
+/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
+#  define SWIGTEMPLATEDISAMBIGUATOR template
+# else
+#  define SWIGTEMPLATEDISAMBIGUATOR
+# endif
+#endif
+
+/* inline attribute */
+#ifndef SWIGINLINE
+# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
+#   define SWIGINLINE inline
+# else
+#   define SWIGINLINE
+# endif
+#endif
+
+/* attribute recognised by some compilers to avoid 'unused' warnings */
+#ifndef SWIGUNUSED
+# if defined(__GNUC__)
+#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#     define SWIGUNUSED __attribute__ ((__unused__)) 
+#   else
+#     define SWIGUNUSED
+#   endif
+# elif defined(__ICC)
+#   define SWIGUNUSED __attribute__ ((__unused__)) 
+# else
+#   define SWIGUNUSED 
+# endif
+#endif
+
+#ifndef SWIG_MSC_UNSUPPRESS_4505
+# if defined(_MSC_VER)
+#   pragma warning(disable : 4505) /* unreferenced local function has been removed */
+# endif 
+#endif
+
+#ifndef SWIGUNUSEDPARM
+# ifdef __cplusplus
+#   define SWIGUNUSEDPARM(p)
+# else
+#   define SWIGUNUSEDPARM(p) p SWIGUNUSED 
+# endif
+#endif
+
+/* internal SWIG method */
+#ifndef SWIGINTERN
+# define SWIGINTERN static SWIGUNUSED
+#endif
+
+/* internal inline SWIG method */
+#ifndef SWIGINTERNINLINE
+# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
+#endif
+
+/* exporting methods */
+#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#  ifndef GCC_HASCLASSVISIBILITY
+#    define GCC_HASCLASSVISIBILITY
+#  endif
+#endif
+
+#ifndef SWIGEXPORT
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+#   if defined(STATIC_LINKED)
+#     define SWIGEXPORT
+#   else
+#     define SWIGEXPORT __declspec(dllexport)
+#   endif
+# else
+#   if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
+#     define SWIGEXPORT __attribute__ ((visibility("default")))
+#   else
+#     define SWIGEXPORT
+#   endif
+# endif
+#endif
+
+/* calling conventions for Windows */
+#ifndef SWIGSTDCALL
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+#   define SWIGSTDCALL __stdcall
+# else
+#   define SWIGSTDCALL
+# endif 
+#endif
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
+#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
+# define _SCL_SECURE_NO_DEPRECATE
+#endif
+
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+
+/* Support for throwing C# exceptions from C/C++. There are two types: 
+ * Exceptions that take a message and ArgumentExceptions that take a message and a parameter name. */
+typedef enum {
+  SWIG_CSharpApplicationException,
+  SWIG_CSharpArithmeticException,
+  SWIG_CSharpDivideByZeroException,
+  SWIG_CSharpIndexOutOfRangeException,
+  SWIG_CSharpInvalidCastException,
+  SWIG_CSharpInvalidOperationException,
+  SWIG_CSharpIOException,
+  SWIG_CSharpNullReferenceException,
+  SWIG_CSharpOutOfMemoryException,
+  SWIG_CSharpOverflowException,
+  SWIG_CSharpSystemException
+} SWIG_CSharpExceptionCodes;
+
+typedef enum {
+  SWIG_CSharpArgumentException,
+  SWIG_CSharpArgumentNullException,
+  SWIG_CSharpArgumentOutOfRangeException
+} SWIG_CSharpExceptionArgumentCodes;
+
+typedef void (SWIGSTDCALL* SWIG_CSharpExceptionCallback_t)(const char *);
+typedef void (SWIGSTDCALL* SWIG_CSharpExceptionArgumentCallback_t)(const char *, const char *);
+
+typedef struct {
+  SWIG_CSharpExceptionCodes code;
+  SWIG_CSharpExceptionCallback_t callback;
+} SWIG_CSharpException_t;
+
+typedef struct {
+  SWIG_CSharpExceptionArgumentCodes code;
+  SWIG_CSharpExceptionArgumentCallback_t callback;
+} SWIG_CSharpExceptionArgument_t;
+
+static SWIG_CSharpException_t SWIG_csharp_exceptions[] = {
+  { SWIG_CSharpApplicationException, NULL },
+  { SWIG_CSharpArithmeticException, NULL },
+  { SWIG_CSharpDivideByZeroException, NULL },
+  { SWIG_CSharpIndexOutOfRangeException, NULL },
+  { SWIG_CSharpInvalidCastException, NULL },
+  { SWIG_CSharpInvalidOperationException, NULL },
+  { SWIG_CSharpIOException, NULL },
+  { SWIG_CSharpNullReferenceException, NULL },
+  { SWIG_CSharpOutOfMemoryException, NULL },
+  { SWIG_CSharpOverflowException, NULL },
+  { SWIG_CSharpSystemException, NULL }
+};
+
+static SWIG_CSharpExceptionArgument_t SWIG_csharp_exceptions_argument[] = {
+  { SWIG_CSharpArgumentException, NULL },
+  { SWIG_CSharpArgumentNullException, NULL },
+  { SWIG_CSharpArgumentOutOfRangeException, NULL }
+};
+
+static void SWIGUNUSED SWIG_CSharpSetPendingException(SWIG_CSharpExceptionCodes code, const char *msg) {
+  SWIG_CSharpExceptionCallback_t callback = SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback;
+  if ((size_t)code < sizeof(SWIG_csharp_exceptions)/sizeof(SWIG_CSharpException_t)) {
+    callback = SWIG_csharp_exceptions[code].callback;
+  }
+  callback(msg);
+}
+
+static void SWIGUNUSED SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpExceptionArgumentCodes code, const char *msg, const char *param_name) {
+  SWIG_CSharpExceptionArgumentCallback_t callback = SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback;
+  if ((size_t)code < sizeof(SWIG_csharp_exceptions_argument)/sizeof(SWIG_CSharpExceptionArgument_t)) {
+    callback = SWIG_csharp_exceptions_argument[code].callback;
+  }
+  callback(msg, param_name);
+}
+
+
+#ifdef __cplusplus
+extern "C" 
+#endif
+SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionCallbacks_ESL(
+                                                SWIG_CSharpExceptionCallback_t applicationCallback,
+                                                SWIG_CSharpExceptionCallback_t arithmeticCallback,
+                                                SWIG_CSharpExceptionCallback_t divideByZeroCallback, 
+                                                SWIG_CSharpExceptionCallback_t indexOutOfRangeCallback, 
+                                                SWIG_CSharpExceptionCallback_t invalidCastCallback,
+                                                SWIG_CSharpExceptionCallback_t invalidOperationCallback,
+                                                SWIG_CSharpExceptionCallback_t ioCallback,
+                                                SWIG_CSharpExceptionCallback_t nullReferenceCallback,
+                                                SWIG_CSharpExceptionCallback_t outOfMemoryCallback, 
+                                                SWIG_CSharpExceptionCallback_t overflowCallback, 
+                                                SWIG_CSharpExceptionCallback_t systemCallback) {
+  SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback = applicationCallback;
+  SWIG_csharp_exceptions[SWIG_CSharpArithmeticException].callback = arithmeticCallback;
+  SWIG_csharp_exceptions[SWIG_CSharpDivideByZeroException].callback = divideByZeroCallback;
+  SWIG_csharp_exceptions[SWIG_CSharpIndexOutOfRangeException].callback = indexOutOfRangeCallback;
+  SWIG_csharp_exceptions[SWIG_CSharpInvalidCastException].callback = invalidCastCallback;
+  SWIG_csharp_exceptions[SWIG_CSharpInvalidOperationException].callback = invalidOperationCallback;
+  SWIG_csharp_exceptions[SWIG_CSharpIOException].callback = ioCallback;
+  SWIG_csharp_exceptions[SWIG_CSharpNullReferenceException].callback = nullReferenceCallback;
+  SWIG_csharp_exceptions[SWIG_CSharpOutOfMemoryException].callback = outOfMemoryCallback;
+  SWIG_csharp_exceptions[SWIG_CSharpOverflowException].callback = overflowCallback;
+  SWIG_csharp_exceptions[SWIG_CSharpSystemException].callback = systemCallback;
+}
+
+#ifdef __cplusplus
+extern "C" 
+#endif
+SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_ESL(
+                                                SWIG_CSharpExceptionArgumentCallback_t argumentCallback,
+                                                SWIG_CSharpExceptionArgumentCallback_t argumentNullCallback,
+                                                SWIG_CSharpExceptionArgumentCallback_t argumentOutOfRangeCallback) {
+  SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback = argumentCallback;
+  SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentNullException].callback = argumentNullCallback;
+  SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentOutOfRangeException].callback = argumentOutOfRangeCallback;
+}
+
+
+/* Callback for returning strings to C# without leaking memory */
+typedef char * (SWIGSTDCALL* SWIG_CSharpStringHelperCallback)(const char *);
+static SWIG_CSharpStringHelperCallback SWIG_csharp_string_callback = NULL;
+
+
+#ifdef __cplusplus
+extern "C" 
+#endif
+SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_ESL(SWIG_CSharpStringHelperCallback callback) {
+  SWIG_csharp_string_callback = callback;
+}
+
+
+/* Contract support */
+
+#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, msg, ""); return nullreturn; } else
+
+
+#include "esl.h"
+#include "esl_oop.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+SWIGEXPORT void SWIGSTDCALL CSharp_ESLevent_Event_set(void * jarg1, void * jarg2) {
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  esl_event_t *arg2 = (esl_event_t *) 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  arg2 = (esl_event_t *)jarg2; 
+  if (arg1) (arg1)->event = arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLevent_Event_get(void * jarg1) {
+  void * jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  esl_event_t *result = 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  result = (esl_event_t *) ((arg1)->event);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_ESLevent_SerializedString_set(void * jarg1, char * jarg2) {
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg1->serialized_string) delete [] arg1->serialized_string;
+    if (arg2) {
+      arg1->serialized_string = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->serialized_string, (const char *)arg2);
+    } else {
+      arg1->serialized_string = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_SerializedString_get(void * jarg1) {
+  char * jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  result = (char *) ((arg1)->serialized_string);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_ESLevent_Mine_set(void * jarg1, int jarg2) {
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  int arg2 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->mine = arg2;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_ESLevent_Mine_get(void * jarg1) {
+  int jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  int result;
+  
+  arg1 = (ESLevent *)jarg1; 
+  result = (int) ((arg1)->mine);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLevent__SWIG_0(char * jarg1, char * jarg2) {
+  void * jresult ;
+  char *arg1 = (char *) 0 ;
+  char *arg2 = (char *) NULL ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (char *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (ESLevent *)new ESLevent((char const *)arg1,(char const *)arg2);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLevent__SWIG_1(void * jarg1, int jarg2) {
+  void * jresult ;
+  esl_event_t *arg1 = (esl_event_t *) 0 ;
+  int arg2 = (int) 0 ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (esl_event_t *)jarg1; 
+  arg2 = (int)jarg2; 
+  result = (ESLevent *)new ESLevent(arg1,arg2);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLevent__SWIG_2(void * jarg1) {
+  void * jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  result = (ESLevent *)new ESLevent(arg1);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_delete_ESLevent(void * jarg1) {
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  delete arg1;
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_Serialize(void * jarg1, char * jarg2) {
+  char * jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *arg2 = (char *) NULL ;
+  char *result = 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (char *)(arg1)->serialize((char const *)arg2);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_SetPriority(void * jarg1, void * jarg2) {
+  unsigned int jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  esl_priority_t arg2 = (esl_priority_t) ESL_PRIORITY_NORMAL ;
+  esl_priority_t *argp2 ;
+  bool result;
+  
+  arg1 = (ESLevent *)jarg1; 
+  argp2 = (esl_priority_t *)jarg2; 
+  if (!argp2) {
+    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null esl_priority_t", 0);
+    return 0;
+  }
+  arg2 = *argp2; 
+  result = (bool)(arg1)->setPriority(arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_GetHeader(void * jarg1, char * jarg2, int jarg3) {
+  char * jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *arg2 = (char *) 0 ;
+  int arg3 = (int) -1 ;
+  char *result = 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (int)jarg3; 
+  result = (char *)(arg1)->getHeader((char const *)arg2,arg3);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_GetBody(void * jarg1) {
+  char * jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  result = (char *)(arg1)->getBody();
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_getType(void * jarg1) {
+  char * jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  result = (char *)(arg1)->getType();
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_AddBody(void * jarg1, char * jarg2) {
+  unsigned int jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *arg2 = (char *) 0 ;
+  bool result;
+  
+  arg1 = (ESLevent *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (bool)(arg1)->addBody((char const *)arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_AddHeader(void * jarg1, char * jarg2, char * jarg3) {
+  unsigned int jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) 0 ;
+  bool result;
+  
+  arg1 = (ESLevent *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  result = (bool)(arg1)->addHeader((char const *)arg2,(char const *)arg3);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_pushHeader(void * jarg1, char * jarg2, char * jarg3) {
+  unsigned int jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) 0 ;
+  bool result;
+  
+  arg1 = (ESLevent *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  result = (bool)(arg1)->pushHeader((char const *)arg2,(char const *)arg3);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_unshiftHeader(void * jarg1, char * jarg2, char * jarg3) {
+  unsigned int jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) 0 ;
+  bool result;
+  
+  arg1 = (ESLevent *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  result = (bool)(arg1)->unshiftHeader((char const *)arg2,(char const *)arg3);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ESLevent_DelHeader(void * jarg1, char * jarg2) {
+  unsigned int jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *arg2 = (char *) 0 ;
+  bool result;
+  
+  arg1 = (ESLevent *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (bool)(arg1)->delHeader((char const *)arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_FirstHeader(void * jarg1) {
+  char * jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  result = (char *)(arg1)->firstHeader();
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_NextHeader(void * jarg1) {
+  char * jresult ;
+  ESLevent *arg1 = (ESLevent *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (ESLevent *)jarg1; 
+  result = (char *)(arg1)->nextHeader();
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_0(char * jarg1, int jarg2, char * jarg3, char * jarg4) {
+  void * jresult ;
+  char *arg1 = (char *) 0 ;
+  int arg2 ;
+  char *arg3 = (char *) 0 ;
+  char *arg4 = (char *) 0 ;
+  ESLconnection *result = 0 ;
+  
+  arg1 = (char *)jarg1; 
+  arg2 = (int)jarg2; 
+  arg3 = (char *)jarg3; 
+  arg4 = (char *)jarg4; 
+  result = (ESLconnection *)new ESLconnection((char const *)arg1,arg2,(char const *)arg3,(char const *)arg4);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_1(char * jarg1, int jarg2, char * jarg3) {
+  void * jresult ;
+  char *arg1 = (char *) 0 ;
+  int arg2 ;
+  char *arg3 = (char *) 0 ;
+  ESLconnection *result = 0 ;
+  
+  arg1 = (char *)jarg1; 
+  arg2 = (int)jarg2; 
+  arg3 = (char *)jarg3; 
+  result = (ESLconnection *)new ESLconnection((char const *)arg1,arg2,(char const *)arg3);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_2(char * jarg1, char * jarg2, char * jarg3, char * jarg4) {
+  void * jresult ;
+  char *arg1 = (char *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) 0 ;
+  char *arg4 = (char *) 0 ;
+  ESLconnection *result = 0 ;
+  
+  arg1 = (char *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  arg4 = (char *)jarg4; 
+  result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_3(char * jarg1, char * jarg2, char * jarg3) {
+  void * jresult ;
+  char *arg1 = (char *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) 0 ;
+  ESLconnection *result = 0 ;
+  
+  arg1 = (char *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_4(int jarg1) {
+  void * jresult ;
+  int arg1 ;
+  ESLconnection *result = 0 ;
+  
+  arg1 = (int)jarg1; 
+  result = (ESLconnection *)new ESLconnection(arg1);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_delete_ESLconnection(void * jarg1) {
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  delete arg1;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_SocketDescriptor(void * jarg1) {
+  int jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  int result;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  result = (int)(arg1)->socketDescriptor();
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_Connected(void * jarg1) {
+  int jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  int result;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  result = (int)(arg1)->connected();
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_GetInfo(void * jarg1) {
+  void * jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  result = (ESLevent *)(arg1)->getInfo();
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_Send(void * jarg1, char * jarg2) {
+  int jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  char *arg2 = (char *) 0 ;
+  int result;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (int)(arg1)->send((char const *)arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_SendRecv(void * jarg1, char * jarg2) {
+  void * jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  char *arg2 = (char *) 0 ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (ESLevent *)(arg1)->sendRecv((char const *)arg2);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_Api(void * jarg1, char * jarg2, char * jarg3) {
+  void * jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) NULL ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  result = (ESLevent *)(arg1)->api((char const *)arg2,(char const *)arg3);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_Bgapi(void * jarg1, char * jarg2, char * jarg3, char * jarg4) {
+  void * jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) NULL ;
+  char *arg4 = (char *) NULL ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  arg4 = (char *)jarg4; 
+  result = (ESLevent *)(arg1)->bgapi((char const *)arg2,(char const *)arg3,(char const *)arg4);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_SendEvent(void * jarg1, void * jarg2) {
+  void * jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  ESLevent *arg2 = (ESLevent *) 0 ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (ESLevent *)jarg2; 
+  result = (ESLevent *)(arg1)->sendEvent(arg2);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_sendMSG(void * jarg1, void * jarg2, char * jarg3) {
+  int jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  ESLevent *arg2 = (ESLevent *) 0 ;
+  char *arg3 = (char *) NULL ;
+  int result;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (ESLevent *)jarg2; 
+  arg3 = (char *)jarg3; 
+  result = (int)(arg1)->sendMSG(arg2,(char const *)arg3);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_RecvEvent(void * jarg1) {
+  void * jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  result = (ESLevent *)(arg1)->recvEvent();
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_RecvEventTimed(void * jarg1, int jarg2) {
+  void * jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  int arg2 ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (int)jarg2; 
+  result = (ESLevent *)(arg1)->recvEventTimed(arg2);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_Filter(void * jarg1, char * jarg2, char * jarg3) {
+  void * jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) 0 ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  result = (ESLevent *)(arg1)->filter((char const *)arg2,(char const *)arg3);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_Events(void * jarg1, char * jarg2, char * jarg3) {
+  int jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) 0 ;
+  int result;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  result = (int)(arg1)->events((char const *)arg2,(char const *)arg3);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_Execute(void * jarg1, char * jarg2, char * jarg3, char * jarg4) {
+  void * jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) NULL ;
+  char *arg4 = (char *) NULL ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  arg4 = (char *)jarg4; 
+  result = (ESLevent *)(arg1)->execute((char const *)arg2,(char const *)arg3,(char const *)arg4);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_ESLconnection_ExecuteAsync(void * jarg1, char * jarg2, char * jarg3, char * jarg4) {
+  void * jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) NULL ;
+  char *arg4 = (char *) NULL ;
+  ESLevent *result = 0 ;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  arg4 = (char *)jarg4; 
+  result = (ESLevent *)(arg1)->executeAsync((char const *)arg2,(char const *)arg3,(char const *)arg4);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_SetAsyncExecute(void * jarg1, char * jarg2) {
+  int jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  char *arg2 = (char *) 0 ;
+  int result;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (int)(arg1)->setAsyncExecute((char const *)arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_SetEventLock(void * jarg1, char * jarg2) {
+  int jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  char *arg2 = (char *) 0 ;
+  int result;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (int)(arg1)->setEventLock((char const *)arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_ESLconnection_Disconnect(void * jarg1) {
+  int jresult ;
+  ESLconnection *arg1 = (ESLconnection *) 0 ;
+  int result;
+  
+  arg1 = (ESLconnection *)jarg1; 
+  result = (int)(arg1)->disconnect();
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_eslSetLogLevel(int jarg1) {
+  int arg1 ;
+  
+  arg1 = (int)jarg1; 
+  eslSetLogLevel(arg1);
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
index 1eb9415422eb146f80ca9b770166152db54d0f66..6795a94a76cd8d25d163ee669e67613b54d3611b 100644 (file)
-/*****************************************************************************\r
-\r
-  FileName:     5ESSStateNT.c\r
-\r
-  Contents:     AT&T 5ESS ISDN State Engine for NT (Network Mode).\r
-\r
-                   The controlling state engine for Q.931 is the state engine\r
-                   on the NT side. The state engine on the TE side is a slave \r
-                   of this. The TE side maintain it's own states as described in\r
-                   ITU-T Q931, but will in    raise conditions be overridden by \r
-                   the NT side.\r
-\r
-  License/Copyright:\r
-\r
-  Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.\r
-  email:janvb@caselaboratories.com  \r
-\r
-  Copyright (c) 2007, Michael Jerris. All rights reserved.\r
-  email:mike@jerris.com  \r
-  \r
-  Copyright (c) 2007, Michael S. Collins, All rights reserved.\r
-  email:mcollins@fcnetwork.com\r
-  \r
-  Redistribution and use in source and binary forms, with or without \r
-  modification, are permitted provided that the following conditions are \r
-  met:\r
-\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 notice, \r
-         this list of conditions and the following disclaimer in the documentation \r
-         and/or other materials provided with the distribution.\r
-       * Neither the name of the Case Labs, Ltd nor the names of its contributors \r
-         may be used to endorse or promote products derived from this software \r
-         without specific prior written permission.\r
-\r
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" \r
-  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \r
-  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE \r
-  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE \r
-  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR \r
-  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF \r
-  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS \r
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN \r
-  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \r
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \r
-  POSSIBILITY OF SUCH DAMAGE.\r
-*****************************************************************************/\r
-\r
-#include "5ESS.h"\r
-\r
-/*****************************************************************************\r
-  Function:     ATT5ESSCreateNT\r
-\r
-  Description:  Will create the AT&T 5ESS ISDN NT as a Dialect in the stack. The first\r
-                   bulk set up the message handlers, the second bulk the IE\r
-                   encoders/coders, and the last bulk set up the state table.\r
-\r
-  Parameters:   i       Dialect index\r
-*****************************************************************************/\r
-void ATT5ESSCreateNT(L3UCHAR i)\r
-{\r
-       Q931SetMesProc(Q931mes_ALERTING,             i, Q931ProcAlertingNT,          Q931Umes_Alerting,          Q931Pmes_Alerting);\r
-       Q931SetMesProc(Q931mes_CALL_PROCEEDING,      i, Q931ProcCallProceedingNT,    Q931Umes_CallProceeding,    Q931Pmes_CallProceeding);\r
-       Q931SetMesProc(Q931mes_CONNECT,              i, Q931ProcConnectNT,           Q931Umes_Connect,           Q931Pmes_Connect);\r
-       Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE,  i, Q931ProcConnectAckNT,        Q931Umes_ConnectAck,        Q931Pmes_ConnectAck);\r
-       Q931SetMesProc(Q931mes_PROGRESS,             i, Q931ProcProgressNT,          Q931Umes_Progress,          Q931Pmes_Progress);\r
-       Q931SetMesProc(Q931mes_SETUP,                i, Q931ProcSetupNT,             Q931Umes_Setup,             Q931Pmes_Setup);\r
-       Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE,    i, Q931ProcSetupAckNT,          Q931Umes_SetupAck,          Q931Pmes_SetupAck);\r
-       Q931SetMesProc(Q931mes_RESUME,               i, Q931ProcResumeNT,            Q931Umes_Resume,            Q931Pmes_Resume);\r
-       Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE,   i, Q931ProcResumeAckNT,         Q931Umes_ResumeAck,         Q931Pmes_ResumeAck);\r
-       Q931SetMesProc(Q931mes_RESUME_REJECT,        i, Q931ProcResumeRejectNT,      Q931Umes_ResumeReject,      Q931Pmes_ResumeReject);\r
-       Q931SetMesProc(Q931mes_SUSPEND,              i, Q931ProcSuspendNT,           Q931Umes_Suspend,           Q931Pmes_Suspend);\r
-       Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE,  i, Q931ProcSuspendAckNT,        Q931Umes_SuspendAck,        Q931Pmes_SuspendAck);\r
-       Q931SetMesProc(Q931mes_SUSPEND_REJECT,       i, Q931ProcSuspendRejectNT,     Q931Umes_SuspendReject,     Q931Pmes_SuspendReject);\r
-       Q931SetMesProc(Q931mes_USER_INFORMATION,     i, Q931ProcUserInformationNT,   Q931Umes_UserInformation,   Q931Pmes_UserInformation);\r
-       Q931SetMesProc(Q931mes_DISCONNECT,           i, Q931ProcDisconnectNT,        Q931Umes_Disconnect,        Q931Pmes_Disconnect);\r
-       Q931SetMesProc(Q931mes_RELEASE,              i, Q931ProcReleaseNT,           Q931Umes_Release,           Q931Pmes_Release);\r
-       Q931SetMesProc(Q931mes_RELEASE_COMPLETE,     i, Q931ProcReleaseCompleteNT,   Q931Umes_ReleaseComplete,   Q931Pmes_ReleaseComplete);\r
-       Q931SetMesProc(Q931mes_RESTART,              i, Q931ProcRestartNT,           Q931Umes_Restart,           Q931Pmes_Restart);\r
-       Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE,  i, Q931ProcRestartAckNT,        Q931Umes_RestartAck,        Q931Pmes_RestartAck);\r
-       Q931SetMesProc(Q931mes_CONGESTION_CONTROL,   i, Q931ProcCongestionControlNT, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);\r
-       Q931SetMesProc(Q931mes_INFORMATION,          i, Q931ProcInformationNT,       Q931Umes_Information,       Q931Pmes_Information);\r
-       Q931SetMesProc(Q931mes_NOTIFY,               i, Q931ProcNotifyNT,            Q931Umes_Notify,            Q931Pmes_Notify);\r
-       Q931SetMesProc(Q931mes_STATUS,               i, Q931ProcStatusNT,            Q931Umes_Status,            Q931Pmes_Status);\r
-       Q931SetMesProc(Q931mes_STATUS_ENQUIRY,       i, Q931ProcStatusEnquiryNT,     Q931Umes_StatusEnquiry,     Q931Pmes_StatusEnquiry);\r
-       Q931SetMesProc(Q931mes_SEGMENT,              i, Q931ProcSegmentNT,           Q931Umes_Segment,           Q931Pmes_Segment);\r
-\r
-       Q931SetMesProc(Q932mes_FACILITY,             i, Q932ProcFacilityNT,          Q932Umes_Facility,          Q932Pmes_Facility);\r
-       Q931SetMesProc(Q932mes_HOLD,                 i, Q932ProcHoldNT,              Q932Umes_Hold,              Q932Pmes_Hold);\r
-       Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE,     i, Q932ProcHoldAckNT,           Q932Umes_HoldAck,           Q932Pmes_HoldAck);\r
-       Q931SetMesProc(Q932mes_HOLD_REJECT,          i, Q932ProcHoldRejectNT,        Q932Umes_HoldReject,        Q932Pmes_HoldReject);\r
-       Q931SetMesProc(Q932mes_REGISTER,             i, Q932ProcRegisterNT,          Q932Umes_Register,          Q932Pmes_Register);\r
-       Q931SetMesProc(Q932mes_RETRIEVE,             i, Q932ProcRetrieveNT,          Q932Umes_Retrieve,          Q932Pmes_Retrieve);\r
-       Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckNT,       Q932Umes_RetrieveAck,       Q932Pmes_RetrieveAck);\r
-       Q931SetMesProc(Q932mes_RETRIEVE_REJECT,      i, Q932ProcRetrieveRejectNT,    Q932Umes_RetrieveReject,    Q932Pmes_RetrieveReject);\r
-\r
-       /* Set up the IE encoder/decoder handle table.*/ \r
-       Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE,                i, Q931Pie_Segment,           Q931Uie_Segment);\r
-       Q931SetIEProc(Q931ie_BEARER_CAPABILITY,                i, Q931Pie_BearerCap,         Q931Uie_BearerCap);\r
-       Q931SetIEProc(Q931ie_CAUSE,                            i, Q931Pie_Cause,             Q931Uie_Cause);\r
-       Q931SetIEProc(Q931ie_CALL_IDENTITY,                    i, Q931Pie_CallID,            Q931Uie_CallID);\r
-       Q931SetIEProc(Q931ie_CALL_STATE,                       i, Q931Pie_CallState,         Q931Uie_CallState);\r
-       Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION,           i, Q931Pie_ChanID,            Q931Uie_ChanID);\r
-       Q931SetIEProc(Q931ie_PROGRESS_INDICATOR,               i, Q931Pie_ProgInd,           Q931Uie_ProgInd);\r
-       Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES,      i, Q931Pie_NetFac,            Q931Uie_NetFac);\r
-       Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR,           i, Q931Pie_NotifInd,          Q931Uie_NotifInd);\r
-       Q931SetIEProc(Q931ie_DISPLAY,                          i, Q931Pie_Display,           Q931Uie_Display);\r
-       Q931SetIEProc(Q931ie_DATETIME,                         i, Q931Pie_DateTime,          Q931Uie_DateTime);\r
-       Q931SetIEProc(Q931ie_KEYPAD_FACILITY,                  i, Q931Pie_KeypadFac,         Q931Uie_KeypadFac);\r
-       Q931SetIEProc(Q931ie_SIGNAL,                           i, Q931Pie_Signal,            Q931Uie_Signal);\r
-       Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND,  i, Q931Pie_TransNetSel,       Q931Uie_TransNetSel);\r
-       Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER,             i, Q931Pie_CallingNum,        Q931Uie_CallingNum);\r
-       Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS,         i, Q931Pie_CallingSub,        Q931Uie_CallingSub);\r
-       Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER,              i, Q931Pie_CalledNum,         Q931Uie_CalledNum);\r
-       Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS,          i, Q931Pie_CalledSub,         Q931Uie_CalledSub);\r
-       Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION,        i, Q931Pie_TransNetSel,       Q931Uie_TransNetSel);\r
-       Q931SetIEProc(Q931ie_RESTART_INDICATOR,                i, Q931Pie_RestartInd,        Q931Uie_RestartInd);\r
-       Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY,          i, Q931Pie_LLComp,            Q931Uie_LLComp);\r
-       Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY,         i, Q931Pie_HLComp,            Q931Uie_HLComp);\r
-       Q931SetIEProc(Q931ie_USER_USER,                        i, Q931Pie_UserUser,          Q931Uie_UserUser);\r
-       Q931SetIEProc(Q931ie_GENERIC_DIGITS,                   i, Q931Pie_GenericDigits,     Q931Uie_GenericDigits);\r
-\r
-       Q931SetIEProc(Q931ie_CONNECTED_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);\r
-       Q931SetIEProc(Q931ie_FACILITY,         i, Q931Pie_Generic, Q931Uie_Generic);\r
-\r
-       /* The following define a state machine. The point is that the Message  */\r
-       /* procs can when search this to find out if the message/state          */\r
-       /* combination is legale. If not, the proc for unexpected message apply.*/\r
-\r
-       /* TODO define state table here */\r
-}\r
+/*****************************************************************************
+
+  FileName:     5ESSStateNT.c
+
+  Contents:     AT&T 5ESS ISDN State Engine for NT (Network Mode).
+
+                   The controlling state engine for Q.931 is the state engine
+                   on the NT side. The state engine on the TE side is a slave 
+                   of this. The TE side maintain it's own states as described in
+                   ITU-T Q931, but will in    raise conditions be overridden by 
+                   the NT side.
+
+  License/Copyright:
+
+  Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
+  email:janvb@caselaboratories.com  
+
+  Copyright (c) 2007, Michael Jerris. All rights reserved.
+  email:mike@jerris.com  
+  
+  Copyright (c) 2007, Michael S. Collins, All rights reserved.
+  email:mcollins@fcnetwork.com
+  
+  Redistribution and use in source and binary forms, with or without 
+  modification, are permitted provided that the following conditions are 
+  met:
+
+       * Redistributions of source code must retain the above copyright notice, 
+         this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright notice, 
+         this list of conditions and the following disclaimer in the documentation 
+         and/or other materials provided with the distribution.
+       * Neither the name of the Case Labs, Ltd nor the names of its contributors 
+         may be used to endorse or promote products derived from this software 
+         without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
+  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
+  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+  POSSIBILITY OF SUCH DAMAGE.
+*****************************************************************************/
+
+#include "5ESS.h"
+
+/*****************************************************************************
+  Function:     ATT5ESSCreateNT
+
+  Description:  Will create the AT&T 5ESS ISDN NT as a Dialect in the stack. The first
+                   bulk set up the message handlers, the second bulk the IE
+                   encoders/coders, and the last bulk set up the state table.
+
+  Parameters:   i       Dialect index
+*****************************************************************************/
+void ATT5ESSCreateNT(L3UCHAR i)
+{
+       Q931SetMesProc(Q931mes_ALERTING,             i, Q931ProcAlertingNT,          Q931Umes_Alerting,          Q931Pmes_Alerting);
+       Q931SetMesProc(Q931mes_CALL_PROCEEDING,      i, Q931ProcCallProceedingNT,    Q931Umes_CallProceeding,    Q931Pmes_CallProceeding);
+       Q931SetMesProc(Q931mes_CONNECT,              i, Q931ProcConnectNT,           Q931Umes_Connect,           Q931Pmes_Connect);
+       Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE,  i, Q931ProcConnectAckNT,        Q931Umes_ConnectAck,        Q931Pmes_ConnectAck);
+       Q931SetMesProc(Q931mes_PROGRESS,             i, Q931ProcProgressNT,          Q931Umes_Progress,          Q931Pmes_Progress);
+       Q931SetMesProc(Q931mes_SETUP,                i, Q931ProcSetupNT,             Q931Umes_Setup,             Q931Pmes_Setup);
+       Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE,    i, Q931ProcSetupAckNT,          Q931Umes_SetupAck,          Q931Pmes_SetupAck);
+       Q931SetMesProc(Q931mes_RESUME,               i, Q931ProcResumeNT,            Q931Umes_Resume,            Q931Pmes_Resume);
+       Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE,   i, Q931ProcResumeAckNT,         Q931Umes_ResumeAck,         Q931Pmes_ResumeAck);
+       Q931SetMesProc(Q931mes_RESUME_REJECT,        i, Q931ProcResumeRejectNT,      Q931Umes_ResumeReject,      Q931Pmes_ResumeReject);
+       Q931SetMesProc(Q931mes_SUSPEND,              i, Q931ProcSuspendNT,           Q931Umes_Suspend,           Q931Pmes_Suspend);
+       Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE,  i, Q931ProcSuspendAckNT,        Q931Umes_SuspendAck,        Q931Pmes_SuspendAck);
+       Q931SetMesProc(Q931mes_SUSPEND_REJECT,       i, Q931ProcSuspendRejectNT,     Q931Umes_SuspendReject,     Q931Pmes_SuspendReject);
+       Q931SetMesProc(Q931mes_USER_INFORMATION,     i, Q931ProcUserInformationNT,   Q931Umes_UserInformation,   Q931Pmes_UserInformation);
+       Q931SetMesProc(Q931mes_DISCONNECT,           i, Q931ProcDisconnectNT,        Q931Umes_Disconnect,        Q931Pmes_Disconnect);
+       Q931SetMesProc(Q931mes_RELEASE,              i, Q931ProcReleaseNT,           Q931Umes_Release,           Q931Pmes_Release);
+       Q931SetMesProc(Q931mes_RELEASE_COMPLETE,     i, Q931ProcReleaseCompleteNT,   Q931Umes_ReleaseComplete,   Q931Pmes_ReleaseComplete);
+       Q931SetMesProc(Q931mes_RESTART,              i, Q931ProcRestartNT,           Q931Umes_Restart,           Q931Pmes_Restart);
+       Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE,  i, Q931ProcRestartAckNT,        Q931Umes_RestartAck,        Q931Pmes_RestartAck);
+       Q931SetMesProc(Q931mes_CONGESTION_CONTROL,   i, Q931ProcCongestionControlNT, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
+       Q931SetMesProc(Q931mes_INFORMATION,          i, Q931ProcInformationNT,       Q931Umes_Information,       Q931Pmes_Information);
+       Q931SetMesProc(Q931mes_NOTIFY,               i, Q931ProcNotifyNT,            Q931Umes_Notify,            Q931Pmes_Notify);
+       Q931SetMesProc(Q931mes_STATUS,               i, Q931ProcStatusNT,            Q931Umes_Status,            Q931Pmes_Status);
+       Q931SetMesProc(Q931mes_STATUS_ENQUIRY,       i, Q931ProcStatusEnquiryNT,     Q931Umes_StatusEnquiry,     Q931Pmes_StatusEnquiry);
+       Q931SetMesProc(Q931mes_SEGMENT,              i, Q931ProcSegmentNT,           Q931Umes_Segment,           Q931Pmes_Segment);
+
+       Q931SetMesProc(Q932mes_FACILITY,             i, Q932ProcFacilityNT,          Q932Umes_Facility,          Q932Pmes_Facility);
+       Q931SetMesProc(Q932mes_HOLD,                 i, Q932ProcHoldNT,              Q932Umes_Hold,              Q932Pmes_Hold);
+       Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE,     i, Q932ProcHoldAckNT,           Q932Umes_HoldAck,           Q932Pmes_HoldAck);
+       Q931SetMesProc(Q932mes_HOLD_REJECT,          i, Q932ProcHoldRejectNT,        Q932Umes_HoldReject,        Q932Pmes_HoldReject);
+       Q931SetMesProc(Q932mes_REGISTER,             i, Q932ProcRegisterNT,          Q932Umes_Register,          Q932Pmes_Register);
+       Q931SetMesProc(Q932mes_RETRIEVE,             i, Q932ProcRetrieveNT,          Q932Umes_Retrieve,          Q932Pmes_Retrieve);
+       Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckNT,       Q932Umes_RetrieveAck,       Q932Pmes_RetrieveAck);
+       Q931SetMesProc(Q932mes_RETRIEVE_REJECT,      i, Q932ProcRetrieveRejectNT,    Q932Umes_RetrieveReject,    Q932Pmes_RetrieveReject);
+
+       /* Set up the IE encoder/decoder handle table.*/ 
+       Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE,                i, Q931Pie_Segment,           Q931Uie_Segment);
+       Q931SetIEProc(Q931ie_BEARER_CAPABILITY,                i, Q931Pie_BearerCap,         Q931Uie_BearerCap);
+       Q931SetIEProc(Q931ie_CAUSE,                            i, Q931Pie_Cause,             Q931Uie_Cause);
+       Q931SetIEProc(Q931ie_CALL_IDENTITY,                    i, Q931Pie_CallID,            Q931Uie_CallID);
+       Q931SetIEProc(Q931ie_CALL_STATE,                       i, Q931Pie_CallState,         Q931Uie_CallState);
+       Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION,           i, Q931Pie_ChanID,            Q931Uie_ChanID);
+       Q931SetIEProc(Q931ie_PROGRESS_INDICATOR,               i, Q931Pie_ProgInd,           Q931Uie_ProgInd);
+       Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES,      i, Q931Pie_NetFac,            Q931Uie_NetFac);
+       Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR,           i, Q931Pie_NotifInd,          Q931Uie_NotifInd);
+       Q931SetIEProc(Q931ie_DISPLAY,                          i, Q931Pie_Display,           Q931Uie_Display);
+       Q931SetIEProc(Q931ie_DATETIME,                         i, Q931Pie_DateTime,          Q931Uie_DateTime);
+       Q931SetIEProc(Q931ie_KEYPAD_FACILITY,                  i, Q931Pie_KeypadFac,         Q931Uie_KeypadFac);
+       Q931SetIEProc(Q931ie_SIGNAL,                           i, Q931Pie_Signal,            Q931Uie_Signal);
+       Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND,  i, Q931Pie_TransNetSel,       Q931Uie_TransNetSel);
+       Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER,             i, Q931Pie_CallingNum,        Q931Uie_CallingNum);
+       Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS,         i, Q931Pie_CallingSub,        Q931Uie_CallingSub);
+       Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER,              i, Q931Pie_CalledNum,         Q931Uie_CalledNum);
+       Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS,          i, Q931Pie_CalledSub,         Q931Uie_CalledSub);
+       Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION,        i, Q931Pie_TransNetSel,       Q931Uie_TransNetSel);
+       Q931SetIEProc(Q931ie_RESTART_INDICATOR,                i, Q931Pie_RestartInd,        Q931Uie_RestartInd);
+       Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY,          i, Q931Pie_LLComp,            Q931Uie_LLComp);
+       Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY,         i, Q931Pie_HLComp,            Q931Uie_HLComp);
+       Q931SetIEProc(Q931ie_USER_USER,                        i, Q931Pie_UserUser,          Q931Uie_UserUser);
+       Q931SetIEProc(Q931ie_GENERIC_DIGITS,                   i, Q931Pie_GenericDigits,     Q931Uie_GenericDigits);
+
+       Q931SetIEProc(Q931ie_CONNECTED_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
+       Q931SetIEProc(Q931ie_FACILITY,         i, Q931Pie_Generic, Q931Uie_Generic);
+
+       /* The following define a state machine. The point is that the Message  */
+       /* procs can when search this to find out if the message/state          */
+       /* combination is legale. If not, the proc for unexpected message apply.*/
+
+       /* TODO define state table here */
+}
index e2ededd9ac298f60c72d96b8d07b0227d2b4ab4d..5a7ed0e21b9084be0010fa54da7096b37e41f720 100644 (file)
-/*****************************************************************************\r
-\r
-  FileName:     5ESSStateTE.c\r
-\r
-  Contents:     AT&T 5ESS ISDN State Engine for TE (User Mode).\r
-\r
-                   The controlling state engine for Q.931 is the state engine\r
-                   on the NT side. The state engine on the TE side is a slave \r
-                   of this. The TE side maintain it's own states as described in\r
-                   ITU-T Q931, but will in    raise conditions be overridden by \r
-                   the NT side.\r
-\r
-                   This reference implementation uses a process per message, \r
-                   meaning that each message must check call states. This\r
-                   is easier for dialect maintenance as each message proc\r
-                   can be replaced individually. A new TE variant only\r
-                   need to copy the Q931CreateTE and replace those procs or\r
-                   need to override.\r
-\r
-  License/Copyright:\r
-\r
-  Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.\r
-  email:janvb@caselaboratories.com  \r
-\r
-  Copyright (c) 2007, Michael Jerris. All rights reserved.\r
-  email:mike@jerris.com  \r
-  \r
-  Copyright (c) 2007, Michael S. Collins, All rights reserved.\r
-  email:mcollins@fcnetwork.com\r
-  \r
-  Redistribution and use in source and binary forms, with or without \r
-  modification, are permitted provided that the following conditions are \r
-  met:\r
-\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 notice, \r
-       this list of conditions and the following disclaimer in the documentation \r
-       and/or other materials provided with the distribution.\r
-       * Neither the name of the Case Labs, Ltd nor the names of its contributors \r
-       may be used to endorse or promote products derived from this software \r
-       without specific prior written permission.\r
-\r
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" \r
-  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \r
-  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE \r
-  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE \r
-  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR \r
-  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF \r
-  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS \r
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN \r
-  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \r
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \r
-  POSSIBILITY OF SUCH DAMAGE.\r
-*****************************************************************************/\r
-\r
-#include "5ESS.h"\r
-extern L3INT Q931L4HeaderSpace;\r
-\r
-/*****************************************************************************\r
-  Function:     ATT5ESSCreateTE\r
-\r
-  Description:  Will create the AT&T 5ESS TE as a Dialect in the stack. The first\r
-                   bulk set up the message handlers, the second bulk the IE\r
-                   encoders/coders, and the last bulk set up the state table.\r
-\r
-  Parameters:   i       Dialect index\r
-*****************************************************************************/\r
-void ATT5ESSCreateTE(L3UCHAR i)\r
-{\r
-       Q931SetMesProc(Q931mes_ALERTING,             i, Q931ProcAlertingTE,          Q931Umes_Alerting,          Q931Pmes_Alerting);\r
-       Q931SetMesProc(Q931mes_CALL_PROCEEDING,      i, Q931ProcCallProceedingTE,    Q931Umes_CallProceeding,    Q931Pmes_CallProceeding);\r
-       Q931SetMesProc(Q931mes_CONNECT,              i, ATT5ESSProc0x07TE,           ATT5ESSUmes_0x07,           ATT5ESSPmes_0x07);\r
-       Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE,  i, ATT5ESSProc0x0fTE,           ATT5ESSUmes_0x0f,           ATT5ESSPmes_0x0f);\r
-       Q931SetMesProc(Q931mes_PROGRESS,             i, Q931ProcProgressTE,          Q931Umes_Progress,          Q931Pmes_Progress);\r
-       Q931SetMesProc(Q931mes_SETUP,                i, Q931ProcSetupTE,             ATT5ESSUmes_Setup,          ATT5ESSPmes_Setup);\r
-       Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE,    i, Q931ProcSetupAckTE,          Q931Umes_SetupAck,          Q931Pmes_SetupAck);\r
-       Q931SetMesProc(Q931mes_RESUME,               i, Q931ProcResumeTE,            Q931Umes_Resume,            Q931Pmes_Resume);\r
-       Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE,   i, Q931ProcResumeAckTE,         Q931Umes_ResumeAck,         Q931Pmes_ResumeAck);\r
-       Q931SetMesProc(Q931mes_RESUME_REJECT,        i, Q931ProcResumeRejectTE,      Q931Umes_ResumeReject,      Q931Pmes_ResumeReject);\r
-       Q931SetMesProc(Q931mes_SUSPEND,              i, Q931ProcSuspendTE,           Q931Umes_Suspend,           Q931Pmes_Suspend);\r
-       Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE,  i, Q931ProcSuspendAckTE,        Q931Umes_SuspendAck,        Q931Pmes_SuspendAck);\r
-       Q931SetMesProc(Q931mes_SUSPEND_REJECT,       i, Q931ProcSuspendRejectTE,     Q931Umes_SuspendReject,     Q931Pmes_SuspendReject);\r
-       Q931SetMesProc(Q931mes_USER_INFORMATION,     i, Q931ProcUserInformationTE,   Q931Umes_UserInformation,   Q931Pmes_UserInformation);\r
-       Q931SetMesProc(Q931mes_DISCONNECT,           i, Q931ProcDisconnectTE,        Q931Umes_Disconnect,        Q931Pmes_Disconnect);\r
-       Q931SetMesProc(Q931mes_RELEASE,              i, Q931ProcReleaseTE,           Q931Umes_Release,           Q931Pmes_Release);\r
-       Q931SetMesProc(Q931mes_RELEASE_COMPLETE,     i, Q931ProcReleaseCompleteTE,   Q931Umes_ReleaseComplete,   Q931Pmes_ReleaseComplete);\r
-       Q931SetMesProc(Q931mes_RESTART,              i, Q931ProcRestartTE,           Q931Umes_Restart,           Q931Pmes_Restart);\r
-       Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE,  i, Q931ProcRestartAckTE,        Q931Umes_RestartAck,        Q931Pmes_RestartAck);\r
-       Q931SetMesProc(Q931mes_CONGESTION_CONTROL,   i, Q931ProcCongestionControlTE, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);\r
-       Q931SetMesProc(Q931mes_INFORMATION,          i, Q931ProcInformationTE,       Q931Umes_Information,       Q931Pmes_Information);\r
-       Q931SetMesProc(Q931mes_NOTIFY,               i, Q931ProcNotifyTE,            Q931Umes_Notify,            Q931Pmes_Notify);\r
-       Q931SetMesProc(Q931mes_STATUS,               i, Q931ProcStatusTE,            Q931Umes_Status,            Q931Pmes_Status);\r
-       Q931SetMesProc(Q931mes_STATUS_ENQUIRY,       i, Q931ProcStatusEnquiryTE,     Q931Umes_StatusEnquiry,     Q931Pmes_StatusEnquiry);\r
-       Q931SetMesProc(Q931mes_SEGMENT,              i, Q931ProcSegmentTE,           Q931Umes_Segment,           Q931Pmes_Segment);\r
-\r
-       Q931SetMesProc(Q932mes_FACILITY,             i, Q932ProcFacilityTE,          Q932Umes_Facility,          Q932Pmes_Facility);\r
-       Q931SetMesProc(Q932mes_HOLD,                 i, Q932ProcHoldTE,              Q932Umes_Hold,              Q932Pmes_Hold);\r
-       Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE,     i, Q932ProcHoldAckTE,           Q932Umes_HoldAck,           Q932Pmes_HoldAck);\r
-       Q931SetMesProc(Q932mes_HOLD_REJECT,          i, Q932ProcHoldRejectTE,        Q932Umes_HoldReject,        Q932Pmes_HoldReject);\r
-       Q931SetMesProc(Q932mes_REGISTER,             i, Q932ProcRegisterTE,          Q932Umes_Register,          Q932Pmes_Register);\r
-       Q931SetMesProc(Q932mes_RETRIEVE,             i, Q932ProcRetrieveTE,          Q932Umes_Retrieve,          Q932Pmes_Retrieve);\r
-       Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckTE,       Q932Umes_RetrieveAck,       Q932Pmes_RetrieveAck);\r
-       Q931SetMesProc(Q932mes_RETRIEVE_REJECT,      i, Q932ProcRetrieveRejectTE,    Q932Umes_RetrieveReject,    Q932Pmes_RetrieveReject);\r
-\r
-       /* Set up the IE encoder/decoder handle table.*/ \r
-       Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE,                i, Q931Pie_Segment,           Q931Uie_Segment);\r
-       Q931SetIEProc(Q931ie_BEARER_CAPABILITY,                i, Q931Pie_BearerCap,         Q931Uie_BearerCap);\r
-       Q931SetIEProc(Q931ie_CAUSE,                            i, Q931Pie_Cause,             Q931Uie_Cause);\r
-       Q931SetIEProc(Q931ie_CALL_IDENTITY,                    i, Q931Pie_CallID,            Q931Uie_CallID);\r
-       Q931SetIEProc(Q931ie_CALL_STATE,                       i, Q931Pie_CallState,         Q931Uie_CallState);\r
-       Q931SetIEProc(Q931ie_CHANGE_STATUS,                    i, Q931Pie_ChangeStatus,      Q931Uie_ChangeStatus);\r
-       Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION,           i, Q931Pie_ChanID,            Q931Uie_ChanID);\r
-       Q931SetIEProc(Q931ie_PROGRESS_INDICATOR,               i, Q931Pie_ProgInd,           Q931Uie_ProgInd);\r
-       Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES,      i, Q931Pie_NetFac,            Q931Uie_NetFac);\r
-       Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR,           i, Q931Pie_NotifInd,          Q931Uie_NotifInd);\r
-       Q931SetIEProc(Q931ie_DISPLAY,                          i, Q931Pie_Display,           Q931Uie_Display);\r
-       Q931SetIEProc(Q931ie_DATETIME,                         i, Q931Pie_DateTime,          Q931Uie_DateTime);\r
-       Q931SetIEProc(Q931ie_KEYPAD_FACILITY,                  i, Q931Pie_KeypadFac,         Q931Uie_KeypadFac);\r
-       Q931SetIEProc(Q931ie_SIGNAL,                           i, Q931Pie_Signal,            Q931Uie_Signal);\r
-       Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND,  i, Q931Pie_TransNetSel,       Q931Uie_TransNetSel);\r
-       Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER,             i, Q931Pie_CallingNum,        Q931Uie_CallingNum);\r
-       Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS,         i, Q931Pie_CallingSub,        Q931Uie_CallingSub);\r
-       Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER,              i, Q931Pie_CalledNum,         Q931Uie_CalledNum);\r
-       Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS,          i, Q931Pie_CalledSub,         Q931Uie_CalledSub);\r
-       Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION,        i, Q931Pie_TransNetSel,       Q931Uie_TransNetSel);\r
-       Q931SetIEProc(Q931ie_RESTART_INDICATOR,                i, Q931Pie_RestartInd,        Q931Uie_RestartInd);\r
-       Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY,          i, Q931Pie_LLComp,            Q931Uie_LLComp);\r
-       Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY,         i, Q931Pie_HLComp,            Q931Uie_HLComp);\r
-       Q931SetIEProc(Q931ie_USER_USER,                        i, Q931Pie_UserUser,          Q931Uie_UserUser);\r
-       Q931SetIEProc(Q931ie_GENERIC_DIGITS,                   i, Q931Pie_GenericDigits,     Q931Uie_GenericDigits);\r
-\r
-       Q931SetIEProc(Q931ie_CONNECTED_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);\r
-       Q931SetIEProc(Q931ie_FACILITY,         i, Q931Pie_Generic, Q931Uie_Generic);\r
-\r
-       /* The following define a state machine. The point is that the Message  */\r
-       /* procs can when search this to find out if the message/state          */\r
-       /* combination is legale. If not, the proc for unexpected message apply.*/\r
-\r
-       /* State 0 Idle */\r
-       Q931AddStateEntry(i, Q931_U0,    Q931mes_RESUME,             2);\r
-       Q931AddStateEntry(i, Q931_U0,    Q931mes_SETUP,              4);\r
-       Q931AddStateEntry(i, Q931_U0,    Q931mes_SETUP,              2);\r
-       Q931AddStateEntry(i, Q931_U0,    Q931mes_STATUS,             4);\r
-       Q931AddStateEntry(i, Q931_U0,    Q931mes_RELEASE,            4);\r
-       Q931AddStateEntry(i, Q931_U0,    Q931mes_RELEASE_COMPLETE,   4);\r
-\r
-       /* State 1 Call Initiating */\r
-       Q931AddStateEntry(i, Q931_U1,    Q931mes_DISCONNECT,         2);\r
-       Q931AddStateEntry(i, Q931_U1,    Q931mes_SETUP_ACKNOWLEDGE,  4);\r
-       Q931AddStateEntry(i, Q931_U1,    Q931mes_RELEASE_COMPLETE,   4);\r
-       Q931AddStateEntry(i, Q931_U1,    Q931mes_CALL_PROCEEDING,    4);\r
-       Q931AddStateEntry(i, Q931_U1,    Q931mes_ALERTING,           4);\r
-       Q931AddStateEntry(i, Q931_U1,    Q931mes_CONNECT,            4);\r
-\r
-       /* State 2 Overlap Sending */\r
-       Q931AddStateEntry(i, Q931_U2,    Q931mes_INFORMATION,        2);\r
-       Q931AddStateEntry(i, Q931_U2,    Q931mes_CALL_PROCEEDING,    4);\r
-       Q931AddStateEntry(i, Q931_U2,    Q931mes_ALERTING,           4);\r
-       Q931AddStateEntry(i, Q931_U2,    Q931mes_PROGRESS,           4);\r
-       Q931AddStateEntry(i, Q931_U2,    Q931mes_CONNECT,            4);\r
-       Q931AddStateEntry(i, Q931_U2,    Q931mes_RELEASE,            2);\r
-\r
-       /* State 3 Outgoing Call Proceeding */\r
-       Q931AddStateEntry(i, Q931_U3,    Q931mes_PROGRESS,           4);\r
-       Q931AddStateEntry(i, Q931_U3,    Q931mes_ALERTING,           4);\r
-       Q931AddStateEntry(i, Q931_U3,    Q931mes_CONNECT,            4);\r
-       Q931AddStateEntry(i, Q931_U3,    Q931mes_RELEASE,            2);\r
-\r
-       /* State 4 Call Delivered */\r
-       Q931AddStateEntry(i, Q931_U4,    Q931mes_CONNECT,            4);\r
-\r
-       /* State 6 Call Precent */\r
-       Q931AddStateEntry(i, Q931_U6,    Q931mes_INFORMATION,        2);\r
-       Q931AddStateEntry(i, Q931_U6,    Q931mes_ALERTING,           2);\r
-       Q931AddStateEntry(i, Q931_U6,    Q931mes_CALL_PROCEEDING,    2);\r
-       Q931AddStateEntry(i, Q931_U6,    Q931mes_CONNECT,            2);\r
-       Q931AddStateEntry(i, Q931_U6,    Q931mes_RELEASE_COMPLETE,   2);\r
-       Q931AddStateEntry(i, Q931_U6,    Q931mes_RELEASE,            4);\r
-       Q931AddStateEntry(i, Q931_U6,    Q931mes_DISCONNECT,         4);\r
-\r
-       /* State 7 Call Received */\r
-       Q931AddStateEntry(i, Q931_U7,    Q931mes_CONNECT,            2);\r
-\r
-       /* State 8 Connect request */\r
-       Q931AddStateEntry(i, Q931_U8,    Q931mes_CONNECT_ACKNOWLEDGE, 4);\r
-\r
-       /* State 9 Incoming Call Proceeding */\r
-       Q931AddStateEntry(i, Q931_U9,    Q931mes_CONNECT,            2);\r
-       Q931AddStateEntry(i, Q931_U9,    Q931mes_ALERTING,           2);\r
-       Q931AddStateEntry(i, Q931_U9,    Q931mes_PROGRESS,           2);\r
-\r
-       /* State 10 Active */\r
-       Q931AddStateEntry(i, Q931_U10,   Q931mes_SUSPEND,            2);\r
-       Q931AddStateEntry(i, Q931_U10,   Q931mes_NOTIFY,             4);\r
-       Q931AddStateEntry(i, Q931_U10,   Q931mes_NOTIFY,             2);\r
-\r
-       /* State 11 Disconnect Request */\r
-       Q931AddStateEntry(i, Q931_U11,   Q931mes_RELEASE,            4);\r
-       Q931AddStateEntry(i, Q931_U11,   Q931mes_DISCONNECT,         4);\r
-       Q931AddStateEntry(i, Q931_U11,   Q931mes_NOTIFY,             4);\r
-\r
-       /* State 12 Disconnect Ind */\r
-       Q931AddStateEntry(i, Q931_U12,   Q931mes_RELEASE,            4);\r
-       Q931AddStateEntry(i, Q931_U12,   Q931mes_RELEASE,            2);\r
-\r
-       /* State 15 Suspend Request */\r
-       Q931AddStateEntry(i, Q931_U15,   Q931mes_SUSPEND_ACKNOWLEDGE, 4);\r
-       Q931AddStateEntry(i, Q931_U15,   Q931mes_SUSPEND_REJECT,      4);\r
-       Q931AddStateEntry(i, Q931_U15,   Q931mes_DISCONNECT,          4);\r
-       Q931AddStateEntry(i, Q931_U15,   Q931mes_RELEASE,             4);\r
-\r
-/* TODO\r
-       Q931AddStateEntry(i, Q931_U17, \r
-       Q931AddStateEntry(i, Q931_U19, \r
-       Q931AddStateEntry(i, Q931_U25, \r
-*/\r
-}\r
-\r
-/*****************************************************************************\r
-\r
-  Function:            ATT5ESSProc0x0fTE\r
-\r
-*****************************************************************************/\r
-L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)\r
-{\r
-       Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];\r
-       L3INT callIndex;\r
-       L3INT ret = Q931E_NO_ERROR;\r
-\r
-       if (pMes->ProtDisc == 8) {\r
-               /* Find the call using CRV */\r
-               ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);\r
-               if (ret != Q931E_NO_ERROR)\r
-                       return ret;\r
-\r
-               /* TODO chack against state table for illegal or unexpected message here*/\r
-\r
-               /* TODO - Set correct timer here */\r
-               Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);\r
-       }\r
-       if (iFrom == 4) {\r
-               /* TODO Add proc here*/\r
-               ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);\r
-       }\r
-       else if (iFrom ==2) {\r
-               /* TODO Add proc here*/\r
-               ret = Q931Tx34(pTrunk, buf, pMes->Size);\r
-\r
-               if (pMes->ProtDisc == 3 && pTrunk->autoServiceAck) {\r
-                       printf("autoServiceAck is on, responding to Service Req from network...\n");\r
-                       Q931AckService(pTrunk, buf);\r
-               }\r
-       }\r
-       return ret;\r
-\r
-}\r
-\r
-/*****************************************************************************\r
-\r
-  Function:            ATT5ESSProc0x07TE\r
-\r
-*****************************************************************************/\r
-L3INT ATT5ESSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)\r
-{\r
-       Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];\r
-       L3INT callIndex;\r
-       L3INT ret = Q931E_NO_ERROR;\r
-\r
-       if (pMes->ProtDisc == 8) {\r
-               /* Find the call using CRV */\r
-               ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);\r
-               if (ret != Q931E_NO_ERROR)\r
-                       return ret;\r
-\r
-               /* TODO chack against state table for illegal or unexpected message here*/\r
-\r
-               /* TODO - Set correct timer here */\r
-               Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);\r
-       }\r
-       if (iFrom == 4) {\r
-               /* TODO Add proc here*/\r
-               ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);\r
-       }\r
-       else if (iFrom == 2) {\r
-               /* TODO Add proc here*/\r
-               ret = Q931Tx34(pTrunk, buf, pMes->Size);\r
-       }\r
-       return ret;\r
-\r
-}\r
+/*****************************************************************************
+
+  FileName:     5ESSStateTE.c
+
+  Contents:     AT&T 5ESS ISDN State Engine for TE (User Mode).
+
+                   The controlling state engine for Q.931 is the state engine
+                   on the NT side. The state engine on the TE side is a slave 
+                   of this. The TE side maintain it's own states as described in
+                   ITU-T Q931, but will in    raise conditions be overridden by 
+                   the NT side.
+
+                   This reference implementation uses a process per message, 
+                   meaning that each message must check call states. This
+                   is easier for dialect maintenance as each message proc
+                   can be replaced individually. A new TE variant only
+                   need to copy the Q931CreateTE and replace those procs or
+                   need to override.
+
+  License/Copyright:
+
+  Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
+  email:janvb@caselaboratories.com  
+
+  Copyright (c) 2007, Michael Jerris. All rights reserved.
+  email:mike@jerris.com  
+  
+  Copyright (c) 2007, Michael S. Collins, All rights reserved.
+  email:mcollins@fcnetwork.com
+  
+  Redistribution and use in source and binary forms, with or without 
+  modification, are permitted provided that the following conditions are 
+  met:
+
+       * Redistributions of source code must retain the above copyright notice, 
+       this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright notice, 
+       this list of conditions and the following disclaimer in the documentation 
+       and/or other materials provided with the distribution.
+       * Neither the name of the Case Labs, Ltd nor the names of its contributors 
+       may be used to endorse or promote products derived from this software 
+       without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
+  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
+  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+  POSSIBILITY OF SUCH DAMAGE.
+*****************************************************************************/
+
+#include "5ESS.h"
+extern L3INT Q931L4HeaderSpace;
+
+/*****************************************************************************
+  Function:     ATT5ESSCreateTE
+
+  Description:  Will create the AT&T 5ESS TE as a Dialect in the stack. The first
+                   bulk set up the message handlers, the second bulk the IE
+                   encoders/coders, and the last bulk set up the state table.
+
+  Parameters:   i       Dialect index
+*****************************************************************************/
+void ATT5ESSCreateTE(L3UCHAR i)
+{
+       Q931SetMesProc(Q931mes_ALERTING,             i, Q931ProcAlertingTE,          Q931Umes_Alerting,          Q931Pmes_Alerting);
+       Q931SetMesProc(Q931mes_CALL_PROCEEDING,      i, Q931ProcCallProceedingTE,    Q931Umes_CallProceeding,    Q931Pmes_CallProceeding);
+       Q931SetMesProc(Q931mes_CONNECT,              i, ATT5ESSProc0x07TE,           ATT5ESSUmes_0x07,           ATT5ESSPmes_0x07);
+       Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE,  i, ATT5ESSProc0x0fTE,           ATT5ESSUmes_0x0f,           ATT5ESSPmes_0x0f);
+       Q931SetMesProc(Q931mes_PROGRESS,             i, Q931ProcProgressTE,          Q931Umes_Progress,          Q931Pmes_Progress);
+       Q931SetMesProc(Q931mes_SETUP,                i, Q931ProcSetupTE,             ATT5ESSUmes_Setup,          ATT5ESSPmes_Setup);
+       Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE,    i, Q931ProcSetupAckTE,          Q931Umes_SetupAck,          Q931Pmes_SetupAck);
+       Q931SetMesProc(Q931mes_RESUME,               i, Q931ProcResumeTE,            Q931Umes_Resume,            Q931Pmes_Resume);
+       Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE,   i, Q931ProcResumeAckTE,         Q931Umes_ResumeAck,         Q931Pmes_ResumeAck);
+       Q931SetMesProc(Q931mes_RESUME_REJECT,        i, Q931ProcResumeRejectTE,      Q931Umes_ResumeReject,      Q931Pmes_ResumeReject);
+       Q931SetMesProc(Q931mes_SUSPEND,              i, Q931ProcSuspendTE,           Q931Umes_Suspend,           Q931Pmes_Suspend);
+       Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE,  i, Q931ProcSuspendAckTE,        Q931Umes_SuspendAck,        Q931Pmes_SuspendAck);
+       Q931SetMesProc(Q931mes_SUSPEND_REJECT,       i, Q931ProcSuspendRejectTE,     Q931Umes_SuspendReject,     Q931Pmes_SuspendReject);
+       Q931SetMesProc(Q931mes_USER_INFORMATION,     i, Q931ProcUserInformationTE,   Q931Umes_UserInformation,   Q931Pmes_UserInformation);
+       Q931SetMesProc(Q931mes_DISCONNECT,           i, Q931ProcDisconnectTE,        Q931Umes_Disconnect,        Q931Pmes_Disconnect);
+       Q931SetMesProc(Q931mes_RELEASE,              i, Q931ProcReleaseTE,           Q931Umes_Release,           Q931Pmes_Release);
+       Q931SetMesProc(Q931mes_RELEASE_COMPLETE,     i, Q931ProcReleaseCompleteTE,   Q931Umes_ReleaseComplete,   Q931Pmes_ReleaseComplete);
+       Q931SetMesProc(Q931mes_RESTART,              i, Q931ProcRestartTE,           Q931Umes_Restart,           Q931Pmes_Restart);
+       Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE,  i, Q931ProcRestartAckTE,        Q931Umes_RestartAck,        Q931Pmes_RestartAck);
+       Q931SetMesProc(Q931mes_CONGESTION_CONTROL,   i, Q931ProcCongestionControlTE, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
+       Q931SetMesProc(Q931mes_INFORMATION,          i, Q931ProcInformationTE,       Q931Umes_Information,       Q931Pmes_Information);
+       Q931SetMesProc(Q931mes_NOTIFY,               i, Q931ProcNotifyTE,            Q931Umes_Notify,            Q931Pmes_Notify);
+       Q931SetMesProc(Q931mes_STATUS,               i, Q931ProcStatusTE,            Q931Umes_Status,            Q931Pmes_Status);
+       Q931SetMesProc(Q931mes_STATUS_ENQUIRY,       i, Q931ProcStatusEnquiryTE,     Q931Umes_StatusEnquiry,     Q931Pmes_StatusEnquiry);
+       Q931SetMesProc(Q931mes_SEGMENT,              i, Q931ProcSegmentTE,           Q931Umes_Segment,           Q931Pmes_Segment);
+
+       Q931SetMesProc(Q932mes_FACILITY,             i, Q932ProcFacilityTE,          Q932Umes_Facility,          Q932Pmes_Facility);
+       Q931SetMesProc(Q932mes_HOLD,                 i, Q932ProcHoldTE,              Q932Umes_Hold,              Q932Pmes_Hold);
+       Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE,     i, Q932ProcHoldAckTE,           Q932Umes_HoldAck,           Q932Pmes_HoldAck);
+       Q931SetMesProc(Q932mes_HOLD_REJECT,          i, Q932ProcHoldRejectTE,        Q932Umes_HoldReject,        Q932Pmes_HoldReject);
+       Q931SetMesProc(Q932mes_REGISTER,             i, Q932ProcRegisterTE,          Q932Umes_Register,          Q932Pmes_Register);
+       Q931SetMesProc(Q932mes_RETRIEVE,             i, Q932ProcRetrieveTE,          Q932Umes_Retrieve,          Q932Pmes_Retrieve);
+       Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE, i, Q932ProcRetrieveAckTE,       Q932Umes_RetrieveAck,       Q932Pmes_RetrieveAck);
+       Q931SetMesProc(Q932mes_RETRIEVE_REJECT,      i, Q932ProcRetrieveRejectTE,    Q932Umes_RetrieveReject,    Q932Pmes_RetrieveReject);
+
+       /* Set up the IE encoder/decoder handle table.*/ 
+       Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE,                i, Q931Pie_Segment,           Q931Uie_Segment);
+       Q931SetIEProc(Q931ie_BEARER_CAPABILITY,                i, Q931Pie_BearerCap,         Q931Uie_BearerCap);
+       Q931SetIEProc(Q931ie_CAUSE,                            i, Q931Pie_Cause,             Q931Uie_Cause);
+       Q931SetIEProc(Q931ie_CALL_IDENTITY,                    i, Q931Pie_CallID,            Q931Uie_CallID);
+       Q931SetIEProc(Q931ie_CALL_STATE,                       i, Q931Pie_CallState,         Q931Uie_CallState);
+       Q931SetIEProc(Q931ie_CHANGE_STATUS,                    i, Q931Pie_ChangeStatus,      Q931Uie_ChangeStatus);
+       Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION,           i, Q931Pie_ChanID,            Q931Uie_ChanID);
+       Q931SetIEProc(Q931ie_PROGRESS_INDICATOR,               i, Q931Pie_ProgInd,           Q931Uie_ProgInd);
+       Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES,      i, Q931Pie_NetFac,            Q931Uie_NetFac);
+       Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR,           i, Q931Pie_NotifInd,          Q931Uie_NotifInd);
+       Q931SetIEProc(Q931ie_DISPLAY,                          i, Q931Pie_Display,           Q931Uie_Display);
+       Q931SetIEProc(Q931ie_DATETIME,                         i, Q931Pie_DateTime,          Q931Uie_DateTime);
+       Q931SetIEProc(Q931ie_KEYPAD_FACILITY,                  i, Q931Pie_KeypadFac,         Q931Uie_KeypadFac);
+       Q931SetIEProc(Q931ie_SIGNAL,                           i, Q931Pie_Signal,            Q931Uie_Signal);
+       Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND,  i, Q931Pie_TransNetSel,       Q931Uie_TransNetSel);
+       Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER,             i, Q931Pie_CallingNum,        Q931Uie_CallingNum);
+       Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS,         i, Q931Pie_CallingSub,        Q931Uie_CallingSub);
+       Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER,              i, Q931Pie_CalledNum,         Q931Uie_CalledNum);
+       Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS,          i, Q931Pie_CalledSub,         Q931Uie_CalledSub);
+       Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION,        i, Q931Pie_TransNetSel,       Q931Uie_TransNetSel);
+       Q931SetIEProc(Q931ie_RESTART_INDICATOR,                i, Q931Pie_RestartInd,        Q931Uie_RestartInd);
+       Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY,          i, Q931Pie_LLComp,            Q931Uie_LLComp);
+       Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY,         i, Q931Pie_HLComp,            Q931Uie_HLComp);
+       Q931SetIEProc(Q931ie_USER_USER,                        i, Q931Pie_UserUser,          Q931Uie_UserUser);
+       Q931SetIEProc(Q931ie_GENERIC_DIGITS,                   i, Q931Pie_GenericDigits,     Q931Uie_GenericDigits);
+
+       Q931SetIEProc(Q931ie_CONNECTED_NUMBER, i, Q931Pie_Generic, Q931Uie_Generic);
+       Q931SetIEProc(Q931ie_FACILITY,         i, Q931Pie_Generic, Q931Uie_Generic);
+
+       /* The following define a state machine. The point is that the Message  */
+       /* procs can when search this to find out if the message/state          */
+       /* combination is legale. If not, the proc for unexpected message apply.*/
+
+       /* State 0 Idle */
+       Q931AddStateEntry(i, Q931_U0,    Q931mes_RESUME,             2);
+       Q931AddStateEntry(i, Q931_U0,    Q931mes_SETUP,              4);
+       Q931AddStateEntry(i, Q931_U0,    Q931mes_SETUP,              2);
+       Q931AddStateEntry(i, Q931_U0,    Q931mes_STATUS,             4);
+       Q931AddStateEntry(i, Q931_U0,    Q931mes_RELEASE,            4);
+       Q931AddStateEntry(i, Q931_U0,    Q931mes_RELEASE_COMPLETE,   4);
+
+       /* State 1 Call Initiating */
+       Q931AddStateEntry(i, Q931_U1,    Q931mes_DISCONNECT,         2);
+       Q931AddStateEntry(i, Q931_U1,    Q931mes_SETUP_ACKNOWLEDGE,  4);
+       Q931AddStateEntry(i, Q931_U1,    Q931mes_RELEASE_COMPLETE,   4);
+       Q931AddStateEntry(i, Q931_U1,    Q931mes_CALL_PROCEEDING,    4);
+       Q931AddStateEntry(i, Q931_U1,    Q931mes_ALERTING,           4);
+       Q931AddStateEntry(i, Q931_U1,    Q931mes_CONNECT,            4);
+
+       /* State 2 Overlap Sending */
+       Q931AddStateEntry(i, Q931_U2,    Q931mes_INFORMATION,        2);
+       Q931AddStateEntry(i, Q931_U2,    Q931mes_CALL_PROCEEDING,    4);
+       Q931AddStateEntry(i, Q931_U2,    Q931mes_ALERTING,           4);
+       Q931AddStateEntry(i, Q931_U2,    Q931mes_PROGRESS,           4);
+       Q931AddStateEntry(i, Q931_U2,    Q931mes_CONNECT,            4);
+       Q931AddStateEntry(i, Q931_U2,    Q931mes_RELEASE,            2);
+
+       /* State 3 Outgoing Call Proceeding */
+       Q931AddStateEntry(i, Q931_U3,    Q931mes_PROGRESS,           4);
+       Q931AddStateEntry(i, Q931_U3,    Q931mes_ALERTING,           4);
+       Q931AddStateEntry(i, Q931_U3,    Q931mes_CONNECT,            4);
+       Q931AddStateEntry(i, Q931_U3,    Q931mes_RELEASE,            2);
+
+       /* State 4 Call Delivered */
+       Q931AddStateEntry(i, Q931_U4,    Q931mes_CONNECT,            4);
+
+       /* State 6 Call Precent */
+       Q931AddStateEntry(i, Q931_U6,    Q931mes_INFORMATION,        2);
+       Q931AddStateEntry(i, Q931_U6,    Q931mes_ALERTING,           2);
+       Q931AddStateEntry(i, Q931_U6,    Q931mes_CALL_PROCEEDING,    2);
+       Q931AddStateEntry(i, Q931_U6,    Q931mes_CONNECT,            2);
+       Q931AddStateEntry(i, Q931_U6,    Q931mes_RELEASE_COMPLETE,   2);
+       Q931AddStateEntry(i, Q931_U6,    Q931mes_RELEASE,            4);
+       Q931AddStateEntry(i, Q931_U6,    Q931mes_DISCONNECT,         4);
+
+       /* State 7 Call Received */
+       Q931AddStateEntry(i, Q931_U7,    Q931mes_CONNECT,            2);
+
+       /* State 8 Connect request */
+       Q931AddStateEntry(i, Q931_U8,    Q931mes_CONNECT_ACKNOWLEDGE, 4);
+
+       /* State 9 Incoming Call Proceeding */
+       Q931AddStateEntry(i, Q931_U9,    Q931mes_CONNECT,            2);
+       Q931AddStateEntry(i, Q931_U9,    Q931mes_ALERTING,           2);
+       Q931AddStateEntry(i, Q931_U9,    Q931mes_PROGRESS,           2);
+
+       /* State 10 Active */
+       Q931AddStateEntry(i, Q931_U10,   Q931mes_SUSPEND,            2);
+       Q931AddStateEntry(i, Q931_U10,   Q931mes_NOTIFY,             4);
+       Q931AddStateEntry(i, Q931_U10,   Q931mes_NOTIFY,             2);
+
+       /* State 11 Disconnect Request */
+       Q931AddStateEntry(i, Q931_U11,   Q931mes_RELEASE,            4);
+       Q931AddStateEntry(i, Q931_U11,   Q931mes_DISCONNECT,         4);
+       Q931AddStateEntry(i, Q931_U11,   Q931mes_NOTIFY,             4);
+
+       /* State 12 Disconnect Ind */
+       Q931AddStateEntry(i, Q931_U12,   Q931mes_RELEASE,            4);
+       Q931AddStateEntry(i, Q931_U12,   Q931mes_RELEASE,            2);
+
+       /* State 15 Suspend Request */
+       Q931AddStateEntry(i, Q931_U15,   Q931mes_SUSPEND_ACKNOWLEDGE, 4);
+       Q931AddStateEntry(i, Q931_U15,   Q931mes_SUSPEND_REJECT,      4);
+       Q931AddStateEntry(i, Q931_U15,   Q931mes_DISCONNECT,          4);
+       Q931AddStateEntry(i, Q931_U15,   Q931mes_RELEASE,             4);
+
+/* TODO
+       Q931AddStateEntry(i, Q931_U17, 
+       Q931AddStateEntry(i, Q931_U19, 
+       Q931AddStateEntry(i, Q931_U25, 
+*/
+}
+
+/*****************************************************************************
+
+  Function:            ATT5ESSProc0x0fTE
+
+*****************************************************************************/
+L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
+{
+       Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
+       L3INT callIndex;
+       L3INT ret = Q931E_NO_ERROR;
+
+       if (pMes->ProtDisc == 8) {
+               /* Find the call using CRV */
+               ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
+               if (ret != Q931E_NO_ERROR)
+                       return ret;
+
+               /* TODO chack against state table for illegal or unexpected message here*/
+
+               /* TODO - Set correct timer here */
+               Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
+       }
+       if (iFrom == 4) {
+               /* TODO Add proc here*/
+               ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
+       }
+       else if (iFrom ==2) {
+               /* TODO Add proc here*/
+               ret = Q931Tx34(pTrunk, buf, pMes->Size);
+
+               if (pMes->ProtDisc == 3 && pTrunk->autoServiceAck) {
+                       printf("autoServiceAck is on, responding to Service Req from network...\n");
+                       Q931AckService(pTrunk, buf);
+               }
+       }
+       return ret;
+
+}
+
+/*****************************************************************************
+
+  Function:            ATT5ESSProc0x07TE
+
+*****************************************************************************/
+L3INT ATT5ESSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
+{
+       Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
+       L3INT callIndex;
+       L3INT ret = Q931E_NO_ERROR;
+
+       if (pMes->ProtDisc == 8) {
+               /* Find the call using CRV */
+               ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
+               if (ret != Q931E_NO_ERROR)
+                       return ret;
+
+               /* TODO chack against state table for illegal or unexpected message here*/
+
+               /* TODO - Set correct timer here */
+               Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303);
+       }
+       if (iFrom == 4) {
+               /* TODO Add proc here*/
+               ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size);
+       }
+       else if (iFrom == 2) {
+               /* TODO Add proc here*/
+               ret = Q931Tx34(pTrunk, buf, pMes->Size);
+       }
+       return ret;
+
+}
index 7cdd21e7cc3e4fce0da1671cde5f993112120542..488d1a485393258e25c463fdcd795e57b3dedff8 100644 (file)
-/*****************************************************************************\r
-\r
-  FileName:    5ESSmes.c\r
-\r
-  Contents:    Pack/Unpack functions. These functions will unpack a 5ESS ISDN\r
-               message from the bit packed original format into structs\r
-               that contains variables sized by the user. It will also pack\r
-               the struct back into a Q.931 message as required.\r
-\r
-               See 5ESS.h for description. \r
-\r
-  License/Copyright:\r
-\r
-  Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.\r
-  email:janvb@caselaboratories.com  \r
-\r
-  Copyright (c) 2007, Michael Jerris. All rights reserved.\r
-  email:mike@jerris.com\r
-  \r
-  Copyright (c) 2007, Michael S. Collins, All rights reserved.\r
-  email:mcollins@fcnetwork.com\r
-\r
-  Redistribution and use in source and binary forms, with or without \r
-  modification, are permitted provided that the following conditions are \r
-  met:\r
-\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 notice, \r
-       this list of conditions and the following disclaimer in the documentation \r
-       and/or other materials provided with the distribution.\r
-       * Neither the name of the Case Labs, Ltd nor the names of its contributors \r
-       may be used to endorse or promote products derived from this software \r
-       without specific prior written permission.\r
-\r
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" \r
-  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \r
-  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE \r
-  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE \r
-  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR \r
-  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF \r
-  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS \r
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN \r
-  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \r
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \r
-  POSSIBILITY OF SUCH DAMAGE.\r
-\r
-*****************************************************************************/\r
-\r
-#include "5ESS.h"\r
-\r
-/*****************************************************************************\r
-\r
-  Function:     ATT5ESSUmes_Setup\r
-\r
-*****************************************************************************/\r
-L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)\r
-{\r
-       L3INT ir = 0;\r
-       L3INT OOff = 0;\r
-       L3INT rc = Q931E_NO_ERROR;\r
-       L3UCHAR last_codeset = 0, codeset = 0;\r
-       L3UCHAR shift_nolock = 1;\r
-\r
-       while (IOff < Size) {\r
-\r
-               if (shift_nolock) {\r
-                       codeset = last_codeset;\r
-               }\r
-\r
-               if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT) {\r
-                       shift_nolock = (IBuf[IOff] & 0x08);\r
-                       if (shift_nolock) {\r
-                               last_codeset = codeset;\r
-                       }\r
-                       codeset = ((IBuf[IOff] & 0x07));\r
-                       IOff++;\r
-               }\r
-\r
-               if (codeset == 0) {\r
-                       switch (IBuf[IOff])\r
-                       {\r
-                       case Q931ie_SENDING_COMPLETE:\r
-                       case Q931ie_BEARER_CAPABILITY:\r
-                       case Q931ie_CHANNEL_IDENTIFICATION:\r
-                       case Q931ie_PROGRESS_INDICATOR:\r
-                       case Q931ie_NETWORK_SPECIFIC_FACILITIES:\r
-                       case Q931ie_DISPLAY:\r
-                       case Q931ie_DATETIME:\r
-                       case Q931ie_KEYPAD_FACILITY:\r
-                       case Q931ie_SIGNAL:\r
-                       case Q931ie_CALLING_PARTY_NUMBER:\r
-                       case Q931ie_CALLING_PARTY_SUBADDRESS:\r
-                       case Q931ie_CALLED_PARTY_NUMBER:\r
-                       case Q931ie_CALLED_PARTY_SUBADDRESS:\r
-                       case Q931ie_TRANSIT_NETWORK_SELECTION:\r
-                       case Q931ie_LOW_LAYER_COMPATIBILITY:\r
-                       case Q931ie_HIGH_LAYER_COMPATIBILITY:\r
-                       case Q931ie_FACILITY:\r
-                               rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);\r
-                               if (rc != Q931E_NO_ERROR) \r
-                                       return rc;\r
-                               break;\r
-                       case Q931ie_REPEAT_INDICATOR:\r
-                               if (ir < 2) {\r
-                                       rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);\r
-                                       ir++;\r
-                               } else {\r
-                                       return Q931E_ILLEGAL_IE;\r
-                               }\r
-                               break;\r
-                       default:\r
-                               return Q931E_ILLEGAL_IE;\r
-                               break;\r
-                       }\r
-               } else if (codeset == 6) {\r
-                       switch (IBuf[IOff])\r
-                       {\r
-                       case Q931ie_GENERIC_DIGITS:\r
-                               rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);\r
-                               if (rc != Q931E_NO_ERROR) \r
-                                       return rc;\r
-                               break;\r
-                       default:\r
-                               return Q931E_ILLEGAL_IE;\r
-                               break;\r
-                       }\r
-               } else if (codeset == 7) {\r
-                       switch (IBuf[IOff])\r
-                       {\r
-                       case Q931ie_DISPLAY:\r
-                               rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);\r
-                               if (rc != Q931E_NO_ERROR) \r
-                                       return rc;\r
-                               break;\r
-                       default:\r
-                               return Q931E_ILLEGAL_IE;\r
-                               break;\r
-                       }\r
-               } else {\r
-                       return Q931E_ILLEGAL_IE;\r
-               }\r
-       }\r
-       mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;\r
-       return Q931E_NO_ERROR;\r
-}\r
-\r
-/*****************************************************************************\r
-\r
-  Function:     ATT5ESSPmes_Setup\r
-\r
-  Decription:   Pack a Q931mes_Generic into a real Q.931 message. The user will\r
-                               set up a SETUP message and issue this to the stack where it\r
-                               is processed by Q931ProcSetup that processes and validates\r
-                               it before it actually sends it out. This function is called\r
-                               to compute the real Q.931 message.\r
-\r
-  Parameters:   IBuf[IN]       Ptr to un-packed struct\r
-                               ISize[IN]   Size of input buffer (unpacked message).\r
-                               OBuf[OUT]   Ptr to packed 'octet' wise message.\r
-                               OSize[OUT]  Size of packed message.\r
-\r
-  Called By:   Q931ProcSetup\r
-\r
-*****************************************************************************/\r
-L3INT ATT5ESSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)\r
-{\r
-       L3INT rc = Q931E_NO_ERROR;\r
-       Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;\r
-       L3INT Octet = 0;\r
-\r
-       /* Q931 Message Header */\r
-       Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);\r
-       \r
-       /* Sending Complete                             */\r
-       if (Q931IsIEPresent(pMes->SendComplete)) {\r
-               OBuf[Octet++]   = (L3UCHAR)(pMes->SendComplete & 0x00ff);\r
-       }\r
-\r
-       /* Repeat Indicator */\r
-       if (Q931IsIEPresent(pMes->RepeatInd)) {\r
-               OBuf[Octet++]   = (L3UCHAR)(pMes->RepeatInd & 0x00ff);\r
-       }\r
-\r
-       /* Bearer capability */\r
-       if (Q931IsIEPresent(pMes->BearerCap)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       } else {\r
-               rc = Q931E_BEARERCAP;\r
-       }\r
-\r
-       /* Channel Identification */\r
-       if (Q931IsIEPresent(pMes->ChanID)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Progress indicator */\r
-       if (Q931IsIEPresent(pMes->ProgInd)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Network specific facilities */\r
-       if (Q931IsIEPresent(pMes->NetFac)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_NETWORK_SPECIFIC_FACILITIES](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Display */\r
-       if (Q931IsIEPresent(pMes->Display)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Date/Time */\r
-       if (Q931IsIEPresent(pMes->DateTime)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DATETIME](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Keypad Facility */\r
-       if (Q931IsIEPresent(pMes->KeypadFac)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_KEYPAD_FACILITY](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Signal */\r
-       if (Q931IsIEPresent(pMes->Signal)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Calling Party Number */\r
-       if (Q931IsIEPresent(pMes->CallingNum)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Calling Party Subaddress */\r
-       if (Q931IsIEPresent(pMes->CallingSub)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Called Party number */\r
-       if (Q931IsIEPresent(pMes->CalledNum)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Called party subaddress */\r
-       if (Q931IsIEPresent(pMes->CalledSub)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Transit network selection */\r
-       if (Q931IsIEPresent(pMes->TransNetSel)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_TRANSIT_NETWORK_SELECTION](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* Repeat Indicator */\r
-       if (Q931IsIEPresent(pMes->LLRepeatInd)) {\r
-               rc = Q931E_UNKNOWN_IE;/* TODO */\r
-       }\r
-\r
-       /* Low Layer Compatibility */\r
-       if (Q931IsIEPresent(pMes->LLComp)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_LOW_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       /* High Layer Compatibility */\r
-       if (Q931IsIEPresent(pMes->HLComp)) {\r
-               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0)\r
-                       return rc;\r
-       }\r
-\r
-       *OSize = Octet;\r
-       return rc;\r
-}\r
-\r
-\r
-/*****************************************************************************\r
-\r
-  Function:     ATT5ESSUmes_0x0f\r
-\r
-*****************************************************************************/\r
-L3INT ATT5ESSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)\r
-{\r
-       if (mes->ProtDisc == 8) {\r
-               return Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size);\r
-       }\r
-\r
-       if (mes->ProtDisc == 3) {\r
-               return Q931Umes_Service(pTrunk, IBuf, mes, IOff, Size);\r
-       }\r
-\r
-       return Q931E_UNKNOWN_MESSAGE;\r
-}\r
-\r
-/*****************************************************************************\r
-\r
-  Function:     ATT5ESSPmes_0x0f\r
-\r
-*****************************************************************************/\r
-L3INT ATT5ESSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)\r
-{\r
-       Q931mes_Generic *mes = (Q931mes_Generic *)IBuf;\r
-\r
-       if (mes->ProtDisc == 8) {\r
-               return Q931Pmes_ConnectAck(pTrunk, IBuf, ISize, OBuf, OSize);\r
-       }\r
-\r
-       if (mes->ProtDisc == 3) {\r
-               return Q931Pmes_Service(pTrunk, IBuf, ISize, OBuf, OSize);\r
-       }\r
-\r
-       return Q931E_UNKNOWN_MESSAGE;\r
-}\r
-\r
-/*****************************************************************************\r
-\r
-  Function:     ATT5ESSUmes_0x07\r
-\r
-*****************************************************************************/\r
-L3INT ATT5ESSUmes_0x07(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)\r
-{\r
-       if (mes->ProtDisc == 8) {\r
-               return Q931Umes_Connect(pTrunk, IBuf, mes, IOff, Size);\r
-       }\r
-\r
-       if (mes->ProtDisc == 3) {\r
-               return Q931Umes_ServiceAck(pTrunk, IBuf, mes, IOff, Size);\r
-       }\r
-\r
-       return Q931E_UNKNOWN_MESSAGE;\r
-}\r
-\r
-/*****************************************************************************\r
-\r
-  Function:     ATT5ESSPmes_0x07\r
-\r
-*****************************************************************************/\r
-L3INT ATT5ESSPmes_0x07(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)\r
-{\r
-       Q931mes_Generic *mes = (Q931mes_Generic *)IBuf;\r
-\r
-       if (mes->ProtDisc == 8) {\r
-               return Q931Pmes_Connect(pTrunk, IBuf, ISize, OBuf, OSize);\r
-       }\r
-\r
-       if (mes->ProtDisc == 3) {\r
-               return Q931Pmes_ServiceAck(pTrunk, IBuf, ISize, OBuf, OSize);\r
-       }\r
-\r
-       return Q931E_UNKNOWN_MESSAGE;\r
-}\r
+/*****************************************************************************
+
+  FileName:    5ESSmes.c
+
+  Contents:    Pack/Unpack functions. These functions will unpack a 5ESS ISDN
+               message from the bit packed original format into structs
+               that contains variables sized by the user. It will also pack
+               the struct back into a Q.931 message as required.
+
+               See 5ESS.h for description. 
+
+  License/Copyright:
+
+  Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
+  email:janvb@caselaboratories.com  
+
+  Copyright (c) 2007, Michael Jerris. All rights reserved.
+  email:mike@jerris.com
+  
+  Copyright (c) 2007, Michael S. Collins, All rights reserved.
+  email:mcollins@fcnetwork.com
+
+  Redistribution and use in source and binary forms, with or without 
+  modification, are permitted provided that the following conditions are 
+  met:
+
+       * Redistributions of source code must retain the above copyright notice, 
+       this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright notice, 
+       this list of conditions and the following disclaimer in the documentation 
+       and/or other materials provided with the distribution.
+       * Neither the name of the Case Labs, Ltd nor the names of its contributors 
+       may be used to endorse or promote products derived from this software 
+       without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
+  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
+  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+  POSSIBILITY OF SUCH DAMAGE.
+
+*****************************************************************************/
+
+#include "5ESS.h"
+
+/*****************************************************************************
+
+  Function:     ATT5ESSUmes_Setup
+
+*****************************************************************************/
+L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
+{
+       L3INT ir = 0;
+       L3INT OOff = 0;
+       L3INT rc = Q931E_NO_ERROR;
+       L3UCHAR last_codeset = 0, codeset = 0;
+       L3UCHAR shift_nolock = 1;
+
+       while (IOff < Size) {
+
+               if (shift_nolock) {
+                       codeset = last_codeset;
+               }
+
+               if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT) {
+                       shift_nolock = (IBuf[IOff] & 0x08);
+                       if (shift_nolock) {
+                               last_codeset = codeset;
+                       }
+                       codeset = ((IBuf[IOff] & 0x07));
+                       IOff++;
+               }
+
+               if (codeset == 0) {
+                       switch (IBuf[IOff])
+                       {
+                       case Q931ie_SENDING_COMPLETE:
+                       case Q931ie_BEARER_CAPABILITY:
+                       case Q931ie_CHANNEL_IDENTIFICATION:
+                       case Q931ie_PROGRESS_INDICATOR:
+                       case Q931ie_NETWORK_SPECIFIC_FACILITIES:
+                       case Q931ie_DISPLAY:
+                       case Q931ie_DATETIME:
+                       case Q931ie_KEYPAD_FACILITY:
+                       case Q931ie_SIGNAL:
+                       case Q931ie_CALLING_PARTY_NUMBER:
+                       case Q931ie_CALLING_PARTY_SUBADDRESS:
+                       case Q931ie_CALLED_PARTY_NUMBER:
+                       case Q931ie_CALLED_PARTY_SUBADDRESS:
+                       case Q931ie_TRANSIT_NETWORK_SELECTION:
+                       case Q931ie_LOW_LAYER_COMPATIBILITY:
+                       case Q931ie_HIGH_LAYER_COMPATIBILITY:
+                       case Q931ie_FACILITY:
+                               rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
+                               if (rc != Q931E_NO_ERROR) 
+                                       return rc;
+                               break;
+                       case Q931ie_REPEAT_INDICATOR:
+                               if (ir < 2) {
+                                       rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
+                                       ir++;
+                               } else {
+                                       return Q931E_ILLEGAL_IE;
+                               }
+                               break;
+                       default:
+                               return Q931E_ILLEGAL_IE;
+                               break;
+                       }
+               } else if (codeset == 6) {
+                       switch (IBuf[IOff])
+                       {
+                       case Q931ie_GENERIC_DIGITS:
+                               rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
+                               if (rc != Q931E_NO_ERROR) 
+                                       return rc;
+                               break;
+                       default:
+                               return Q931E_ILLEGAL_IE;
+                               break;
+                       }
+               } else if (codeset == 7) {
+                       switch (IBuf[IOff])
+                       {
+                       case Q931ie_DISPLAY:
+                               rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
+                               if (rc != Q931E_NO_ERROR) 
+                                       return rc;
+                               break;
+                       default:
+                               return Q931E_ILLEGAL_IE;
+                               break;
+                       }
+               } else {
+                       return Q931E_ILLEGAL_IE;
+               }
+       }
+       mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
+       return Q931E_NO_ERROR;
+}
+
+/*****************************************************************************
+
+  Function:     ATT5ESSPmes_Setup
+
+  Decription:   Pack a Q931mes_Generic into a real Q.931 message. The user will
+                               set up a SETUP message and issue this to the stack where it
+                               is processed by Q931ProcSetup that processes and validates
+                               it before it actually sends it out. This function is called
+                               to compute the real Q.931 message.
+
+  Parameters:   IBuf[IN]       Ptr to un-packed struct
+                               ISize[IN]   Size of input buffer (unpacked message).
+                               OBuf[OUT]   Ptr to packed 'octet' wise message.
+                               OSize[OUT]  Size of packed message.
+
+  Called By:   Q931ProcSetup
+
+*****************************************************************************/
+L3INT ATT5ESSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
+{
+       L3INT rc = Q931E_NO_ERROR;
+       Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
+       L3INT Octet = 0;
+
+       /* Q931 Message Header */
+       Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
+       
+       /* Sending Complete                             */
+       if (Q931IsIEPresent(pMes->SendComplete)) {
+               OBuf[Octet++]   = (L3UCHAR)(pMes->SendComplete & 0x00ff);
+       }
+
+       /* Repeat Indicator */
+       if (Q931IsIEPresent(pMes->RepeatInd)) {
+               OBuf[Octet++]   = (L3UCHAR)(pMes->RepeatInd & 0x00ff);
+       }
+
+       /* Bearer capability */
+       if (Q931IsIEPresent(pMes->BearerCap)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       } else {
+               rc = Q931E_BEARERCAP;
+       }
+
+       /* Channel Identification */
+       if (Q931IsIEPresent(pMes->ChanID)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Progress indicator */
+       if (Q931IsIEPresent(pMes->ProgInd)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Network specific facilities */
+       if (Q931IsIEPresent(pMes->NetFac)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_NETWORK_SPECIFIC_FACILITIES](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Display */
+       if (Q931IsIEPresent(pMes->Display)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Date/Time */
+       if (Q931IsIEPresent(pMes->DateTime)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DATETIME](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Keypad Facility */
+       if (Q931IsIEPresent(pMes->KeypadFac)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_KEYPAD_FACILITY](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Signal */
+       if (Q931IsIEPresent(pMes->Signal)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Calling Party Number */
+       if (Q931IsIEPresent(pMes->CallingNum)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Calling Party Subaddress */
+       if (Q931IsIEPresent(pMes->CallingSub)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Called Party number */
+       if (Q931IsIEPresent(pMes->CalledNum)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Called party subaddress */
+       if (Q931IsIEPresent(pMes->CalledSub)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Transit network selection */
+       if (Q931IsIEPresent(pMes->TransNetSel)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_TRANSIT_NETWORK_SELECTION](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* Repeat Indicator */
+       if (Q931IsIEPresent(pMes->LLRepeatInd)) {
+               rc = Q931E_UNKNOWN_IE;/* TODO */
+       }
+
+       /* Low Layer Compatibility */
+       if (Q931IsIEPresent(pMes->LLComp)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_LOW_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       /* High Layer Compatibility */
+       if (Q931IsIEPresent(pMes->HLComp)) {
+               if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0)
+                       return rc;
+       }
+
+       *OSize = Octet;
+       return rc;
+}
+
+
+/*****************************************************************************
+
+  Function:     ATT5ESSUmes_0x0f
+
+*****************************************************************************/
+L3INT ATT5ESSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
+{
+       if (mes->ProtDisc == 8) {
+               return Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size);
+       }
+
+       if (mes->ProtDisc == 3) {
+               return Q931Umes_Service(pTrunk, IBuf, mes, IOff, Size);
+       }
+
+       return Q931E_UNKNOWN_MESSAGE;
+}
+
+/*****************************************************************************
+
+  Function:     ATT5ESSPmes_0x0f
+
+*****************************************************************************/
+L3INT ATT5ESSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
+{
+       Q931mes_Generic *mes = (Q931mes_Generic *)IBuf;
+
+       if (mes->ProtDisc == 8) {
+               return Q931Pmes_ConnectAck(pTrunk, IBuf, ISize, OBuf, OSize);
+       }
+
+       if (mes->ProtDisc == 3) {
+               return Q931Pmes_Service(pTrunk, IBuf, ISize, OBuf, OSize);
+       }
+
+       return Q931E_UNKNOWN_MESSAGE;
+}
+
+/*****************************************************************************
+
+  Function:     ATT5ESSUmes_0x07
+
+*****************************************************************************/
+L3INT ATT5ESSUmes_0x07(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
+{
+       if (mes->ProtDisc == 8) {
+               return Q931Umes_Connect(pTrunk, IBuf, mes, IOff, Size);
+       }
+
+       if (mes->ProtDisc == 3) {
+               return Q931Umes_ServiceAck(pTrunk, IBuf, mes, IOff, Size);
+       }
+
+       return Q931E_UNKNOWN_MESSAGE;
+}
+
+/*****************************************************************************
+
+  Function:     ATT5ESSPmes_0x07
+
+*****************************************************************************/
+L3INT ATT5ESSPmes_0x07(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
+{
+       Q931mes_Generic *mes = (Q931mes_Generic *)IBuf;
+
+       if (mes->ProtDisc == 8) {
+               return Q931Pmes_Connect(pTrunk, IBuf, ISize, OBuf, OSize);
+       }
+
+       if (mes->ProtDisc == 3) {
+               return Q931Pmes_ServiceAck(pTrunk, IBuf, ISize, OBuf, OSize);
+       }
+
+       return Q931E_UNKNOWN_MESSAGE;
+}
index 2c5193d7246fb1b7df9397a338cdb77aca611b03..2f3a129293ff3ff71de3330b59e4d9e377d31d0b 100644 (file)
@@ -1,11 +1,11 @@
-\r
-#Test iLBC executable for 20 and 30 ms frames on a clean channel\r
-\r
-./iLBC_test 20 iLBC.INP iLBC_20ms.BIT iLBC_20ms_clean.OUT clean.chn\r
-./iLBC_test 30 iLBC.INP iLBC_30ms.BIT iLBC_30ms_clean.OUT clean.chn\r
-\r
-#Test iLBC executable for 20 and 30 ms frames on a channel with ~5% packet losses\r
-\r
-./iLBC_test 20 iLBC.INP tmp.BIT iLBC_20ms_tlm05.OUT tlm05.chn\r
-./iLBC_test 30 iLBC.INP tmp.BIT iLBC_30ms_tlm05.OUT tlm05.chn\r
-\r
+
+#Test iLBC executable for 20 and 30 ms frames on a clean channel
+
+./iLBC_test 20 iLBC.INP iLBC_20ms.BIT iLBC_20ms_clean.OUT clean.chn
+./iLBC_test 30 iLBC.INP iLBC_30ms.BIT iLBC_30ms_clean.OUT clean.chn
+
+#Test iLBC executable for 20 and 30 ms frames on a channel with ~5% packet losses
+
+./iLBC_test 20 iLBC.INP tmp.BIT iLBC_20ms_tlm05.OUT tlm05.chn
+./iLBC_test 30 iLBC.INP tmp.BIT iLBC_30ms_tlm05.OUT tlm05.chn
+
index 23a53e95073a6b3181c2fa1885af9500a2757ec5..e8c5f6232c5bc785c8a758717c8adf0ab7a8a8db 100644 (file)
@@ -1,74 +1,74 @@
-/*\r
- * libZRTP SDK library, implements the ZRTP secure VoIP protocol.\r
- * Copyright (c) 2006-2009 Philip R. Zimmermann.  All rights reserved.\r
- * Contact: http://philzimmermann.com\r
- * For licensing and other legal details, see the file zrtp_legal.c.\r
- * \r
- * Viktor Krykun <v.krikun at zfoneproject.com> \r
- */\r
-\r
-#ifndef ZRTP_WIN_CONFIG_H__\r
-#define ZRTP_WIN_CONFIG_H__\r
-\r
-#define        _CRT_SECURE_NO_WARNINGS 1\r
-#pragma        warning(disable: 4068)\r
-\r
-#if !(defined(__BUILDMACHINE__) && __BUILDMACHINE__ == WinDDK)\r
-#include <Windows.h>\r
-#endif\r
-\r
-/*\r
- * Used to map system integer types to zrtp integer definitions.\r
- * Define to 1 if you have the <inttypes.h> header file.\r
- */\r
-#undef ZRTP_HAVE_INTTYPES_H\r
-\r
-#define ZRTP_HAVE_STRING_H     1\r
-\r
-/*\r
- * This header is needed for operations with binary file in deefault realization\r
- * of the secrets' cache. Can be eliminated if default cache isn't used.\r
- * Define to 1 if you have the <stdio.h> header file.\r
- */\r
-#ifndef ZRTP_HAVE_STDIO_H\r
-#      define ZRTP_HAVE_STDIO_H 1\r
-#endif\r
-\r
-#ifndef ZRTP_HAVE_STDARG_H\r
-#      define ZRTP_HAVE_STDARG_H 1\r
-#endif\r
-\r
-/*\r
- * Used by bnlib, but we don't need this on Windows platform.\r
- */\r
-#ifndef NO_ASSERT_H\r
-       #define NO_ASSERT_H 1\r
-#endif\r
-\r
-/*\r
- * Used by bnlib. We have stdlib in any Windows platform - set it to 1.\r
- */\r
-#ifndef NO_STDLIB_H\r
-       #define NO_STDLIB_H 0\r
-#endif\r
-\r
-\r
-#define ZRTP_HAVE_INT64_T 0\r
-#define ZRTP_HAVE_INT32_T 0\r
-#define ZRTP_HAVE_INT16_T 0\r
-#define ZRTP_HAVE_INT8_T  0\r
-\r
-#define ZRTP_HAVE_UINT64_T 0\r
-#define ZRTP_HAVE_UINT32_T 0\r
-#define ZRTP_HAVE_UINT16_T 0\r
-#define ZRTP_HAVE_UINT8_T  0\r
-\r
-#define SIZEOF_UNSIGNED_LONG 4\r
-#define SIZEOF_UNSIGNED_LONG_LONG 8\r
-\r
-#define ZRTP_INLINE static __inline\r
-\r
-#define ZRTP_VERSION   "0.90"\r
-\r
-\r
-#endif /* ZRTP_WIN_CONFIG_H__ */\r
+/*
+ * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
+ * Copyright (c) 2006-2009 Philip R. Zimmermann.  All rights reserved.
+ * Contact: http://philzimmermann.com
+ * For licensing and other legal details, see the file zrtp_legal.c.
+ * 
+ * Viktor Krykun <v.krikun at zfoneproject.com> 
+ */
+
+#ifndef ZRTP_WIN_CONFIG_H__
+#define ZRTP_WIN_CONFIG_H__
+
+#define        _CRT_SECURE_NO_WARNINGS 1
+#pragma        warning(disable: 4068)
+
+#if !(defined(__BUILDMACHINE__) && __BUILDMACHINE__ == WinDDK)
+#include <Windows.h>
+#endif
+
+/*
+ * Used to map system integer types to zrtp integer definitions.
+ * Define to 1 if you have the <inttypes.h> header file.
+ */
+#undef ZRTP_HAVE_INTTYPES_H
+
+#define ZRTP_HAVE_STRING_H     1
+
+/*
+ * This header is needed for operations with binary file in deefault realization
+ * of the secrets' cache. Can be eliminated if default cache isn't used.
+ * Define to 1 if you have the <stdio.h> header file.
+ */
+#ifndef ZRTP_HAVE_STDIO_H
+#      define ZRTP_HAVE_STDIO_H 1
+#endif
+
+#ifndef ZRTP_HAVE_STDARG_H
+#      define ZRTP_HAVE_STDARG_H 1
+#endif
+
+/*
+ * Used by bnlib, but we don't need this on Windows platform.
+ */
+#ifndef NO_ASSERT_H
+       #define NO_ASSERT_H 1
+#endif
+
+/*
+ * Used by bnlib. We have stdlib in any Windows platform - set it to 1.
+ */
+#ifndef NO_STDLIB_H
+       #define NO_STDLIB_H 0
+#endif
+
+
+#define ZRTP_HAVE_INT64_T 0
+#define ZRTP_HAVE_INT32_T 0
+#define ZRTP_HAVE_INT16_T 0
+#define ZRTP_HAVE_INT8_T  0
+
+#define ZRTP_HAVE_UINT64_T 0
+#define ZRTP_HAVE_UINT32_T 0
+#define ZRTP_HAVE_UINT16_T 0
+#define ZRTP_HAVE_UINT8_T  0
+
+#define SIZEOF_UNSIGNED_LONG 4
+#define SIZEOF_UNSIGNED_LONG_LONG 8
+
+#define ZRTP_INLINE static __inline
+
+#define ZRTP_VERSION   "0.90"
+
+
+#endif /* ZRTP_WIN_CONFIG_H__ */
index c9e6fb7892e2705117d12153430bee7129d5d797..e0297d63fff71b918eb2a70dfe9b6ca6bde1e708 100644 (file)
@@ -1,79 +1,79 @@
-/*\r
- ============================================================================\r
- Name          : CDelayRuner.cpp\r
- Author          : R. Drutsky\r
- Version        : 1.0\r
- Copyright   : Copyright (c) 2010 Soft Industry\r
- Description : CCDelayRuner implementation\r
- ============================================================================\r
- */\r
-\r
-#include "DelayRuner.h"\r
-#include "zrtp_iface_system.h"\r
-\r
-void zrtp_internal_delete_task_from_list(zrtp_stream_t* ctx, zrtp_retry_task_t* ztask);\r
-\r
-CDelayRuner::CDelayRuner() :\r
-       CActive(EPriorityLow) // Standard priority\r
-       {\r
-       }\r
-\r
-CDelayRuner* CDelayRuner::NewLC()\r
-       {\r
-       CDelayRuner* self = new (ELeave) CDelayRuner();\r
-       CleanupStack::PushL(self);\r
-       self->ConstructL();\r
-       return self;\r
-       }\r
-\r
-CDelayRuner* CDelayRuner::NewL()\r
-       {\r
-       CDelayRuner* self = CDelayRuner::NewLC();\r
-       CleanupStack::Pop(); // self;\r
-       return self;\r
-       }\r
-\r
-void CDelayRuner::ConstructL()\r
-       {\r
-       User::LeaveIfError(iTimer.CreateLocal()); // Initialize timer\r
-       CActiveScheduler::Add(this); // Add to scheduler\r
-       }\r
-\r
-CDelayRuner::~CDelayRuner()\r
-       {\r
-       Cancel(); // Cancel any request, if outstanding\r
-       iTimer.Close(); // Destroy the RTimer object\r
-       // Delete instance variables if any\r
-       }\r
-\r
-void CDelayRuner::DoCancel()\r
-       {\r
-       iTimer.Cancel();\r
-       }\r
-\r
-void CDelayRuner::StartL(zrtp_stream_t *ctx, zrtp_retry_task_t* ztask)\r
-       {\r
-       Cancel(); // Cancel any request, just to be sure\r
-       //iState = EUninitialized;\r
-       iCtx = ctx;\r
-       iZTask = ztask;\r
-       iTimer.After(iStatus, ztask->timeout * 1000); // Set for later\r
-       SetActive(); // Tell scheduler a request is active\r
-       }\r
-\r
-void CDelayRuner::RunL()\r
-       {\r
-       if (iStatus == KErrNone)\r
-               {\r
-               // Do something useful\r
-               iZTask->_is_busy = 1 ; // may be we don't need this\r
-               (iZTask->callback)(iCtx,iZTask);\r
-               iZTask->_is_busy = 0 ; // may be we don't need this\r
-               }\r
-       zrtp_internal_delete_task_from_list(iCtx,iZTask);\r
-       }\r
-\r
-TInt CDelayRuner::RunError(TInt aError)\r
-       {\r
-       return aError;\r
-       }\r
+/*
+ ============================================================================
+ Name          : CDelayRuner.cpp
+ Author          : R. Drutsky
+ Version        : 1.0
+ Copyright   : Copyright (c) 2010 Soft Industry
+ Description : CCDelayRuner implementation
+ ============================================================================
+ */
+
+#include "DelayRuner.h"
+#include "zrtp_iface_system.h"
+
+void zrtp_internal_delete_task_from_list(zrtp_stream_t* ctx, zrtp_retry_task_t* ztask);
+
+CDelayRuner::CDelayRuner() :
+       CActive(EPriorityLow) // Standard priority
+       {
+       }
+
+CDelayRuner* CDelayRuner::NewLC()
+       {
+       CDelayRuner* self = new (ELeave) CDelayRuner();
+       CleanupStack::PushL(self);
+       self->ConstructL();
+       return self;
+       }
+
+CDelayRuner* CDelayRuner::NewL()
+       {
+       CDelayRuner* self = CDelayRuner::NewLC();
+       CleanupStack::Pop(); // self;
+       return self;
+       }
+
+void CDelayRuner::ConstructL()
+       {
+       User::LeaveIfError(iTimer.CreateLocal()); // Initialize timer
+       CActiveScheduler::Add(this); // Add to scheduler
+       }
+
+CDelayRuner::~CDelayRuner()
+       {
+       Cancel(); // Cancel any request, if outstanding
+       iTimer.Close(); // Destroy the RTimer object
+       // Delete instance variables if any
+       }
+
+void CDelayRuner::DoCancel()
+       {
+       iTimer.Cancel();
+       }
+
+void CDelayRuner::StartL(zrtp_stream_t *ctx, zrtp_retry_task_t* ztask)
+       {
+       Cancel(); // Cancel any request, just to be sure
+       //iState = EUninitialized;
+       iCtx = ctx;
+       iZTask = ztask;
+       iTimer.After(iStatus, ztask->timeout * 1000); // Set for later
+       SetActive(); // Tell scheduler a request is active
+       }
+
+void CDelayRuner::RunL()
+       {
+       if (iStatus == KErrNone)
+               {
+               // Do something useful
+               iZTask->_is_busy = 1 ; // may be we don't need this
+               (iZTask->callback)(iCtx,iZTask);
+               iZTask->_is_busy = 0 ; // may be we don't need this
+               }
+       zrtp_internal_delete_task_from_list(iCtx,iZTask);
+       }
+
+TInt CDelayRuner::RunError(TInt aError)
+       {
+       return aError;
+       }
index 39679c6fc4de9b9462c6a4296caedbdbd510b61f..58fa5ddc9b6ab4f20704fae6732f60c57ce8adb3 100644 (file)
@@ -1,72 +1,72 @@
-/*\r
- ============================================================================\r
- Name          : CDelayRuner.h\r
- Author          : R. Drutsky\r
- Version        : 1.0\r
- Copyright   : Copyright (c) 2010 Soft Industry\r
- Description : CDelayRuner declaration\r
- ============================================================================\r
- */\r
-\r
-#ifndef DELAYRUNER_H\r
-#define DELAYRUNER_H\r
-\r
-#include <e32base.h>   // For CActive, link against: euser.lib\r
-#include <e32std.h>            // For RTimer, link against: euser.lib\r
-\r
-#include <zrtp.h>\r
-class CDelayRuner : public CActive\r
-       {\r
-public:\r
-       // Cancel and destroy\r
-       ~CDelayRuner();\r
-\r
-       // Two-phased constructor.\r
-       static CDelayRuner* NewL();\r
-\r
-       // Two-phased constructor.\r
-       static CDelayRuner* NewLC();\r
-\r
-public:\r
-       // New functions\r
-       // Function for making the initial request\r
-       void StartL(zrtp_stream_t *ctx, zrtp_retry_task_t* ztask);\r
-\r
-private:\r
-       // C++ constructor\r
-       CDelayRuner();\r
-\r
-       // Second-phase constructor\r
-       void ConstructL();\r
-\r
-private:\r
-       // From CActive\r
-       // Handle completion\r
-       void RunL();\r
-\r
-       // How to cancel me\r
-       void DoCancel();\r
-\r
-       // Override to handle leaves from RunL(). Default implementation causes\r
-       // the active scheduler to panic.\r
-       TInt RunError(TInt aError);\r
-\r
-private:\r
-       enum TCDelayRunerState\r
-               {\r
-               EUninitialized, // Uninitialized\r
-               EInitialized, // Initalized\r
-               EError\r
-               // Error condition\r
-               };\r
-\r
-private:\r
-       TInt iState; // State of the active object\r
-       RTimer iTimer; // Provides async timing service\r
-       \r
-       zrtp_stream_t *iCtx;\r
-       zrtp_retry_task_t * iZTask;\r
-\r
-       };\r
-\r
-#endif // CDELAYRUNER_H\r
+/*
+ ============================================================================
+ Name          : CDelayRuner.h
+ Author          : R. Drutsky
+ Version        : 1.0
+ Copyright   : Copyright (c) 2010 Soft Industry
+ Description : CDelayRuner declaration
+ ============================================================================
+ */
+
+#ifndef DELAYRUNER_H
+#define DELAYRUNER_H
+
+#include <e32base.h>   // For CActive, link against: euser.lib
+#include <e32std.h>            // For RTimer, link against: euser.lib
+
+#include <zrtp.h>
+class CDelayRuner : public CActive
+       {
+public:
+       // Cancel and destroy
+       ~CDelayRuner();
+
+       // Two-phased constructor.
+       static CDelayRuner* NewL();
+
+       // Two-phased constructor.
+       static CDelayRuner* NewLC();
+
+public:
+       // New functions
+       // Function for making the initial request
+       void StartL(zrtp_stream_t *ctx, zrtp_retry_task_t* ztask);
+
+private:
+       // C++ constructor
+       CDelayRuner();
+
+       // Second-phase constructor
+       void ConstructL();
+
+private:
+       // From CActive
+       // Handle completion
+       void RunL();
+
+       // How to cancel me
+       void DoCancel();
+
+       // Override to handle leaves from RunL(). Default implementation causes
+       // the active scheduler to panic.
+       TInt RunError(TInt aError);
+
+private:
+       enum TCDelayRunerState
+               {
+               EUninitialized, // Uninitialized
+               EInitialized, // Initalized
+               EError
+               // Error condition
+               };
+
+private:
+       TInt iState; // State of the active object
+       RTimer iTimer; // Provides async timing service
+       
+       zrtp_stream_t *iCtx;
+       zrtp_retry_task_t * iZTask;
+
+       };
+
+#endif // CDELAYRUNER_H
index e722b6841822f3c2e9b13bb9e63080ff170b40f4..af49c77d4919cc3479e477ccfc3607c6cf1e3b13 100644 (file)
-/*\r
- * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.\r
- * Contact: http://philzimmermann.com\r
- * For licensing and other legal details, see the file zrtp_legal.c.\r
- */\r
-\r
-#include <charconv.h>\r
-#include <stdarg.h>\r
-#include <sys/time.h>\r
-\r
-#include <e32msgqueue.h>\r
-\r
-#include <UNISTD.H>\r
-#include <e32base.h>\r
-#include <e32math.h>\r
-\r
-#include <zrtp.h>\r
-\r
-extern "C"\r
-{\r
-/**\r
- * @brief Get kernel-generated random number\r
- * @bug                seems not work\r
- * @return 32 random bits\r
- */\r
-uint32_t zrtp_symbian_kernel_random();\r
-\r
-/**\r
- * @brief Pseudo random number: sum of pid's shifted and xored by number of precceses \r
- * @return\r
- */\r
-uint32_t zrtp_sum_of_pid_and_number_of_poccesses();\r
-\r
-/**\r
- * @brief Number of milisecond past from particular date and time\r
- * @return\r
- */\r
-uint64_t zrtp_get_system_time_crazy();\r
-\r
-/**\r
- * @brief Current procces PID\r
- * @return PID\r
- */\r
-unsigned int zrtp_get_pid();\r
-\r
-/**\r
- * @brief Availible memory\r
- * @return memory availible on heap\r
- */\r
-uint32_t zrtp_get_availible_heap();\r
-\r
-}\r
-\r
-\r
-\r
-//-----------------------------------------------------------------------------\r
-zrtp_status_t zrtp_mutex_init(zrtp_mutex_t **mutex) {\r
-       RMutex *rmutex = new RMutex();\r
-       //rmutex->CreateLocal(); was before\r
-       rmutex->CreateGlobal(KNullDesC);\r
-       *mutex = (zrtp_mutex_t*) rmutex;\r
-       return zrtp_status_ok;  \r
-}\r
-\r
-zrtp_status_t zrtp_mutex_lock(zrtp_mutex_t* mutex) {\r
-       RMutex *rmutex = (RMutex *) mutex;\r
-       rmutex->Wait();\r
-       return zrtp_status_ok;  \r
-}\r
-\r
-zrtp_status_t zrtp_mutex_unlock(zrtp_mutex_t* mutex) {\r
-       RMutex *rmutex = (RMutex *) mutex;\r
-       rmutex->Signal();\r
-       return zrtp_status_ok;  \r
-}\r
-\r
-zrtp_status_t zrtp_mutex_destroy(zrtp_mutex_t* mutex) {\r
-       RMutex *rmutex = (RMutex *) mutex;\r
-       if (rmutex) {\r
-               rmutex->Close();\r
-               delete rmutex;\r
-       }\r
-       return zrtp_status_ok;  \r
-}\r
-\r
-//-----------------------------------------------------------------------------\r
-zrtp_status_t zrtp_sem_init(zrtp_sem_t** sem, uint32_t value, uint32_t limit) {\r
-       RSemaphore *rsem = new RSemaphore();\r
-       //rsem->CreateLocal(value);\r
-       rsem->CreateGlobal(KNullDesC,value);\r
-       *sem = (zrtp_sem_t*) rsem;\r
-       return zrtp_status_ok;  \r
-}\r
-\r
-zrtp_status_t zrtp_sem_destroy(zrtp_sem_t* sem) {\r
-       RSemaphore *rsem = (RSemaphore *) sem;\r
-       if (rsem) {\r
-               rsem->Close();\r
-               delete rsem;\r
-       }\r
-       return zrtp_status_ok;     \r
-}\r
-\r
-zrtp_status_t zrtp_sem_wait(zrtp_sem_t* sem) {\r
-       RSemaphore *rsem = (RSemaphore *) sem;\r
-       rsem->Wait();\r
-       return zrtp_status_ok;     \r
-}\r
-\r
-zrtp_status_t zrtp_sem_trtwait(zrtp_sem_t* sem) {\r
-       RSemaphore *rsem = (RSemaphore *) sem;\r
-       rsem->Wait(1000);\r
-       return zrtp_status_ok;     \r
-}\r
-\r
-zrtp_status_t zrtp_sem_post(zrtp_sem_t* sem) {\r
-       RSemaphore *rsem = (RSemaphore *) sem;\r
-       rsem->Signal();\r
-       return zrtp_status_ok;     \r
-}\r
-\r
-//-----------------------------------------------------------------------------\r
-int zrtp_sleep(unsigned int msec) {\r
-       TTimeIntervalMicroSeconds32 i(msec *1000);\r
-       User::After(i);\r
-       return 0;\r
-}\r
-\r
-int zrtp_thread_create(zrtp_thread_routine_t start_routine, void *arg) {   \r
-       RThread h;\r
-       TBuf<64> thName=_L("zrtp_thread");\r
-\r
-       h.Create(thName, start_routine, KDefaultStackSize*2, NULL, arg) ;   \r
-       h.Resume();\r
-       h.Close();\r
-   \r
-   return NULL;\r
-}\r
-//-----------------------------------------------------------------------------\r
-//                     For Scheduler\r
-#if (defined(ZRTP_USE_BUILTIN_SCEHDULER) && (ZRTP_USE_BUILTIN_SCEHDULER ==1))\r
-\r
-#include "DelayRuner.h"\r
-#include "zrtp_error.h"\r
-mlist_t                tasks_head_s;\r
-static uint8_t inited = 0 ;\r
-static uint8_t is_running = 0;\r
-\r
-typedef struct {    \r
-       zrtp_stream_t   *ctx;           /** ZRTP stream context associated with the task */\r
-       zrtp_retry_task_t       *ztask;         /** ZRTP stream associated with the task */\r
-       mlist_t                         _mlist;\r
-       CDelayRuner*                    ao;             // Active object\r
-} zrtp_sched_task_s_t;\r
-\r
-zrtp_status_t zrtp_def_scheduler_init(zrtp_global_t* zrtp)\r
-{      \r
-       zrtp_status_t status = zrtp_status_ok;\r
-       ZRTP_LOG(3,("symbian","Init start"));   \r
-       if (inited) {\r
-               return zrtp_status_ok;\r
-       }\r
-\r
-       do {\r
-               init_mlist(&tasks_head_s);\r
-               is_running = 1;\r
-               inited  = 1;\r
-       } while (0);\r
-\r
-       ZRTP_LOG(3,("symbian","Init end"));\r
-       return status;\r
-}\r
-\r
-void zrtp_def_scheduler_down()\r
-{      \r
-       ZRTP_LOG(3,("symbian","Down start"));\r
-       mlist_t *node = 0, *tmp = 0;\r
-       \r
-       if (!inited) {\r
-               return;\r
-       }\r
-\r
-       /* Stop main thread */          \r
-       is_running = 0; \r
-//     zrtp_sem_post(count);\r
-       \r
-       /* Then destroy tasks queue and realease all other resources */\r
-       //zrtp_mutex_lock(protector);\r
-\r
-       mlist_for_each_safe(node, tmp, &tasks_head_s) {\r
-               zrtp_sched_task_s_t* task = mlist_get_struct(zrtp_sched_task_s_t, _mlist, node);\r
-               if (task->ao!=NULL)\r
-                       {\r
-                       delete task->ao;\r
-                       }\r
-               zrtp_sys_free(task);\r
-       }\r
-       init_mlist(&tasks_head_s);\r
-\r
-//     zrtp_mutex_unlock(protector);\r
-       \r
-//     zrtp_mutex_destroy(protector);\r
-//     zrtp_sem_destroy(count);\r
-\r
-       ZRTP_LOG(3,("symbian","Down end"));\r
-       inited  = 0;\r
-}\r
-\r
-\r
-void zrtp_def_scheduler_call_later(zrtp_stream_t *ctx, zrtp_retry_task_t* ztask)\r
-{      \r
-//     ZRTP_LOG(3,("symbian","CallLater start"));\r
-       //mlist_t *node=0, *tmp=0;                      \r
-       mlist_t* last = &tasks_head_s;\r
-\r
-       //zrtp_mutex_lock(protector);\r
-\r
-       if (!ztask->_is_enabled) {\r
-               //zrtp_mutex_unlock(protector);\r
-               return;\r
-       }\r
-\r
-       do {\r
-               zrtp_sched_task_s_t* new_task = (zrtp_sched_task_s_t*)zrtp_sys_alloc(sizeof(zrtp_sched_task_s_t));\r
-               if (!new_task) {\r
-                       break;\r
-               }\r
-\r
-               new_task->ctx                   = ctx;\r
-               new_task->ztask                 = ztask;                \r
-               new_task->ao                    = CDelayRuner::NewL();\r
-               \r
-               mlist_insert(last, &new_task->_mlist);          \r
-               \r
-               new_task->ao->StartL(ctx,ztask);\r
-               //zrtp_sem_post(count);\r
-       } while (0);\r
-\r
-       //ZRTP_LOG(3,("symbian","CallLater end"));\r
-       //zrtp_mutex_unlock(protector);         \r
-}\r
-\r
-void zrtp_def_scheduler_cancel_call_later(zrtp_stream_t* ctx, zrtp_retry_task_t* ztask)\r
-{\r
-       mlist_t *node=0, *tmp=0;\r
-       ZRTP_LOG(3,("symbian","CancelcallLater start"));\r
-//     zrtp_mutex_lock(protector);\r
-\r
-       mlist_for_each_safe(node, tmp, &tasks_head_s) {\r
-               zrtp_sched_task_s_t* task = mlist_get_struct(zrtp_sched_task_s_t, _mlist, node);\r
-               if ((task->ctx == ctx) && ((task->ztask == ztask) || !ztask)) {\r
-                       task->ao->Cancel();\r
-                       delete task->ao; // Cancel and delete task\r
-                       mlist_del(&task->_mlist);\r
-                       zrtp_sys_free(task);\r
-                       //zrtp_sem_trtwait(count);\r
-                       if (ztask) {\r
-                               break;\r
-                       }\r
-               }\r
-       }\r
-       ZRTP_LOG(3,("symbian","CancelCallLater done"));\r
-//     zrtp_mutex_unlock(protector);   \r
-}\r
-\r
-void zrtp_internal_delete_task_from_list(zrtp_stream_t* ctx, zrtp_retry_task_t* ztask)\r
-       {\r
-       mlist_t *node=0, *tmp=0;\r
-       ZRTP_LOG(3,("symbian","DelTask begin"));\r
-       mlist_for_each_safe(node, tmp, &tasks_head_s) \r
-               {\r
-               zrtp_sched_task_s_t* task = mlist_get_struct(zrtp_sched_task_s_t, _mlist, node);\r
-               if ((task->ctx == ctx) && ((task->ztask == ztask) || !ztask)) \r
-                       {\r
-                       delete task->ao; // Cancel and delete task\r
-                       mlist_del(&task->_mlist);\r
-                       zrtp_sys_free(task);\r
-                       ZRTP_LOG(3,("symbian","DelTask Del"));\r
-                       //zrtp_sem_trtwait(count);\r
-                       if (ztask) \r
-                               {\r
-                               break;\r
-                               }\r
-                       }\r
-               }\r
-       ZRTP_LOG(3,("symbian","DelTask end"));\r
-       }\r
-\r
-void zrtp_def_scheduler_wait_call_later(zrtp_stream_t* ctx)\r
-{\r
-}\r
-#endif // ZRTP_USE_BUILTIN_SCEHDULER\r
-//-----------------------------------------------------------------------------\r
-\r
-unsigned int zrtp_get_pid()\r
-       {\r
-       return getpid();\r
-       }\r
-\r
-uint64_t zrtp_get_system_time_crazy()\r
-       {\r
-       TTime time;\r
-       \r
-       return time.MicroSecondsFrom(TTime(TDateTime (491,EAugust,7,3,37,17,347))).Int64();\r
-       }\r
-\r
-uint32_t zrtp_sum_of_pid_and_number_of_poccesses()\r
-       {\r
-       TFindProcess fp;\r
-       RProcess procces;\r
-       TFullName proccesName;\r
-       uint_32t idsum=1;\r
-       uint_32t proccesCount=0;\r
-       fp.Find(KNullDesC);\r
-       while (fp.Next(proccesName)==KErrNone)\r
-               {\r
-                if (procces.Open(proccesName,EOwnerProcess)==KErrNone)\r
-                        {\r
-                        idsum+=procces.Id();\r
-                        proccesCount++;\r
-                        procces.Close();\r
-                        }\r
-               }\r
-       idsum = (idsum << 3) xor proccesCount;\r
-       return idsum;\r
-       }\r
-\r
-uint32_t zrtp_get_availible_heap()\r
-       {\r
-       return User::Heap().MaxLength();\r
-       }\r
-\r
-uint32_t zrtp_symbian_kernel_random()\r
-       {\r
-       return Math::Random();\r
-       }\r
+/*
+ * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
+ * Contact: http://philzimmermann.com
+ * For licensing and other legal details, see the file zrtp_legal.c.
+ */
+
+#include <charconv.h>
+#include <stdarg.h>
+#include <sys/time.h>
+
+#include <e32msgqueue.h>
+
+#include <UNISTD.H>
+#include <e32base.h>
+#include <e32math.h>
+
+#include <zrtp.h>
+
+extern "C"
+{
+/**
+ * @brief Get kernel-generated random number
+ * @bug                seems not work
+ * @return 32 random bits
+ */
+uint32_t zrtp_symbian_kernel_random();
+
+/**
+ * @brief Pseudo random number: sum of pid's shifted and xored by number of precceses 
+ * @return
+ */
+uint32_t zrtp_sum_of_pid_and_number_of_poccesses();
+
+/**
+ * @brief Number of milisecond past from particular date and time
+ * @return
+ */
+uint64_t zrtp_get_system_time_crazy();
+
+/**
+ * @brief Current procces PID
+ * @return PID
+ */
+unsigned int zrtp_get_pid();
+
+/**
+ * @brief Availible memory
+ * @return memory availible on heap
+ */
+uint32_t zrtp_get_availible_heap();
+
+}
+
+
+
+//-----------------------------------------------------------------------------
+zrtp_status_t zrtp_mutex_init(zrtp_mutex_t **mutex) {
+       RMutex *rmutex = new RMutex();
+       //rmutex->CreateLocal(); was before
+       rmutex->CreateGlobal(KNullDesC);
+       *mutex = (zrtp_mutex_t*) rmutex;
+       return zrtp_status_ok;  
+}
+
+zrtp_status_t zrtp_mutex_lock(zrtp_mutex_t* mutex) {
+       RMutex *rmutex = (RMutex *) mutex;
+       rmutex->Wait();
+       return zrtp_status_ok;  
+}
+
+zrtp_status_t zrtp_mutex_unlock(zrtp_mutex_t* mutex) {
+       RMutex *rmutex = (RMutex *) mutex;
+       rmutex->Signal();
+       return zrtp_status_ok;  
+}
+
+zrtp_status_t zrtp_mutex_destroy(zrtp_mutex_t* mutex) {
+       RMutex *rmutex = (RMutex *) mutex;
+       if (rmutex) {
+               rmutex->Close();
+               delete rmutex;
+       }
+       return zrtp_status_ok;  
+}
+
+//-----------------------------------------------------------------------------
+zrtp_status_t zrtp_sem_init(zrtp_sem_t** sem, uint32_t value, uint32_t limit) {
+       RSemaphore *rsem = new RSemaphore();
+       //rsem->CreateLocal(value);
+       rsem->CreateGlobal(KNullDesC,value);
+       *sem = (zrtp_sem_t*) rsem;
+       return zrtp_status_ok;  
+}
+
+zrtp_status_t zrtp_sem_destroy(zrtp_sem_t* sem) {
+       RSemaphore *rsem = (RSemaphore *) sem;
+       if (rsem) {
+               rsem->Close();
+               delete rsem;
+       }
+       return zrtp_status_ok;     
+}
+
+zrtp_status_t zrtp_sem_wait(zrtp_sem_t* sem) {
+       RSemaphore *rsem = (RSemaphore *) sem;
+       rsem->Wait();
+       return zrtp_status_ok;     
+}
+
+zrtp_status_t zrtp_sem_trtwait(zrtp_sem_t* sem) {
+       RSemaphore *rsem = (RSemaphore *) sem;
+       rsem->Wait(1000);
+       return zrtp_status_ok;     
+}
+
+zrtp_status_t zrtp_sem_post(zrtp_sem_t* sem) {
+       RSemaphore *rsem = (RSemaphore *) sem;
+       rsem->Signal();
+       return zrtp_status_ok;     
+}
+
+//-----------------------------------------------------------------------------
+int zrtp_sleep(unsigned int msec) {
+       TTimeIntervalMicroSeconds32 i(msec *1000);
+       User::After(i);
+       return 0;
+}
+
+int zrtp_thread_create(zrtp_thread_routine_t start_routine, void *arg) {   
+       RThread h;
+       TBuf<64> thName=_L("zrtp_thread");
+
+       h.Create(thName, start_routine, KDefaultStackSize*2, NULL, arg) ;   
+       h.Resume();
+       h.Close();
+   
+   return NULL;
+}
+//-----------------------------------------------------------------------------
+//                     For Scheduler
+#if (defined(ZRTP_USE_BUILTIN_SCEHDULER) && (ZRTP_USE_BUILTIN_SCEHDULER ==1))
+
+#include "DelayRuner.h"
+#include "zrtp_error.h"
+mlist_t                tasks_head_s;
+static uint8_t inited = 0 ;
+static uint8_t is_running = 0;
+
+typedef struct {    
+       zrtp_stream_t   *ctx;           /** ZRTP stream context associated with the task */
+       zrtp_retry_task_t       *ztask;         /** ZRTP stream associated with the task */
+       mlist_t                         _mlist;
+       CDelayRuner*                    ao;             // Active object
+} zrtp_sched_task_s_t;
+
+zrtp_status_t zrtp_def_scheduler_init(zrtp_global_t* zrtp)
+{      
+       zrtp_status_t status = zrtp_status_ok;
+       ZRTP_LOG(3,("symbian","Init start"));   
+       if (inited) {
+               return zrtp_status_ok;
+       }
+
+       do {
+               init_mlist(&tasks_head_s);
+               is_running = 1;
+               inited  = 1;
+       } while (0);
+
+       ZRTP_LOG(3,("symbian","Init end"));
+       return status;
+}
+
+void zrtp_def_scheduler_down()
+{      
+       ZRTP_LOG(3,("symbian","Down start"));
+       mlist_t *node = 0, *tmp = 0;
+       
+       if (!inited) {
+               return;
+       }
+
+       /* Stop main thread */          
+       is_running = 0; 
+//     zrtp_sem_post(count);
+       
+       /* Then destroy tasks queue and realease all other resources */
+       //zrtp_mutex_lock(protector);
+
+       mlist_for_each_safe(node, tmp, &tasks_head_s) {
+               zrtp_sched_task_s_t* task = mlist_get_struct(zrtp_sched_task_s_t, _mlist, node);
+               if (task->ao!=NULL)
+                       {
+                       delete task->ao;
+                       }
+               zrtp_sys_free(task);
+       }
+       init_mlist(&tasks_head_s);
+
+//     zrtp_mutex_unlock(protector);
+       
+//     zrtp_mutex_destroy(protector);
+//     zrtp_sem_destroy(count);
+
+       ZRTP_LOG(3,("symbian","Down end"));
+       inited  = 0;
+}
+
+
+void zrtp_def_scheduler_call_later(zrtp_stream_t *ctx, zrtp_retry_task_t* ztask)
+{      
+//     ZRTP_LOG(3,("symbian","CallLater start"));
+       //mlist_t *node=0, *tmp=0;                      
+       mlist_t* last = &tasks_head_s;
+
+       //zrtp_mutex_lock(protector);
+
+       if (!ztask->_is_enabled) {
+               //zrtp_mutex_unlock(protector);
+               return;
+       }
+
+       do {
+               zrtp_sched_task_s_t* new_task = (zrtp_sched_task_s_t*)zrtp_sys_alloc(sizeof(zrtp_sched_task_s_t));
+               if (!new_task) {
+                       break;
+               }
+
+               new_task->ctx                   = ctx;
+               new_task->ztask                 = ztask;                
+               new_task->ao                    = CDelayRuner::NewL();
+               
+               mlist_insert(last, &new_task->_mlist);          
+               
+               new_task->ao->StartL(ctx,ztask);
+               //zrtp_sem_post(count);
+       } while (0);
+
+       //ZRTP_LOG(3,("symbian","CallLater end"));
+       //zrtp_mutex_unlock(protector);         
+}
+
+void zrtp_def_scheduler_cancel_call_later(zrtp_stream_t* ctx, zrtp_retry_task_t* ztask)
+{
+       mlist_t *node=0, *tmp=0;
+       ZRTP_LOG(3,("symbian","CancelcallLater start"));
+//     zrtp_mutex_lock(protector);
+
+       mlist_for_each_safe(node, tmp, &tasks_head_s) {
+               zrtp_sched_task_s_t* task = mlist_get_struct(zrtp_sched_task_s_t, _mlist, node);
+               if ((task->ctx == ctx) && ((task->ztask == ztask) || !ztask)) {
+                       task->ao->Cancel();
+                       delete task->ao; // Cancel and delete task
+                       mlist_del(&task->_mlist);
+                       zrtp_sys_free(task);
+                       //zrtp_sem_trtwait(count);
+                       if (ztask) {
+                               break;
+                       }
+               }
+       }
+       ZRTP_LOG(3,("symbian","CancelCallLater done"));
+//     zrtp_mutex_unlock(protector);   
+}
+
+void zrtp_internal_delete_task_from_list(zrtp_stream_t* ctx, zrtp_retry_task_t* ztask)
+       {
+       mlist_t *node=0, *tmp=0;
+       ZRTP_LOG(3,("symbian","DelTask begin"));
+       mlist_for_each_safe(node, tmp, &tasks_head_s) 
+               {
+               zrtp_sched_task_s_t* task = mlist_get_struct(zrtp_sched_task_s_t, _mlist, node);
+               if ((task->ctx == ctx) && ((task->ztask == ztask) || !ztask)) 
+                       {
+                       delete task->ao; // Cancel and delete task
+                       mlist_del(&task->_mlist);
+                       zrtp_sys_free(task);
+                       ZRTP_LOG(3,("symbian","DelTask Del"));
+                       //zrtp_sem_trtwait(count);
+                       if (ztask) 
+                               {
+                               break;
+                               }
+                       }
+               }
+       ZRTP_LOG(3,("symbian","DelTask end"));
+       }
+
+void zrtp_def_scheduler_wait_call_later(zrtp_stream_t* ctx)
+{
+}
+#endif // ZRTP_USE_BUILTIN_SCEHDULER
+//-----------------------------------------------------------------------------
+
+unsigned int zrtp_get_pid()
+       {
+       return getpid();
+       }
+
+uint64_t zrtp_get_system_time_crazy()
+       {
+       TTime time;
+       
+       return time.MicroSecondsFrom(TTime(TDateTime (491,EAugust,7,3,37,17,347))).Int64();
+       }
+
+uint32_t zrtp_sum_of_pid_and_number_of_poccesses()
+       {
+       TFindProcess fp;
+       RProcess procces;
+       TFullName proccesName;
+       uint_32t idsum=1;
+       uint_32t proccesCount=0;
+       fp.Find(KNullDesC);
+       while (fp.Next(proccesName)==KErrNone)
+               {
+                if (procces.Open(proccesName,EOwnerProcess)==KErrNone)
+                        {
+                        idsum+=procces.Id();
+                        proccesCount++;
+                        procces.Close();
+                        }
+               }
+       idsum = (idsum << 3) xor proccesCount;
+       return idsum;
+       }
+
+uint32_t zrtp_get_availible_heap()
+       {
+       return User::Heap().MaxLength();
+       }
+
+uint32_t zrtp_symbian_kernel_random()
+       {
+       return Math::Random();
+       }
index 19ccbd0ac9ddcab4b4026081f7064e83c0f7384f..79c1157f8a17f0d453c10a2b6d746376d5bec056 100644 (file)
@@ -14,7 +14,7 @@
  * code omits one level of interface glue has no perceptible effect on
  * the results.
  */
-#include "zrtp.h"\r
+#include "zrtp.h"
 
 #ifndef HAVE_CONFIG_H
 #define HAVE_CONFIG_H 0
@@ -289,14 +289,14 @@ bntest_main(int argc, char **argv)
 
     /* Timing test code - only if requested on the command line */
     if (modbits) {
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
        timetype start, stop;
        unsigned long cursec, expsec, twoexpsec, dblexpsec;
        unsigned curms, expms, twoexpms, dblexpms;
 
        expsec = twoexpsec = dblexpsec = 0;
        expms = twoexpms = dblexpms = 0;
-#endif\r
+#endif
 
        lbnCopy_16(C,B,i);
        lbnSub1_16(C,i,1);        /* C is exponent: p-1 */
@@ -407,31 +407,31 @@ bntest_main(int argc, char **argv)
                bnput16("e = ", e, i);
                ZRTP_LOG(3, (_ZTU_, "%u bits, should be %d", m, (int)expbits2));
            }
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
                gettime(&start);
-#endif\r
+#endif
            z = lbnTwoExpMod_16(A, B, k, C, i);
            if (z < 0)
                goto nomem;
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
            gettime(&stop);
            subtime(stop, start);
            twoexpsec += cursec = sec(stop);
            twoexpms += curms = msec(stop);
 
            ZRTP_LOG(3, (_ZTU_, "2^<%d>:%4lu.%03u   ", (int)expbits, cursec, curms));
-#else\r
+#else
                ZRTP_LOG(3, (_ZTU_, "<%d>^<%d>    ", (int)modbits, (int)expbits));
-#endif\r
+#endif
            fflush(stdout);
 
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
            gettime(&start);
-#endif\r
+#endif
            z = lbnExpMod_16(A, A, i, B, k, C, i);
            if (z < 0)
                goto nomem;
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
            gettime(&stop);
            subtime(stop, start);
            expsec += cursec = sec(stop);
@@ -451,13 +451,13 @@ bntest_main(int argc, char **argv)
                   (int)modbits, (int)expbits,
                   (int)modbits, (int)expbits2,
                   cursec, curms));
-#else\r
-               ZRTP_LOG(3, (_ZTU_, "<%d>^<%d>*<%d>^<%d>",\r
-                       (int)modbits, (int)expbits,\r
-                       (int)modbits, (int)expbits2));\r
-#endif\r
+#else
+               ZRTP_LOG(3, (_ZTU_, "<%d>^<%d>*<%d>^<%d>",
+                       (int)modbits, (int)expbits,
+                       (int)modbits, (int)expbits2));
+#endif
        }
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
        twoexpms += (twoexpsec % j) * 1000;
        ZRTP_LOG(3, (_ZTU_, "2^<%d> mod <%d> bits AVERAGE: %4lu.%03u s",
               (int)expbits, (int)modbits, twoexpsec/j, twoexpms/j));
@@ -472,7 +472,7 @@ bntest_main(int argc, char **argv)
               (int)modbits, dblexpsec/j, dblexpms/j));
 
        putchar('\n');
-#endif\r
+#endif
     }
 
     puts("Beginning 1000 interations of sanity checking.\n"
@@ -486,9 +486,9 @@ bntest_main(int argc, char **argv)
      * on in case of major wierdness, but it produces a *lot* of
      * output.
      */
-#if (ZRTP_PLATFORM == ZP_WINCE) || (ZRTP_PLATFORM == ZP_SYMBIAN)\r
-       for (j = 1; j <= 20; j++) {\r
-#else\r
+#if (ZRTP_PLATFORM == ZP_WINCE) || (ZRTP_PLATFORM == ZP_SYMBIAN)
+       for (j = 1; j <= 20; j++) {
+#else
     for (j = 1; j <= 1000; j++) {
 #endif
 /* Do the tests for lots of different number sizes. */
index 6cc9ff27c5555c587b7b00183fdafd754876a8b8..2e8c33494ea4a4e45f4df3178978c5739d377f3c 100644 (file)
@@ -14,7 +14,7 @@
  * code omits one level of interface glue has no perceptible effect on
  * the results.
  */
-#include "zrtp.h"\r
+#include "zrtp.h"
 
 #ifndef HAVE_CONFIG_H
 #define HAVE_CONFIG_H 0
@@ -289,14 +289,14 @@ bntest_main(int argc, char **argv)
 
     /* Timing test code - only if requested on the command line */
     if (modbits) {
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
        timetype start, stop;
        unsigned long cursec, expsec, twoexpsec, dblexpsec;
        unsigned curms, expms, twoexpms, dblexpms;
 
        expsec = twoexpsec = dblexpsec = 0;
        expms = twoexpms = dblexpms = 0;
-#endif\r
+#endif
 
        lbnCopy_32(C,B,i);
        lbnSub1_32(C,i,1);        /* C is exponent: p-1 */
@@ -407,31 +407,31 @@ bntest_main(int argc, char **argv)
                bnput32("e = ", e, i);
                ZRTP_LOG(3, (_ZTU_, "%u bits, should be %d", m, (int)expbits2));
            }
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
                gettime(&start);
-#endif\r
+#endif
            z = lbnTwoExpMod_32(A, B, k, C, i);
            if (z < 0)
                goto nomem;
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
            gettime(&stop);
            subtime(stop, start);
            twoexpsec += cursec = sec(stop);
            twoexpms += curms = msec(stop);
 
            ZRTP_LOG(3, (_ZTU_, "2^<%d>:%4lu.%03u   ", (int)expbits, cursec, curms));
-#else\r
+#else
                ZRTP_LOG(3, (_ZTU_, "<%d>^<%d>    ", (int)modbits, (int)expbits));
-#endif\r
+#endif
            fflush(stdout);
 
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
            gettime(&start);
-#endif\r
+#endif
            z = lbnExpMod_32(A, A, i, B, k, C, i);
            if (z < 0)
                goto nomem;
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
            gettime(&stop);
            subtime(stop, start);
            expsec += cursec = sec(stop);
@@ -451,13 +451,13 @@ bntest_main(int argc, char **argv)
                   (int)modbits, (int)expbits,
                   (int)modbits, (int)expbits2,
                   cursec, curms));
-#else\r
-               ZRTP_LOG(3, (_ZTU_, "<%d>^<%d>*<%d>^<%d>",\r
-                       (int)modbits, (int)expbits,\r
-                       (int)modbits, (int)expbits2));\r
-#endif\r
+#else
+               ZRTP_LOG(3, (_ZTU_, "<%d>^<%d>*<%d>^<%d>",
+                       (int)modbits, (int)expbits,
+                       (int)modbits, (int)expbits2));
+#endif
        }
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
        twoexpms += (twoexpsec % j) * 1000;
        ZRTP_LOG(3, (_ZTU_, "2^<%d> mod <%d> bits AVERAGE: %4lu.%03u s",
               (int)expbits, (int)modbits, twoexpsec/j, twoexpms/j));
@@ -472,7 +472,7 @@ bntest_main(int argc, char **argv)
               (int)modbits, dblexpsec/j, dblexpms/j));
 
        putchar('\n');
-#endif\r
+#endif
     }
 
     puts("Beginning 1000 interations of sanity checking.\n"
@@ -486,9 +486,9 @@ bntest_main(int argc, char **argv)
      * on in case of major wierdness, but it produces a *lot* of
      * output.
      */
-#if (ZRTP_PLATFORM == ZP_WINCE) || (ZRTP_PLATFORM == ZP_SYMBIAN)\r
-       for (j = 1; j <= 20; j++) {\r
-#else\r
+#if (ZRTP_PLATFORM == ZP_WINCE) || (ZRTP_PLATFORM == ZP_SYMBIAN)
+       for (j = 1; j <= 20; j++) {
+#else
     for (j = 1; j <= 1000; j++) {
 #endif
 /* Do the tests for lots of different number sizes. */
index dbc4fd6c0d90a56554a68f204b9c4df1c8b3dd6e..8afdb967ef10b74d2a2fd6afd80b3cf925ba43fe 100644 (file)
@@ -14,7 +14,7 @@
  * code omits one level of interface glue has no perceptible effect on
  * the results.
  */
-#include "zrtp.h"\r
+#include "zrtp.h"
 
 #ifndef HAVE_CONFIG_H
 #define HAVE_CONFIG_H 0
@@ -289,14 +289,14 @@ bntest_main(int argc, char **argv)
 
     /* Timing test code - only if requested on the command line */
     if (modbits) {
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
        timetype start, stop;
        unsigned long cursec, expsec, twoexpsec, dblexpsec;
        unsigned curms, expms, twoexpms, dblexpms;
 
        expsec = twoexpsec = dblexpsec = 0;
        expms = twoexpms = dblexpms = 0;
-#endif\r
+#endif
 
        lbnCopy_64(C,B,i);
        lbnSub1_64(C,i,1);        /* C is exponent: p-1 */
@@ -407,31 +407,31 @@ bntest_main(int argc, char **argv)
                bnput64("e = ", e, i);
                ZRTP_LOG(3, (_ZTU_, "%u bits, should be %d", m, (int)expbits2));
            }
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
                gettime(&start);
-#endif\r
+#endif
            z = lbnTwoExpMod_64(A, B, k, C, i);
            if (z < 0)
                goto nomem;
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
            gettime(&stop);
            subtime(stop, start);
            twoexpsec += cursec = sec(stop);
            twoexpms += curms = msec(stop);
 
            ZRTP_LOG(3, (_ZTU_, "2^<%d>:%4lu.%03u   ", (int)expbits, cursec, curms));
-#else\r
+#else
                ZRTP_LOG(3, (_ZTU_, "<%d>^<%d>    ", (int)modbits, (int)expbits));
-#endif\r
+#endif
            fflush(stdout);
 
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
            gettime(&start);
-#endif\r
+#endif
            z = lbnExpMod_64(A, A, i, B, k, C, i);
            if (z < 0)
                goto nomem;
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
            gettime(&stop);
            subtime(stop, start);
            expsec += cursec = sec(stop);
@@ -451,13 +451,13 @@ bntest_main(int argc, char **argv)
                   (int)modbits, (int)expbits,
                   (int)modbits, (int)expbits2,
                   cursec, curms));
-#else\r
-               ZRTP_LOG(3, (_ZTU_, "<%d>^<%d>*<%d>^<%d>",\r
-                       (int)modbits, (int)expbits,\r
-                       (int)modbits, (int)expbits2));\r
-#endif\r
+#else
+               ZRTP_LOG(3, (_ZTU_, "<%d>^<%d>*<%d>^<%d>",
+                       (int)modbits, (int)expbits,
+                       (int)modbits, (int)expbits2));
+#endif
        }
-#if CLOCK_AVAIL\r
+#if CLOCK_AVAIL
        twoexpms += (twoexpsec % j) * 1000;
        ZRTP_LOG(3, (_ZTU_, "2^<%d> mod <%d> bits AVERAGE: %4lu.%03u s",
               (int)expbits, (int)modbits, twoexpsec/j, twoexpms/j));
@@ -472,7 +472,7 @@ bntest_main(int argc, char **argv)
               (int)modbits, dblexpsec/j, dblexpms/j));
 
        putchar('\n');
-#endif\r
+#endif
     }
 
     puts("Beginning 1000 interations of sanity checking.\n"
@@ -486,9 +486,9 @@ bntest_main(int argc, char **argv)
      * on in case of major wierdness, but it produces a *lot* of
      * output.
      */
-#if (ZRTP_PLATFORM == ZP_WINCE) || (ZRTP_PLATFORM == ZP_SYMBIAN)\r
-       for (j = 1; j <= 20; j++) {\r
-#else\r
+#if (ZRTP_PLATFORM == ZP_WINCE) || (ZRTP_PLATFORM == ZP_SYMBIAN)
+       for (j = 1; j <= 20; j++) {
+#else
     for (j = 1; j <= 1000; j++) {
 #endif
 /* Do the tests for lots of different number sizes. */
index 1e6778273b90170b18959046be58e171c97370cc..93020a6241699006f3dfdb3f363c0b65370e8eb8 100644 (file)
-/***********************************************************************\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
-#ifndef SKP_SILK_SDK_API_H\r
-#define SKP_SILK_SDK_API_H\r
-\r
-#include "SKP_Silk_control.h"\r
-#include "SKP_Silk_typedef.h"\r
-#include "SKP_Silk_errors.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-#define SILK_MAX_FRAMES_PER_PACKET  5\r
-\r
-/* Struct for TOC (Table of Contents) */\r
-typedef struct {\r
-    SKP_int     framesInPacket;                             /* Number of 20 ms frames in packet     */\r
-    SKP_int     fs_kHz;                                     /* Sampling frequency in packet         */\r
-    SKP_int     inbandLBRR;                                 /* Does packet contain LBRR information */\r
-    SKP_int     corrupt;                                    /* Packet is corrupt                    */\r
-    SKP_int     vadFlags[     SILK_MAX_FRAMES_PER_PACKET ]; /* VAD flag for each frame in packet    */\r
-    SKP_int     sigtypeFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* Signal type for each frame in packet */\r
-} SKP_Silk_TOC_struct;\r
-\r
-/****************************************/\r
-/* Encoder functions                    */\r
-/****************************************/\r
-\r
-/***********************************************/\r
-/* Get size in bytes of the Silk encoder state */\r
-/***********************************************/\r
-SKP_int SKP_Silk_SDK_Get_Encoder_Size( \r
-    SKP_int32                           *encSizeBytes   /* O:   Number of bytes in SILK encoder state           */\r
-);\r
-\r
-/*************************/\r
-/* Init or reset encoder */\r
-/*************************/\r
-SKP_int SKP_Silk_SDK_InitEncoder(\r
-    void                                *encState,      /* I/O: State                                           */\r
-    SKP_SILK_SDK_EncControlStruct       *encStatus      /* O:   Encoder Status                                  */\r
-);\r
-\r
-/***************************************/\r
-/* Read control structure from encoder */\r
-/***************************************/\r
-SKP_int SKP_Silk_SDK_QueryEncoder(\r
-    const void                          *encState,      /* I:   State                                           */\r
-    SKP_SILK_SDK_EncControlStruct       *encStatus      /* O:   Encoder Status                                  */\r
-);\r
-\r
-/**************************/\r
-/* Encode frame with Silk */\r
-/**************************/\r
-SKP_int SKP_Silk_SDK_Encode( \r
-    void                                *encState,      /* I/O: State                                           */\r
-    const SKP_SILK_SDK_EncControlStruct *encControl,    /* I:   Control status                                  */\r
-    const SKP_int16                     *samplesIn,     /* I:   Speech sample input vector                      */\r
-    SKP_int                             nSamplesIn,     /* I:   Number of samples in input vector               */\r
-    SKP_uint8                           *outData,       /* O:   Encoded output vector                           */\r
-    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in outData (input: Max bytes)   */\r
-);\r
-\r
-/****************************************/\r
-/* Decoder functions                    */\r
-/****************************************/\r
-\r
-/***********************************************/\r
-/* Get size in bytes of the Silk decoder state */\r
-/***********************************************/\r
-SKP_int SKP_Silk_SDK_Get_Decoder_Size( \r
-    SKP_int32                           *decSizeBytes   /* O:   Number of bytes in SILK decoder state           */\r
-);\r
-\r
-/*************************/\r
-/* Init or Reset decoder */\r
-/*************************/\r
-SKP_int SKP_Silk_SDK_InitDecoder( \r
-    void                                *decState       /* I/O: State                                           */\r
-);\r
-\r
-/******************/\r
-/* Decode a frame */\r
-/******************/\r
-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                              */\r
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
-    const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */\r
-    SKP_int16                           *samplesOut,    /* O:   Decoded output speech vector                    */\r
-    SKP_int16                           *nSamplesOut    /* I/O: Number of samples (vector/decoded)              */\r
-);\r
-\r
-/***************************************************************/\r
-/* Find Low Bit Rate Redundancy (LBRR) information in a packet */\r
-/***************************************************************/\r
-void SKP_Silk_SDK_search_for_LBRR(\r
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
-    const SKP_int                       nBytesIn,       /* I:   Number of input Bytes                           */\r
-    SKP_int                             lost_offset,    /* I:   Offset from lost packet                         */\r
-    SKP_uint8                           *LBRRData,      /* O:   LBRR payload                                    */\r
-    SKP_int16                           *nLBRRBytes     /* O:   Number of LBRR Bytes                            */\r
-);\r
-\r
-/**************************************/\r
-/* Get table of contents for a packet */\r
-/**************************************/\r
-void SKP_Silk_SDK_get_TOC(\r
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
-    const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */\r
-    SKP_Silk_TOC_struct                 *Silk_TOC       /* O:   Table of contents                               */\r
-);\r
-\r
-/**************************/\r
-/* Get the version number */\r
-/**************************/\r
-/* Return a pointer to string specifying the version */ \r
-const char *SKP_Silk_SDK_get_version();\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_SDK_API_H
+#define SKP_SILK_SDK_API_H
+
+#include "SKP_Silk_control.h"
+#include "SKP_Silk_typedef.h"
+#include "SKP_Silk_errors.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define SILK_MAX_FRAMES_PER_PACKET  5
+
+/* Struct for TOC (Table of Contents) */
+typedef struct {
+    SKP_int     framesInPacket;                             /* Number of 20 ms frames in packet     */
+    SKP_int     fs_kHz;                                     /* Sampling frequency in packet         */
+    SKP_int     inbandLBRR;                                 /* Does packet contain LBRR information */
+    SKP_int     corrupt;                                    /* Packet is corrupt                    */
+    SKP_int     vadFlags[     SILK_MAX_FRAMES_PER_PACKET ]; /* VAD flag for each frame in packet    */
+    SKP_int     sigtypeFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* Signal type for each frame in packet */
+} SKP_Silk_TOC_struct;
+
+/****************************************/
+/* Encoder functions                    */
+/****************************************/
+
+/***********************************************/
+/* Get size in bytes of the Silk encoder state */
+/***********************************************/
+SKP_int SKP_Silk_SDK_Get_Encoder_Size( 
+    SKP_int32                           *encSizeBytes   /* O:   Number of bytes in SILK encoder state           */
+);
+
+/*************************/
+/* Init or reset encoder */
+/*************************/
+SKP_int SKP_Silk_SDK_InitEncoder(
+    void                                *encState,      /* I/O: State                                           */
+    SKP_SILK_SDK_EncControlStruct       *encStatus      /* O:   Encoder Status                                  */
+);
+
+/***************************************/
+/* Read control structure from encoder */
+/***************************************/
+SKP_int SKP_Silk_SDK_QueryEncoder(
+    const void                          *encState,      /* I:   State                                           */
+    SKP_SILK_SDK_EncControlStruct       *encStatus      /* O:   Encoder Status                                  */
+);
+
+/**************************/
+/* Encode frame with Silk */
+/**************************/
+SKP_int SKP_Silk_SDK_Encode( 
+    void                                *encState,      /* I/O: State                                           */
+    const SKP_SILK_SDK_EncControlStruct *encControl,    /* I:   Control status                                  */
+    const SKP_int16                     *samplesIn,     /* I:   Speech sample input vector                      */
+    SKP_int                             nSamplesIn,     /* I:   Number of samples in input vector               */
+    SKP_uint8                           *outData,       /* O:   Encoded output vector                           */
+    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in outData (input: Max bytes)   */
+);
+
+/****************************************/
+/* Decoder functions                    */
+/****************************************/
+
+/***********************************************/
+/* Get size in bytes of the Silk decoder state */
+/***********************************************/
+SKP_int SKP_Silk_SDK_Get_Decoder_Size( 
+    SKP_int32                           *decSizeBytes   /* O:   Number of bytes in SILK decoder state           */
+);
+
+/*************************/
+/* Init or Reset decoder */
+/*************************/
+SKP_int SKP_Silk_SDK_InitDecoder( 
+    void                                *decState       /* I/O: State                                           */
+);
+
+/******************/
+/* Decode a frame */
+/******************/
+SKP_int SKP_Silk_SDK_Decode(
+    void*                               decState,       /* I/O: State                                           */
+    SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control Structure                               */
+    SKP_int                             lostFlag,       /* I:   0: no loss, 1 loss                              */
+    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
+    const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */
+    SKP_int16                           *samplesOut,    /* O:   Decoded output speech vector                    */
+    SKP_int16                           *nSamplesOut    /* I/O: Number of samples (vector/decoded)              */
+);
+
+/***************************************************************/
+/* Find Low Bit Rate Redundancy (LBRR) information in a packet */
+/***************************************************************/
+void SKP_Silk_SDK_search_for_LBRR(
+    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
+    const SKP_int                       nBytesIn,       /* I:   Number of input Bytes                           */
+    SKP_int                             lost_offset,    /* I:   Offset from lost packet                         */
+    SKP_uint8                           *LBRRData,      /* O:   LBRR payload                                    */
+    SKP_int16                           *nLBRRBytes     /* O:   Number of LBRR Bytes                            */
+);
+
+/**************************************/
+/* Get table of contents for a packet */
+/**************************************/
+void SKP_Silk_SDK_get_TOC(
+    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
+    const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */
+    SKP_Silk_TOC_struct                 *Silk_TOC       /* O:   Table of contents                               */
+);
+
+/**************************/
+/* Get the version number */
+/**************************/
+/* Return a pointer to string specifying the version */ 
+const char *SKP_Silk_SDK_get_version();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 4e52dce97d5958b5d897012cc394a7dff50a1d5e..d469991caa87c1d2526df976653baae1027d3f03 100644 (file)
@@ -1,91 +1,91 @@
-/***********************************************************************\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
-#ifndef SKP_SILK_CONTROL_H\r
-#define SKP_SILK_CONTROL_H\r
-\r
-#include "SKP_Silk_typedef.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-/***********************************************/\r
-/* Structure for controlling encoder operation */\r
-/***********************************************/\r
-typedef struct {\r
-    /* I:   Input signal sampling rate in Hertz; 8000/12000/16000/24000                     */\r
-    SKP_int32 API_sampleRate;\r
-\r
-    /* I:   Maximum internal sampling rate in Hertz; 8000/12000/16000/24000                 */\r
-    SKP_int32 maxInternalSampleRate;\r
-\r
-    /* I:   Number of samples per packet; must be equivalent of 20, 40, 60, 80 or 100 ms    */\r
-    SKP_int packetSize;\r
-\r
-    /* I:   Bitrate during active speech in bits/second; internally limited                 */\r
-    SKP_int32 bitRate;                        \r
-\r
-    /* I:   Uplink packet loss in percent (0-100)                                           */\r
-    SKP_int packetLossPercentage;\r
-    \r
-    /* I:   Complexity mode; 0 is lowest; 1 is medium and 2 is highest complexity           */\r
-    SKP_int complexity;\r
-\r
-    /* I:   Flag to enable in-band Forward Error Correction (FEC); 0/1                      */\r
-    SKP_int useInBandFEC;\r
-\r
-    /* I:   Flag to enable discontinuous transmission (DTX); 0/1                            */\r
-    SKP_int useDTX;\r
-} SKP_SILK_SDK_EncControlStruct;\r
-\r
-/**************************************************************************/\r
-/* Structure for controlling decoder operation and reading decoder status */\r
-/**************************************************************************/\r
-typedef struct {\r
-    /* I:   Output signal sampling rate in Hertz; 8000/12000/16000/24000                    */\r
-    SKP_int32 API_sampleRate;\r
-\r
-    /* O:   Number of samples per frame                                                     */\r
-    SKP_int frameSize;\r
-\r
-    /* O:   Frames per packet 1, 2, 3, 4, 5                                                 */\r
-    SKP_int framesPerPacket;\r
-\r
-    /* O:   Flag to indicate that the decoder has remaining payloads internally             */\r
-    SKP_int moreInternalDecoderFrames;\r
-\r
-    /* O:   Distance between main payload and redundant payload in packets                  */\r
-    SKP_int inBandFECOffset;\r
-} SKP_SILK_SDK_DecControlStruct;\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_CONTROL_H
+#define SKP_SILK_CONTROL_H
+
+#include "SKP_Silk_typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/***********************************************/
+/* Structure for controlling encoder operation */
+/***********************************************/
+typedef struct {
+    /* I:   Input signal sampling rate in Hertz; 8000/12000/16000/24000                     */
+    SKP_int32 API_sampleRate;
+
+    /* I:   Maximum internal sampling rate in Hertz; 8000/12000/16000/24000                 */
+    SKP_int32 maxInternalSampleRate;
+
+    /* I:   Number of samples per packet; must be equivalent of 20, 40, 60, 80 or 100 ms    */
+    SKP_int packetSize;
+
+    /* I:   Bitrate during active speech in bits/second; internally limited                 */
+    SKP_int32 bitRate;                        
+
+    /* I:   Uplink packet loss in percent (0-100)                                           */
+    SKP_int packetLossPercentage;
+    
+    /* I:   Complexity mode; 0 is lowest; 1 is medium and 2 is highest complexity           */
+    SKP_int complexity;
+
+    /* I:   Flag to enable in-band Forward Error Correction (FEC); 0/1                      */
+    SKP_int useInBandFEC;
+
+    /* I:   Flag to enable discontinuous transmission (DTX); 0/1                            */
+    SKP_int useDTX;
+} SKP_SILK_SDK_EncControlStruct;
+
+/**************************************************************************/
+/* Structure for controlling decoder operation and reading decoder status */
+/**************************************************************************/
+typedef struct {
+    /* I:   Output signal sampling rate in Hertz; 8000/12000/16000/24000                    */
+    SKP_int32 API_sampleRate;
+
+    /* O:   Number of samples per frame                                                     */
+    SKP_int frameSize;
+
+    /* O:   Frames per packet 1, 2, 3, 4, 5                                                 */
+    SKP_int framesPerPacket;
+
+    /* O:   Flag to indicate that the decoder has remaining payloads internally             */
+    SKP_int moreInternalDecoderFrames;
+
+    /* O:   Distance between main payload and redundant payload in packets                  */
+    SKP_int inBandFECOffset;
+} SKP_SILK_SDK_DecControlStruct;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index eb196cee48d5bfb07c4ef8de9eef101b515e1697..a7f62e453e50b32cc451440e923c4033e6d37f97 100644 (file)
@@ -1,89 +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
-#ifndef SKP_SILK_ERRORS_H\r
-#define SKP_SILK_ERRORS_H\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-/******************/\r
-/* Error messages */\r
-/******************/\r
-#define SKP_SILK_NO_ERROR                               0\r
-\r
-/**************************/\r
-/* Encoder error messages */\r
-/**************************/\r
-\r
-/* Input length is not a multiplum of 10 ms, or length is longer than the packet length */\r
-#define SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES        -1\r
-\r
-/* Sampling frequency not 8000, 12000, 16000 or 24000 Hertz */\r
-#define SKP_SILK_ENC_FS_NOT_SUPPORTED                   -2\r
-\r
-/* Packet size not 20, 40, 60, 80 or 100 ms */\r
-#define SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED          -3\r
-\r
-/* Allocated payload buffer too short */\r
-#define SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT              -4\r
-\r
-/* Loss rate not between 0 and 100 percent */\r
-#define SKP_SILK_ENC_INVALID_LOSS_RATE                  -5\r
-\r
-/* Complexity setting not valid, use 0, 1 or 2 */\r
-#define SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING         -6\r
-\r
-/* Inband FEC setting not valid, use 0 or 1 */\r
-#define SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING         -7\r
-\r
-/* DTX setting not valid, use 0 or 1 */\r
-#define SKP_SILK_ENC_INVALID_DTX_SETTING                -8\r
-\r
-/* Internal encoder error */\r
-#define SKP_SILK_ENC_INTERNAL_ERROR                     -9\r
-\r
-/**************************/\r
-/* Decoder error messages */\r
-/**************************/\r
-\r
-/* Output sampling frequency lower than internal decoded sampling frequency */\r
-#define SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY         -10\r
-\r
-/* Payload size exceeded the maximum allowed 1024 bytes */\r
-#define SKP_SILK_DEC_PAYLOAD_TOO_LARGE                  -11\r
-\r
-/* Payload has bit errors */\r
-#define SKP_SILK_DEC_PAYLOAD_ERROR                      -12\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_ERRORS_H
+#define SKP_SILK_ERRORS_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/******************/
+/* Error messages */
+/******************/
+#define SKP_SILK_NO_ERROR                               0
+
+/**************************/
+/* Encoder error messages */
+/**************************/
+
+/* Input length is not a multiplum of 10 ms, or length is longer than the packet length */
+#define SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES        -1
+
+/* Sampling frequency not 8000, 12000, 16000 or 24000 Hertz */
+#define SKP_SILK_ENC_FS_NOT_SUPPORTED                   -2
+
+/* Packet size not 20, 40, 60, 80 or 100 ms */
+#define SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED          -3
+
+/* Allocated payload buffer too short */
+#define SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT              -4
+
+/* Loss rate not between 0 and 100 percent */
+#define SKP_SILK_ENC_INVALID_LOSS_RATE                  -5
+
+/* Complexity setting not valid, use 0, 1 or 2 */
+#define SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING         -6
+
+/* Inband FEC setting not valid, use 0 or 1 */
+#define SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING         -7
+
+/* DTX setting not valid, use 0 or 1 */
+#define SKP_SILK_ENC_INVALID_DTX_SETTING                -8
+
+/* Internal encoder error */
+#define SKP_SILK_ENC_INTERNAL_ERROR                     -9
+
+/**************************/
+/* Decoder error messages */
+/**************************/
+
+/* Output sampling frequency lower than internal decoded sampling frequency */
+#define SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY         -10
+
+/* Payload size exceeded the maximum allowed 1024 bytes */
+#define SKP_SILK_DEC_PAYLOAD_TOO_LARGE                  -11
+
+/* Payload has bit errors */
+#define SKP_SILK_DEC_PAYLOAD_ERROR                      -12
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index f2c1f6f2c2136e77922a19562e5b92afa80faf37..bcc8021accbb851acb120c60c74c98dca26aea65 100644 (file)
@@ -1,99 +1,99 @@
-/***********************************************************************\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
-#ifndef _SKP_SILK_API_TYPDEF_H_\r
-#define _SKP_SILK_API_TYPDEF_H_\r
-\r
-#ifndef SKP_USE_DOUBLE_PRECISION_FLOATS\r
-#define SKP_USE_DOUBLE_PRECISION_FLOATS     0\r
-#endif\r
-\r
-#include <float.h>\r
-#if defined( __GNUC__ )\r
-#include <stdint.h>\r
-#endif\r
-\r
-#define SKP_int         int                     /* used for counters etc; at least 16 bits */\r
-#define SKP_int64       long long\r
-#define SKP_int32       int\r
-#define SKP_int16       short\r
-#define SKP_int8        signed char\r
-\r
-#define SKP_uint        unsigned int            /* used for counters etc; at least 16 bits */\r
-#define SKP_uint64      unsigned long long\r
-#define SKP_uint32      unsigned int\r
-#define SKP_uint16      unsigned short\r
-#define SKP_uint8       unsigned char\r
-\r
-#define SKP_int_ptr_size intptr_t\r
-\r
-#if SKP_USE_DOUBLE_PRECISION_FLOATS\r
-# define SKP_float      double\r
-# define SKP_float_MAX  DBL_MAX\r
-#else\r
-# define SKP_float      float\r
-# define SKP_float_MAX  FLT_MAX\r
-#endif\r
-\r
-#define SKP_INLINE      static __inline\r
-\r
-#ifdef _WIN32\r
-# define SKP_STR_CASEINSENSITIVE_COMPARE(x, y) _stricmp(x, y)\r
-#else\r
-# define SKP_STR_CASEINSENSITIVE_COMPARE(x, y) strcasecmp(x, y)\r
-#endif \r
-\r
-#define SKP_int64_MAX   ((SKP_int64)0x7FFFFFFFFFFFFFFFLL)   //  2^63 - 1  \r
-#define SKP_int64_MIN   ((SKP_int64)0x8000000000000000LL)   // -2^63     \r
-#define SKP_int32_MAX   0x7FFFFFFF                          //  2^31 - 1 =  2147483647\r
-#define SKP_int32_MIN   ((SKP_int32)0x80000000)             // -2^31     = -2147483648\r
-#define SKP_int16_MAX   0x7FFF                              //  2^15 - 1 =  32767\r
-#define SKP_int16_MIN   ((SKP_int16)0x8000)                 // -2^15     = -32768\r
-#define SKP_int8_MAX    0x7F                                //  2^7 - 1  =  127\r
-#define SKP_int8_MIN    ((SKP_int8)0x80)                    // -2^7      = -128\r
-\r
-#define SKP_uint32_MAX  0xFFFFFFFF  // 2^32 - 1 = 4294967295\r
-#define SKP_uint32_MIN  0x00000000\r
-#define SKP_uint16_MAX  0xFFFF      // 2^16 - 1 = 65535\r
-#define SKP_uint16_MIN  0x0000\r
-#define SKP_uint8_MAX   0xFF        //  2^8 - 1 = 255\r
-#define SKP_uint8_MIN   0x00\r
-\r
-#define SKP_TRUE        1\r
-#define SKP_FALSE       0\r
-\r
-/* assertions */\r
-#if (defined _WIN32 && !defined _WINCE && !defined(__GNUC__) && !defined(NO_ASSERTS))\r
-# ifndef SKP_assert\r
-#  include <crtdbg.h>      /* ASSERTE() */\r
-#  define SKP_assert(COND)   _ASSERTE(COND)\r
-# endif\r
-#else\r
-# define SKP_assert(COND)\r
-#endif\r
-\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef _SKP_SILK_API_TYPDEF_H_
+#define _SKP_SILK_API_TYPDEF_H_
+
+#ifndef SKP_USE_DOUBLE_PRECISION_FLOATS
+#define SKP_USE_DOUBLE_PRECISION_FLOATS     0
+#endif
+
+#include <float.h>
+#if defined( __GNUC__ )
+#include <stdint.h>
+#endif
+
+#define SKP_int         int                     /* used for counters etc; at least 16 bits */
+#define SKP_int64       long long
+#define SKP_int32       int
+#define SKP_int16       short
+#define SKP_int8        signed char
+
+#define SKP_uint        unsigned int            /* used for counters etc; at least 16 bits */
+#define SKP_uint64      unsigned long long
+#define SKP_uint32      unsigned int
+#define SKP_uint16      unsigned short
+#define SKP_uint8       unsigned char
+
+#define SKP_int_ptr_size intptr_t
+
+#if SKP_USE_DOUBLE_PRECISION_FLOATS
+# define SKP_float      double
+# define SKP_float_MAX  DBL_MAX
+#else
+# define SKP_float      float
+# define SKP_float_MAX  FLT_MAX
+#endif
+
+#define SKP_INLINE      static __inline
+
+#ifdef _WIN32
+# define SKP_STR_CASEINSENSITIVE_COMPARE(x, y) _stricmp(x, y)
+#else
+# define SKP_STR_CASEINSENSITIVE_COMPARE(x, y) strcasecmp(x, y)
+#endif 
+
+#define SKP_int64_MAX   ((SKP_int64)0x7FFFFFFFFFFFFFFFLL)   //  2^63 - 1  
+#define SKP_int64_MIN   ((SKP_int64)0x8000000000000000LL)   // -2^63     
+#define SKP_int32_MAX   0x7FFFFFFF                          //  2^31 - 1 =  2147483647
+#define SKP_int32_MIN   ((SKP_int32)0x80000000)             // -2^31     = -2147483648
+#define SKP_int16_MAX   0x7FFF                              //  2^15 - 1 =  32767
+#define SKP_int16_MIN   ((SKP_int16)0x8000)                 // -2^15     = -32768
+#define SKP_int8_MAX    0x7F                                //  2^7 - 1  =  127
+#define SKP_int8_MIN    ((SKP_int8)0x80)                    // -2^7      = -128
+
+#define SKP_uint32_MAX  0xFFFFFFFF  // 2^32 - 1 = 4294967295
+#define SKP_uint32_MIN  0x00000000
+#define SKP_uint16_MAX  0xFFFF      // 2^16 - 1 = 65535
+#define SKP_uint16_MIN  0x0000
+#define SKP_uint8_MAX   0xFF        //  2^8 - 1 = 255
+#define SKP_uint8_MIN   0x00
+
+#define SKP_TRUE        1
+#define SKP_FALSE       0
+
+/* assertions */
+#if (defined _WIN32 && !defined _WINCE && !defined(__GNUC__) && !defined(NO_ASSERTS))
+# ifndef SKP_assert
+#  include <crtdbg.h>      /* ASSERTE() */
+#  define SKP_assert(COND)   _ASSERTE(COND)
+# endif
+#else
+# define SKP_assert(COND)
+#endif
+
+#endif
index b1ad84170c7c4f118cfc050dbb086c34be47395f..5ebf155f62f3fa847668ef1385800d64e7774382 100644 (file)
@@ -1,96 +1,96 @@
-************************************************************************\r
-Fixed Point SILK SDK 1.0.8 beta source code package\r
-Copyright 2010 (c), Skype Limited\r
-https://developer.skype.com/silk/\r
-************************************************************************\r
-\r
-Date: 15/06/2011 (Format: DD/MM/YYYY)\r
-\r
-I. Description\r
-\r
-This package contains files for compilation and evaluation of the fixed\r
-point SILK SDK library. The following is included in this package:\r
-\r
-    o Source code for the fixed point SILK SDK library\r
-    o Source code for creating encoder and decoder executables\r
-    o Test vectors\r
-    o Comparison tool\r
-    o Microsoft Visual Studio solution and project files\r
-    o Makefile for GNU C-compiler (GCC)\r
-    \r
-II. Files and Folders\r
-\r
-    o doc/          - contains more information about the SILK SDK\r
-    o interface/    - contains API header files\r
-    o src/          - contains all SILK SDK library source files\r
-    o test/         - contains source files for testing the SILK SDK\r
-    o test_vectors/ - contains test vectors   \r
-    o Makefile      - Makefile for compiling with GCC\r
-    o readme.txt    - this file\r
-    o Silk_SDK.sln  - Visual Studio solution for all SILK SDK code\r
-\r
-III. How to use the Makefile\r
-\r
-    1. How to clean and compile the SILK SDK library:\r
-         \r
-       make clean lib\r
\r
-    2. How to compile an encoder executable:\r
-\r
-       make encoder\r
-\r
-    3. How to compile a decoder executable:\r
-\r
-       make decoder\r
-\r
-    4. How to compile the comparison tool:\r
-\r
-       make signalcompare\r
-\r
-    5. How to clean and compile all of the above:\r
-\r
-       make clean all\r
-\r
-    6. How to build for big endian CPU's\r
-\r
-       Make clean all ADDED_DEFINES+=_SYSTEM_IS_BIG_ENDIAN\r
-       To be able to use the test vectors with big endian CPU's the test programs\r
-       need to be compiled in a different way. Note that the 16 bit input and output \r
-       from the test programs will have the upper and lower bytes swapped with this setting. \r
-\r
-    7. How to use the comparison tool:\r
-\r
-       See 'How to use the test vectors.txt' in the test_vectors folder.       \r
-\r
-IV. History\r
-\r
-    Version 1.0.8 - Improved noise shaping, various other improvements, and various bugfixes. Added a MIPS version\r
-    Version 1.0.7 - Updated with bugfixes for LBRR and pitch estimator. SignalCompare updated\r
-    Version 1.0.6 - Updated with bugfixes for ARM builds\r
-    Version 1.0.5 - Updated with bugfixes for ARM builds\r
-    Version 1.0.4 - Updated with various bugfixes and improvements, including some API changes\r
-                    Added support for big endian platforms\r
-                    Added resampler support for additional API sample rates\r
-    Version 1.0.3 - Updated with various bugfixes and improvements\r
-    Version 1.0.2 - Updated with various bugfixes and improvements\r
-    Version 1.0.1 - First beta source code release\r
-    \r
-V. Compatibility\r
-\r
-    This package has been tested on the following platforms:\r
-\r
-    Windows XP Home and Professional\r
-    Windows Vista, 32-bit version\r
-    Mac OSX intel\r
-    Mac OSX ppc\r
-    Ubuntu Linux 9.10, 64-bit version \r
-\r
-VI. Known Issues\r
-\r
-    None\r
-\r
-VII. Additional Resources\r
-\r
-    For more information, visit the SILK SDK web site at:\r
-\r
-    <https://developer.skype.com/silk/>\r
+************************************************************************
+Fixed Point SILK SDK 1.0.8 beta source code package
+Copyright 2010 (c), Skype Limited
+https://developer.skype.com/silk/
+************************************************************************
+
+Date: 15/06/2011 (Format: DD/MM/YYYY)
+
+I. Description
+
+This package contains files for compilation and evaluation of the fixed
+point SILK SDK library. The following is included in this package:
+
+    o Source code for the fixed point SILK SDK library
+    o Source code for creating encoder and decoder executables
+    o Test vectors
+    o Comparison tool
+    o Microsoft Visual Studio solution and project files
+    o Makefile for GNU C-compiler (GCC)
+    
+II. Files and Folders
+
+    o doc/          - contains more information about the SILK SDK
+    o interface/    - contains API header files
+    o src/          - contains all SILK SDK library source files
+    o test/         - contains source files for testing the SILK SDK
+    o test_vectors/ - contains test vectors   
+    o Makefile      - Makefile for compiling with GCC
+    o readme.txt    - this file
+    o Silk_SDK.sln  - Visual Studio solution for all SILK SDK code
+
+III. How to use the Makefile
+
+    1. How to clean and compile the SILK SDK library:
+         
+       make clean lib
+    2. How to compile an encoder executable:
+
+       make encoder
+
+    3. How to compile a decoder executable:
+
+       make decoder
+
+    4. How to compile the comparison tool:
+
+       make signalcompare
+
+    5. How to clean and compile all of the above:
+
+       make clean all
+
+    6. How to build for big endian CPU's
+
+       Make clean all ADDED_DEFINES+=_SYSTEM_IS_BIG_ENDIAN
+       To be able to use the test vectors with big endian CPU's the test programs
+       need to be compiled in a different way. Note that the 16 bit input and output 
+       from the test programs will have the upper and lower bytes swapped with this setting. 
+
+    7. How to use the comparison tool:
+
+       See 'How to use the test vectors.txt' in the test_vectors folder.       
+
+IV. History
+
+    Version 1.0.8 - Improved noise shaping, various other improvements, and various bugfixes. Added a MIPS version
+    Version 1.0.7 - Updated with bugfixes for LBRR and pitch estimator. SignalCompare updated
+    Version 1.0.6 - Updated with bugfixes for ARM builds
+    Version 1.0.5 - Updated with bugfixes for ARM builds
+    Version 1.0.4 - Updated with various bugfixes and improvements, including some API changes
+                    Added support for big endian platforms
+                    Added resampler support for additional API sample rates
+    Version 1.0.3 - Updated with various bugfixes and improvements
+    Version 1.0.2 - Updated with various bugfixes and improvements
+    Version 1.0.1 - First beta source code release
+    
+V. Compatibility
+
+    This package has been tested on the following platforms:
+
+    Windows XP Home and Professional
+    Windows Vista, 32-bit version
+    Mac OSX intel
+    Mac OSX ppc
+    Ubuntu Linux 9.10, 64-bit version 
+
+VI. Known Issues
+
+    None
+
+VII. Additional Resources
+
+    For more information, visit the SILK SDK web site at:
+
+    <https://developer.skype.com/silk/>
index 98cc8c1ace8532b2bfada4fb44c137dd4b5143df..b6cba8995e9c4f769523084b4e77ac4afdf39e18 100644 (file)
-/***********************************************************************\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
-/* Conversion between prediction filter coefficients and NLSFs  */\r
-/* Requires the order to be an even number                      */\r
-/* A piecewise linear approximation maps LSF <-> cos(LSF)       */\r
-/* Therefore the result is not accurate NLSFs, but the two      */\r
-/* function are accurate inverses of each other                 */\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Number of binary divisions */\r
-#define BIN_DIV_STEPS_A2NLSF_FIX      3 /* must be no higher than 16 - log2( LSF_COS_TAB_SZ_FIX ) */\r
-#define QPoly                        16\r
-#define MAX_ITERATIONS_A2NLSF_FIX    30\r
-\r
-/* Flag for using 2x as many cosine sampling points, reduces the risk of missing a root */\r
-#define OVERSAMPLE_COSINE_TABLE       0\r
-\r
-/* Helper function for A2NLSF(..)                    */\r
-/* Transforms polynomials from cos(n*f) to cos(f)^n  */\r
-SKP_INLINE void SKP_Silk_A2NLSF_trans_poly(\r
-    SKP_int32        *p,    /* I/O    Polynomial                                */\r
-    const SKP_int    dd     /* I      Polynomial order (= filter order / 2 )    */\r
-)\r
-{\r
-    SKP_int k, n;\r
-    \r
-    for( k = 2; k <= dd; k++ ) {\r
-        for( n = dd; n > k; n-- ) {\r
-            p[ n - 2 ] -= p[ n ];\r
-        }\r
-        p[ k - 2 ] -= SKP_LSHIFT( p[ k ], 1 );\r
-    }\r
-}    \r
-/* Helper function for A2NLSF(..)                    */\r
-/* Polynomial evaluation                             */\r
-SKP_INLINE SKP_int32 SKP_Silk_A2NLSF_eval_poly(    /* return the polynomial evaluation, in QPoly */\r
-    SKP_int32        *p,    /* I    Polynomial, QPoly        */\r
-    const SKP_int32   x,    /* I    Evaluation point, Q12    */\r
-    const SKP_int    dd     /* I    Order                    */\r
-)\r
-{\r
-    SKP_int   n;\r
-    SKP_int32 x_Q16, y32;\r
-\r
-    y32 = p[ dd ];                                    /* QPoly */\r
-    x_Q16 = SKP_LSHIFT( x, 4 );\r
-    for( n = dd - 1; n >= 0; n-- ) {\r
-        y32 = SKP_SMLAWW( p[ n ], y32, x_Q16 );       /* QPoly */\r
-    }\r
-    return y32;\r
-}\r
-\r
-SKP_INLINE void SKP_Silk_A2NLSF_init(\r
-     const SKP_int32    *a_Q16,\r
-     SKP_int32          *P, \r
-     SKP_int32          *Q, \r
-     const SKP_int      dd\r
-) \r
-{\r
-    SKP_int k;\r
-\r
-    /* Convert filter coefs to even and odd polynomials */\r
-    P[dd] = SKP_LSHIFT( 1, QPoly );\r
-    Q[dd] = SKP_LSHIFT( 1, QPoly );\r
-    for( k = 0; k < dd; k++ ) {\r
-#if( QPoly < 16 )\r
-        P[ k ] = SKP_RSHIFT_ROUND( -a_Q16[ dd - k - 1 ] - a_Q16[ dd + k ], 16 - QPoly ); /* QPoly */\r
-        Q[ k ] = SKP_RSHIFT_ROUND( -a_Q16[ dd - k - 1 ] + a_Q16[ dd + k ], 16 - QPoly ); /* QPoly */\r
-#elif( Qpoly == 16 )\r
-        P[ k ] = -a_Q16[ dd - k - 1 ] - a_Q16[ dd + k ]; // QPoly\r
-        Q[ k ] = -a_Q16[ dd - k - 1 ] + a_Q16[ dd + k ]; // QPoly\r
-#else\r
-        P[ k ] = SKP_LSHIFT( -a_Q16[ dd - k - 1 ] - a_Q16[ dd + k ], QPoly - 16 ); /* QPoly */\r
-        Q[ k ] = SKP_LSHIFT( -a_Q16[ dd - k - 1 ] + a_Q16[ dd + k ], QPoly - 16 ); /* QPoly */\r
-#endif\r
-    }\r
-\r
-    /* Divide out zeros as we have that for even filter orders, */\r
-    /* z =  1 is always a root in Q, and                        */\r
-    /* z = -1 is always a root in P                             */\r
-    for( k = dd; k > 0; k-- ) {\r
-        P[ k - 1 ] -= P[ k ]; \r
-        Q[ k - 1 ] += Q[ k ]; \r
-    }\r
-\r
-    /* Transform polynomials from cos(n*f) to cos(f)^n */\r
-    SKP_Silk_A2NLSF_trans_poly( P, dd );\r
-    SKP_Silk_A2NLSF_trans_poly( Q, dd );\r
-}\r
-\r
-/* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients        */\r
-/* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence.    */\r
-void SKP_Silk_A2NLSF(\r
-    SKP_int          *NLSF,                 /* O    Normalized Line Spectral Frequencies, Q15 (0 - (2^15-1)), [d]    */\r
-    SKP_int32        *a_Q16,                /* I/O  Monic whitening filter coefficients in Q16 [d]                   */\r
-    const SKP_int    d                      /* I    Filter order (must be even)                                      */\r
-)\r
-{\r
-    SKP_int      i, k, m, dd, root_ix, ffrac;\r
-    SKP_int32 xlo, xhi, xmid;\r
-    SKP_int32 ylo, yhi, ymid;\r
-    SKP_int32 nom, den;\r
-    SKP_int32 P[ SKP_Silk_MAX_ORDER_LPC / 2 + 1 ];\r
-    SKP_int32 Q[ SKP_Silk_MAX_ORDER_LPC / 2 + 1 ];\r
-    SKP_int32 *PQ[ 2 ];\r
-    SKP_int32 *p;\r
-\r
-    /* Store pointers to array */\r
-    PQ[ 0 ] = P;\r
-    PQ[ 1 ] = Q;\r
-\r
-    dd = SKP_RSHIFT( d, 1 );\r
-\r
-    SKP_Silk_A2NLSF_init( a_Q16, P, Q, dd );\r
-\r
-    /* Find roots, alternating between P and Q */\r
-    p = P;    /* Pointer to polynomial */\r
-    \r
-    xlo = SKP_Silk_LSFCosTab_FIX_Q12[ 0 ]; // Q12\r
-    ylo = SKP_Silk_A2NLSF_eval_poly( p, xlo, dd );\r
-\r
-    if( ylo < 0 ) {\r
-        /* Set the first NLSF to zero and move on to the next */\r
-        NLSF[ 0 ] = 0;\r
-        p = Q;                      /* Pointer to polynomial */\r
-        ylo = SKP_Silk_A2NLSF_eval_poly( p, xlo, dd );\r
-        root_ix = 1;                /* Index of current root */\r
-    } else {\r
-        root_ix = 0;                /* Index of current root */\r
-    }\r
-    k = 1;                          /* Loop counter */\r
-    i = 0;                          /* Counter for bandwidth expansions applied */\r
-    while( 1 ) {\r
-        /* Evaluate polynomial */\r
-#if OVERSAMPLE_COSINE_TABLE\r
-        xhi = SKP_Silk_LSFCosTab_FIX_Q12[   k       >> 1 ] +\r
-          ( ( SKP_Silk_LSFCosTab_FIX_Q12[ ( k + 1 ) >> 1 ] - \r
-              SKP_Silk_LSFCosTab_FIX_Q12[   k       >> 1 ] ) >> 1 );    /* Q12 */\r
-#else\r
-        xhi = SKP_Silk_LSFCosTab_FIX_Q12[ k ]; /* Q12 */\r
-#endif\r
-        yhi = SKP_Silk_A2NLSF_eval_poly( p, xhi, dd );\r
-        \r
-        /* Detect zero crossing */\r
-        if( ( ylo <= 0 && yhi >= 0 ) || ( ylo >= 0 && yhi <= 0 ) ) {\r
-            /* Binary division */\r
-#if OVERSAMPLE_COSINE_TABLE\r
-            ffrac = -128;\r
-#else\r
-            ffrac = -256;\r
-#endif\r
-            for( m = 0; m < BIN_DIV_STEPS_A2NLSF_FIX; m++ ) {\r
-                /* Evaluate polynomial */\r
-                xmid = SKP_RSHIFT_ROUND( xlo + xhi, 1 );\r
-                ymid = SKP_Silk_A2NLSF_eval_poly( p, xmid, dd );\r
-\r
-                /* Detect zero crossing */\r
-                if( ( ylo <= 0 && ymid >= 0 ) || ( ylo >= 0 && ymid <= 0 ) ) {\r
-                    /* Reduce frequency */\r
-                    xhi = xmid;\r
-                    yhi = ymid;\r
-                } else {\r
-                    /* Increase frequency */\r
-                    xlo = xmid;\r
-                    ylo = ymid;\r
-#if OVERSAMPLE_COSINE_TABLE\r
-                    ffrac = SKP_ADD_RSHIFT( ffrac,  64, m );\r
-#else\r
-                    ffrac = SKP_ADD_RSHIFT( ffrac, 128, m );\r
-#endif\r
-                }\r
-            }\r
-            \r
-            /* Interpolate */\r
-            if( SKP_abs( ylo ) < 65536 ) {\r
-                /* Avoid dividing by zero */\r
-                den = ylo - yhi;\r
-                nom = SKP_LSHIFT( ylo, 8 - BIN_DIV_STEPS_A2NLSF_FIX ) + SKP_RSHIFT( den, 1 );\r
-                if( den != 0 ) {\r
-                    ffrac += SKP_DIV32( nom, den );\r
-                }\r
-            } else {\r
-                /* No risk of dividing by zero because abs(ylo - yhi) >= abs(ylo) >= 65536 */\r
-                ffrac += SKP_DIV32( ylo, SKP_RSHIFT( ylo - yhi, 8 - BIN_DIV_STEPS_A2NLSF_FIX ) );\r
-            }\r
-#if OVERSAMPLE_COSINE_TABLE\r
-            NLSF[ root_ix ] = (SKP_int)SKP_min_32( SKP_LSHIFT( (SKP_int32)k, 7 ) + ffrac, SKP_int16_MAX ); \r
-#else\r
-            NLSF[ root_ix ] = (SKP_int)SKP_min_32( SKP_LSHIFT( (SKP_int32)k, 8 ) + ffrac, SKP_int16_MAX ); \r
-#endif\r
-\r
-            SKP_assert( NLSF[ root_ix ] >=     0 );\r
-            SKP_assert( NLSF[ root_ix ] <= 32767 );\r
-\r
-            root_ix++;        /* Next root */\r
-            if( root_ix >= d ) {\r
-                /* Found all roots */\r
-                break;\r
-            }\r
-            /* Alternate pointer to polynomial */\r
-            p = PQ[ root_ix & 1 ];\r
-            \r
-            /* Evaluate polynomial */\r
-#if OVERSAMPLE_COSINE_TABLE\r
-            xlo = SKP_Silk_LSFCosTab_FIX_Q12[ ( k - 1 ) >> 1 ] +\r
-              ( ( SKP_Silk_LSFCosTab_FIX_Q12[   k       >> 1 ] - \r
-                  SKP_Silk_LSFCosTab_FIX_Q12[ ( k - 1 ) >> 1 ] ) >> 1 ); // Q12\r
-#else\r
-            xlo = SKP_Silk_LSFCosTab_FIX_Q12[ k - 1 ]; // Q12\r
-#endif\r
-            ylo = SKP_LSHIFT( 1 - ( root_ix & 2 ), 12 );\r
-        } else {\r
-            /* Increment loop counter */\r
-            k++;\r
-            xlo    = xhi;\r
-            ylo    = yhi;\r
-            \r
-#if OVERSAMPLE_COSINE_TABLE\r
-            if( k > 2 * LSF_COS_TAB_SZ_FIX ) {\r
-#else\r
-            if( k > LSF_COS_TAB_SZ_FIX ) {\r
-#endif\r
-                i++;\r
-                if( i > MAX_ITERATIONS_A2NLSF_FIX ) {\r
-                    /* Set NLSFs to white spectrum and exit */\r
-                    NLSF[ 0 ] = SKP_DIV32_16( 1 << 15, d + 1 );\r
-                    for( k = 1; k < d; k++ ) {\r
-                        NLSF[ k ] = SKP_SMULBB( k + 1, NLSF[ 0 ] );\r
-                    }\r
-                    return;\r
-                }\r
-\r
-                /* Error: Apply progressively more bandwidth expansion and run again */\r
-                SKP_Silk_bwexpander_32( a_Q16, d, 65536 - SKP_SMULBB( 10 + i, i ) ); // 10_Q16 = 0.00015\r
-\r
-                SKP_Silk_A2NLSF_init( a_Q16, P, Q, dd );\r
-                p = P;                            /* Pointer to polynomial */\r
-                xlo = SKP_Silk_LSFCosTab_FIX_Q12[ 0 ]; // Q12\r
-                ylo = SKP_Silk_A2NLSF_eval_poly( p, xlo, dd );\r
-                if( ylo < 0 ) {\r
-                    /* Set the first NLSF to zero and move on to the next */\r
-                    NLSF[ 0 ] = 0;\r
-                    p = Q;                        /* Pointer to polynomial */\r
-                    ylo = SKP_Silk_A2NLSF_eval_poly( p, xlo, dd );\r
-                    root_ix = 1;                  /* Index of current root */\r
-                } else {\r
-                    root_ix = 0;                  /* Index of current root */\r
-                }\r
-                k = 1;                            /* Reset loop counter */\r
-            }\r
-        }\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/* Conversion between prediction filter coefficients and NLSFs  */
+/* Requires the order to be an even number                      */
+/* A piecewise linear approximation maps LSF <-> cos(LSF)       */
+/* Therefore the result is not accurate NLSFs, but the two      */
+/* function are accurate inverses of each other                 */
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Number of binary divisions */
+#define BIN_DIV_STEPS_A2NLSF_FIX      3 /* must be no higher than 16 - log2( LSF_COS_TAB_SZ_FIX ) */
+#define QPoly                        16
+#define MAX_ITERATIONS_A2NLSF_FIX    30
+
+/* Flag for using 2x as many cosine sampling points, reduces the risk of missing a root */
+#define OVERSAMPLE_COSINE_TABLE       0
+
+/* Helper function for A2NLSF(..)                    */
+/* Transforms polynomials from cos(n*f) to cos(f)^n  */
+SKP_INLINE void SKP_Silk_A2NLSF_trans_poly(
+    SKP_int32        *p,    /* I/O    Polynomial                                */
+    const SKP_int    dd     /* I      Polynomial order (= filter order / 2 )    */
+)
+{
+    SKP_int k, n;
+    
+    for( k = 2; k <= dd; k++ ) {
+        for( n = dd; n > k; n-- ) {
+            p[ n - 2 ] -= p[ n ];
+        }
+        p[ k - 2 ] -= SKP_LSHIFT( p[ k ], 1 );
+    }
+}    
+/* Helper function for A2NLSF(..)                    */
+/* Polynomial evaluation                             */
+SKP_INLINE SKP_int32 SKP_Silk_A2NLSF_eval_poly(    /* return the polynomial evaluation, in QPoly */
+    SKP_int32        *p,    /* I    Polynomial, QPoly        */
+    const SKP_int32   x,    /* I    Evaluation point, Q12    */
+    const SKP_int    dd     /* I    Order                    */
+)
+{
+    SKP_int   n;
+    SKP_int32 x_Q16, y32;
+
+    y32 = p[ dd ];                                    /* QPoly */
+    x_Q16 = SKP_LSHIFT( x, 4 );
+    for( n = dd - 1; n >= 0; n-- ) {
+        y32 = SKP_SMLAWW( p[ n ], y32, x_Q16 );       /* QPoly */
+    }
+    return y32;
+}
+
+SKP_INLINE void SKP_Silk_A2NLSF_init(
+     const SKP_int32    *a_Q16,
+     SKP_int32          *P, 
+     SKP_int32          *Q, 
+     const SKP_int      dd
+) 
+{
+    SKP_int k;
+
+    /* Convert filter coefs to even and odd polynomials */
+    P[dd] = SKP_LSHIFT( 1, QPoly );
+    Q[dd] = SKP_LSHIFT( 1, QPoly );
+    for( k = 0; k < dd; k++ ) {
+#if( QPoly < 16 )
+        P[ k ] = SKP_RSHIFT_ROUND( -a_Q16[ dd - k - 1 ] - a_Q16[ dd + k ], 16 - QPoly ); /* QPoly */
+        Q[ k ] = SKP_RSHIFT_ROUND( -a_Q16[ dd - k - 1 ] + a_Q16[ dd + k ], 16 - QPoly ); /* QPoly */
+#elif( Qpoly == 16 )
+        P[ k ] = -a_Q16[ dd - k - 1 ] - a_Q16[ dd + k ]; // QPoly
+        Q[ k ] = -a_Q16[ dd - k - 1 ] + a_Q16[ dd + k ]; // QPoly
+#else
+        P[ k ] = SKP_LSHIFT( -a_Q16[ dd - k - 1 ] - a_Q16[ dd + k ], QPoly - 16 ); /* QPoly */
+        Q[ k ] = SKP_LSHIFT( -a_Q16[ dd - k - 1 ] + a_Q16[ dd + k ], QPoly - 16 ); /* QPoly */
+#endif
+    }
+
+    /* Divide out zeros as we have that for even filter orders, */
+    /* z =  1 is always a root in Q, and                        */
+    /* z = -1 is always a root in P                             */
+    for( k = dd; k > 0; k-- ) {
+        P[ k - 1 ] -= P[ k ]; 
+        Q[ k - 1 ] += Q[ k ]; 
+    }
+
+    /* Transform polynomials from cos(n*f) to cos(f)^n */
+    SKP_Silk_A2NLSF_trans_poly( P, dd );
+    SKP_Silk_A2NLSF_trans_poly( Q, dd );
+}
+
+/* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients        */
+/* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence.    */
+void SKP_Silk_A2NLSF(
+    SKP_int          *NLSF,                 /* O    Normalized Line Spectral Frequencies, Q15 (0 - (2^15-1)), [d]    */
+    SKP_int32        *a_Q16,                /* I/O  Monic whitening filter coefficients in Q16 [d]                   */
+    const SKP_int    d                      /* I    Filter order (must be even)                                      */
+)
+{
+    SKP_int      i, k, m, dd, root_ix, ffrac;
+    SKP_int32 xlo, xhi, xmid;
+    SKP_int32 ylo, yhi, ymid;
+    SKP_int32 nom, den;
+    SKP_int32 P[ SKP_Silk_MAX_ORDER_LPC / 2 + 1 ];
+    SKP_int32 Q[ SKP_Silk_MAX_ORDER_LPC / 2 + 1 ];
+    SKP_int32 *PQ[ 2 ];
+    SKP_int32 *p;
+
+    /* Store pointers to array */
+    PQ[ 0 ] = P;
+    PQ[ 1 ] = Q;
+
+    dd = SKP_RSHIFT( d, 1 );
+
+    SKP_Silk_A2NLSF_init( a_Q16, P, Q, dd );
+
+    /* Find roots, alternating between P and Q */
+    p = P;    /* Pointer to polynomial */
+    
+    xlo = SKP_Silk_LSFCosTab_FIX_Q12[ 0 ]; // Q12
+    ylo = SKP_Silk_A2NLSF_eval_poly( p, xlo, dd );
+
+    if( ylo < 0 ) {
+        /* Set the first NLSF to zero and move on to the next */
+        NLSF[ 0 ] = 0;
+        p = Q;                      /* Pointer to polynomial */
+        ylo = SKP_Silk_A2NLSF_eval_poly( p, xlo, dd );
+        root_ix = 1;                /* Index of current root */
+    } else {
+        root_ix = 0;                /* Index of current root */
+    }
+    k = 1;                          /* Loop counter */
+    i = 0;                          /* Counter for bandwidth expansions applied */
+    while( 1 ) {
+        /* Evaluate polynomial */
+#if OVERSAMPLE_COSINE_TABLE
+        xhi = SKP_Silk_LSFCosTab_FIX_Q12[   k       >> 1 ] +
+          ( ( SKP_Silk_LSFCosTab_FIX_Q12[ ( k + 1 ) >> 1 ] - 
+              SKP_Silk_LSFCosTab_FIX_Q12[   k       >> 1 ] ) >> 1 );    /* Q12 */
+#else
+        xhi = SKP_Silk_LSFCosTab_FIX_Q12[ k ]; /* Q12 */
+#endif
+        yhi = SKP_Silk_A2NLSF_eval_poly( p, xhi, dd );
+        
+        /* Detect zero crossing */
+        if( ( ylo <= 0 && yhi >= 0 ) || ( ylo >= 0 && yhi <= 0 ) ) {
+            /* Binary division */
+#if OVERSAMPLE_COSINE_TABLE
+            ffrac = -128;
+#else
+            ffrac = -256;
+#endif
+            for( m = 0; m < BIN_DIV_STEPS_A2NLSF_FIX; m++ ) {
+                /* Evaluate polynomial */
+                xmid = SKP_RSHIFT_ROUND( xlo + xhi, 1 );
+                ymid = SKP_Silk_A2NLSF_eval_poly( p, xmid, dd );
+
+                /* Detect zero crossing */
+                if( ( ylo <= 0 && ymid >= 0 ) || ( ylo >= 0 && ymid <= 0 ) ) {
+                    /* Reduce frequency */
+                    xhi = xmid;
+                    yhi = ymid;
+                } else {
+                    /* Increase frequency */
+                    xlo = xmid;
+                    ylo = ymid;
+#if OVERSAMPLE_COSINE_TABLE
+                    ffrac = SKP_ADD_RSHIFT( ffrac,  64, m );
+#else
+                    ffrac = SKP_ADD_RSHIFT( ffrac, 128, m );
+#endif
+                }
+            }
+            
+            /* Interpolate */
+            if( SKP_abs( ylo ) < 65536 ) {
+                /* Avoid dividing by zero */
+                den = ylo - yhi;
+                nom = SKP_LSHIFT( ylo, 8 - BIN_DIV_STEPS_A2NLSF_FIX ) + SKP_RSHIFT( den, 1 );
+                if( den != 0 ) {
+                    ffrac += SKP_DIV32( nom, den );
+                }
+            } else {
+                /* No risk of dividing by zero because abs(ylo - yhi) >= abs(ylo) >= 65536 */
+                ffrac += SKP_DIV32( ylo, SKP_RSHIFT( ylo - yhi, 8 - BIN_DIV_STEPS_A2NLSF_FIX ) );
+            }
+#if OVERSAMPLE_COSINE_TABLE
+            NLSF[ root_ix ] = (SKP_int)SKP_min_32( SKP_LSHIFT( (SKP_int32)k, 7 ) + ffrac, SKP_int16_MAX ); 
+#else
+            NLSF[ root_ix ] = (SKP_int)SKP_min_32( SKP_LSHIFT( (SKP_int32)k, 8 ) + ffrac, SKP_int16_MAX ); 
+#endif
+
+            SKP_assert( NLSF[ root_ix ] >=     0 );
+            SKP_assert( NLSF[ root_ix ] <= 32767 );
+
+            root_ix++;        /* Next root */
+            if( root_ix >= d ) {
+                /* Found all roots */
+                break;
+            }
+            /* Alternate pointer to polynomial */
+            p = PQ[ root_ix & 1 ];
+            
+            /* Evaluate polynomial */
+#if OVERSAMPLE_COSINE_TABLE
+            xlo = SKP_Silk_LSFCosTab_FIX_Q12[ ( k - 1 ) >> 1 ] +
+              ( ( SKP_Silk_LSFCosTab_FIX_Q12[   k       >> 1 ] - 
+                  SKP_Silk_LSFCosTab_FIX_Q12[ ( k - 1 ) >> 1 ] ) >> 1 ); // Q12
+#else
+            xlo = SKP_Silk_LSFCosTab_FIX_Q12[ k - 1 ]; // Q12
+#endif
+            ylo = SKP_LSHIFT( 1 - ( root_ix & 2 ), 12 );
+        } else {
+            /* Increment loop counter */
+            k++;
+            xlo    = xhi;
+            ylo    = yhi;
+            
+#if OVERSAMPLE_COSINE_TABLE
+            if( k > 2 * LSF_COS_TAB_SZ_FIX ) {
+#else
+            if( k > LSF_COS_TAB_SZ_FIX ) {
+#endif
+                i++;
+                if( i > MAX_ITERATIONS_A2NLSF_FIX ) {
+                    /* Set NLSFs to white spectrum and exit */
+                    NLSF[ 0 ] = SKP_DIV32_16( 1 << 15, d + 1 );
+                    for( k = 1; k < d; k++ ) {
+                        NLSF[ k ] = SKP_SMULBB( k + 1, NLSF[ 0 ] );
+                    }
+                    return;
+                }
+
+                /* Error: Apply progressively more bandwidth expansion and run again */
+                SKP_Silk_bwexpander_32( a_Q16, d, 65536 - SKP_SMULBB( 10 + i, i ) ); // 10_Q16 = 0.00015
+
+                SKP_Silk_A2NLSF_init( a_Q16, P, Q, dd );
+                p = P;                            /* Pointer to polynomial */
+                xlo = SKP_Silk_LSFCosTab_FIX_Q12[ 0 ]; // Q12
+                ylo = SKP_Silk_A2NLSF_eval_poly( p, xlo, dd );
+                if( ylo < 0 ) {
+                    /* Set the first NLSF to zero and move on to the next */
+                    NLSF[ 0 ] = 0;
+                    p = Q;                        /* Pointer to polynomial */
+                    ylo = SKP_Silk_A2NLSF_eval_poly( p, xlo, dd );
+                    root_ix = 1;                  /* Index of current root */
+                } else {
+                    root_ix = 0;                  /* Index of current root */
+                }
+                k = 1;                            /* Reset loop counter */
+            }
+        }
+    }
+}
index 00bde3b83eb009c8e047651d1d4a85cc33f02133..33c774ad88a7b0b4429b63cbeaac59e679ab3056 100644 (file)
-/***********************************************************************\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
-/* Generates excitation for CNG LPC synthesis */\r
-SKP_INLINE void SKP_Silk_CNG_exc(\r
-    SKP_int16                       residual[],         /* O    CNG residual signal Q0                      */\r
-    SKP_int32                       exc_buf_Q10[],      /* I    Random samples buffer Q10                   */\r
-    SKP_int32                       Gain_Q16,           /* I    Gain to apply                               */\r
-    SKP_int                         length,             /* I    Length                                      */\r
-    SKP_int32                       *rand_seed          /* I/O  Seed to random index generator              */\r
-)\r
-{\r
-    SKP_int32 seed;\r
-    SKP_int   i, idx, exc_mask;\r
-\r
-    exc_mask = CNG_BUF_MASK_MAX;\r
-    while( exc_mask > length ) {\r
-        exc_mask = SKP_RSHIFT( exc_mask, 1 );\r
-    }\r
-\r
-    seed = *rand_seed;\r
-    for( i = 0; i < length; i++ ) {\r
-        seed = SKP_RAND( seed );\r
-        idx = ( SKP_int )( SKP_RSHIFT( seed, 24 ) & exc_mask );\r
-        SKP_assert( idx >= 0 );\r
-        SKP_assert( idx <= CNG_BUF_MASK_MAX );\r
-        residual[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( exc_buf_Q10[ idx ], Gain_Q16 ), 10 ) );\r
-    }\r
-    *rand_seed = seed;\r
-}\r
-\r
-void SKP_Silk_CNG_Reset(\r
-    SKP_Silk_decoder_state      *psDec              /* I/O  Decoder state                               */\r
-)\r
-{\r
-    SKP_int i, NLSF_step_Q15, NLSF_acc_Q15;\r
-\r
-    NLSF_step_Q15 = SKP_DIV32_16( SKP_int16_MAX, psDec->LPC_order + 1 );\r
-    NLSF_acc_Q15 = 0;\r
-    for( i = 0; i < psDec->LPC_order; i++ ) {\r
-        NLSF_acc_Q15 += NLSF_step_Q15;\r
-        psDec->sCNG.CNG_smth_NLSF_Q15[ i ] = NLSF_acc_Q15;\r
-    }\r
-    psDec->sCNG.CNG_smth_Gain_Q16 = 0;\r
-    psDec->sCNG.rand_seed = 3176576;\r
-}\r
-\r
-/* Updates CNG estimate, and applies the CNG when packet was lost   */\r
-void SKP_Silk_CNG(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O  Decoder state                               */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */\r
-    SKP_int16                   signal[],           /* I/O  Signal                                      */\r
-    SKP_int                     length              /* I    Length of residual                          */\r
-)\r
-{\r
-    SKP_int   i, subfr;\r
-    SKP_int32 tmp_32, Gain_Q26, max_Gain_Q16;\r
-    SKP_int16 LPC_buf[ MAX_LPC_ORDER ];\r
-    SKP_int16 CNG_sig[ MAX_FRAME_LENGTH ];\r
-    SKP_Silk_CNG_struct *psCNG;\r
-    psCNG = &psDec->sCNG;\r
-\r
-    if( psDec->fs_kHz != psCNG->fs_kHz ) {\r
-        /* Reset state */\r
-        SKP_Silk_CNG_Reset( psDec );\r
-\r
-        psCNG->fs_kHz = psDec->fs_kHz;\r
-    }\r
-    if( psDec->lossCnt == 0 && psDec->vadFlag == NO_VOICE_ACTIVITY ) {\r
-        /* Update CNG parameters */\r
-\r
-        /* Smoothing of LSF's  */\r
-        for( i = 0; i < psDec->LPC_order; i++ ) {\r
-            psCNG->CNG_smth_NLSF_Q15[ i ] += SKP_SMULWB( psDec->prevNLSF_Q15[ i ] - psCNG->CNG_smth_NLSF_Q15[ i ], CNG_NLSF_SMTH_Q16 );\r
-        }\r
-        /* Find the subframe with the highest gain */\r
-        max_Gain_Q16 = 0;\r
-        subfr        = 0;\r
-        for( i = 0; i < NB_SUBFR; i++ ) {\r
-            if( psDecCtrl->Gains_Q16[ i ] > max_Gain_Q16 ) {\r
-                max_Gain_Q16 = psDecCtrl->Gains_Q16[ i ];\r
-                subfr        = i;\r
-            }\r
-        }\r
-        /* Update CNG excitation buffer with excitation from this subframe */\r
-        SKP_memmove( &psCNG->CNG_exc_buf_Q10[ psDec->subfr_length ], psCNG->CNG_exc_buf_Q10, ( NB_SUBFR - 1 ) * psDec->subfr_length * sizeof( SKP_int32 ) );\r
-        SKP_memcpy(   psCNG->CNG_exc_buf_Q10, &psDec->exc_Q10[ subfr * psDec->subfr_length ], psDec->subfr_length * sizeof( SKP_int32 ) );\r
-\r
-        /* Smooth gains */\r
-        for( i = 0; i < NB_SUBFR; i++ ) {\r
-            psCNG->CNG_smth_Gain_Q16 += SKP_SMULWB( psDecCtrl->Gains_Q16[ i ] - psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_Q16 );\r
-        }\r
-    }\r
-\r
-    /* Add CNG when packet is lost and / or when low speech activity */\r
-    if( psDec->lossCnt ) {//|| psDec->vadFlag == NO_VOICE_ACTIVITY ) {\r
-\r
-        /* Generate CNG excitation */\r
-        SKP_Silk_CNG_exc( CNG_sig, psCNG->CNG_exc_buf_Q10, \r
-                psCNG->CNG_smth_Gain_Q16, length, &psCNG->rand_seed );\r
-\r
-        /* Convert CNG NLSF to filter representation */\r
-        SKP_Silk_NLSF2A_stable( LPC_buf, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order );\r
-\r
-        Gain_Q26 = ( SKP_int32 )1 << 26; /* 1.0 */\r
-        \r
-        /* Generate CNG signal, by synthesis filtering */\r
-        if( psDec->LPC_order == 16 ) {\r
-            SKP_Silk_LPC_synthesis_order16( CNG_sig, LPC_buf, \r
-                Gain_Q26, psCNG->CNG_synth_state, CNG_sig, length );\r
-        } else {\r
-            SKP_Silk_LPC_synthesis_filter( CNG_sig, LPC_buf, \r
-                Gain_Q26, psCNG->CNG_synth_state, CNG_sig, length, psDec->LPC_order );\r
-        }\r
-        /* Mix with signal */\r
-        for( i = 0; i < length; i++ ) {\r
-            tmp_32 = signal[ i ] + CNG_sig[ i ];\r
-            signal[ i ] = SKP_SAT16( tmp_32 );\r
-        }\r
-    } else {\r
-        SKP_memset( psCNG->CNG_synth_state, 0, psDec->LPC_order *  sizeof( SKP_int32 ) );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Generates excitation for CNG LPC synthesis */
+SKP_INLINE void SKP_Silk_CNG_exc(
+    SKP_int16                       residual[],         /* O    CNG residual signal Q0                      */
+    SKP_int32                       exc_buf_Q10[],      /* I    Random samples buffer Q10                   */
+    SKP_int32                       Gain_Q16,           /* I    Gain to apply                               */
+    SKP_int                         length,             /* I    Length                                      */
+    SKP_int32                       *rand_seed          /* I/O  Seed to random index generator              */
+)
+{
+    SKP_int32 seed;
+    SKP_int   i, idx, exc_mask;
+
+    exc_mask = CNG_BUF_MASK_MAX;
+    while( exc_mask > length ) {
+        exc_mask = SKP_RSHIFT( exc_mask, 1 );
+    }
+
+    seed = *rand_seed;
+    for( i = 0; i < length; i++ ) {
+        seed = SKP_RAND( seed );
+        idx = ( SKP_int )( SKP_RSHIFT( seed, 24 ) & exc_mask );
+        SKP_assert( idx >= 0 );
+        SKP_assert( idx <= CNG_BUF_MASK_MAX );
+        residual[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( exc_buf_Q10[ idx ], Gain_Q16 ), 10 ) );
+    }
+    *rand_seed = seed;
+}
+
+void SKP_Silk_CNG_Reset(
+    SKP_Silk_decoder_state      *psDec              /* I/O  Decoder state                               */
+)
+{
+    SKP_int i, NLSF_step_Q15, NLSF_acc_Q15;
+
+    NLSF_step_Q15 = SKP_DIV32_16( SKP_int16_MAX, psDec->LPC_order + 1 );
+    NLSF_acc_Q15 = 0;
+    for( i = 0; i < psDec->LPC_order; i++ ) {
+        NLSF_acc_Q15 += NLSF_step_Q15;
+        psDec->sCNG.CNG_smth_NLSF_Q15[ i ] = NLSF_acc_Q15;
+    }
+    psDec->sCNG.CNG_smth_Gain_Q16 = 0;
+    psDec->sCNG.rand_seed = 3176576;
+}
+
+/* Updates CNG estimate, and applies the CNG when packet was lost   */
+void SKP_Silk_CNG(
+    SKP_Silk_decoder_state      *psDec,             /* I/O  Decoder state                               */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */
+    SKP_int16                   signal[],           /* I/O  Signal                                      */
+    SKP_int                     length              /* I    Length of residual                          */
+)
+{
+    SKP_int   i, subfr;
+    SKP_int32 tmp_32, Gain_Q26, max_Gain_Q16;
+    SKP_int16 LPC_buf[ MAX_LPC_ORDER ];
+    SKP_int16 CNG_sig[ MAX_FRAME_LENGTH ];
+    SKP_Silk_CNG_struct *psCNG;
+    psCNG = &psDec->sCNG;
+
+    if( psDec->fs_kHz != psCNG->fs_kHz ) {
+        /* Reset state */
+        SKP_Silk_CNG_Reset( psDec );
+
+        psCNG->fs_kHz = psDec->fs_kHz;
+    }
+    if( psDec->lossCnt == 0 && psDec->vadFlag == NO_VOICE_ACTIVITY ) {
+        /* Update CNG parameters */
+
+        /* Smoothing of LSF's  */
+        for( i = 0; i < psDec->LPC_order; i++ ) {
+            psCNG->CNG_smth_NLSF_Q15[ i ] += SKP_SMULWB( psDec->prevNLSF_Q15[ i ] - psCNG->CNG_smth_NLSF_Q15[ i ], CNG_NLSF_SMTH_Q16 );
+        }
+        /* Find the subframe with the highest gain */
+        max_Gain_Q16 = 0;
+        subfr        = 0;
+        for( i = 0; i < NB_SUBFR; i++ ) {
+            if( psDecCtrl->Gains_Q16[ i ] > max_Gain_Q16 ) {
+                max_Gain_Q16 = psDecCtrl->Gains_Q16[ i ];
+                subfr        = i;
+            }
+        }
+        /* Update CNG excitation buffer with excitation from this subframe */
+        SKP_memmove( &psCNG->CNG_exc_buf_Q10[ psDec->subfr_length ], psCNG->CNG_exc_buf_Q10, ( NB_SUBFR - 1 ) * psDec->subfr_length * sizeof( SKP_int32 ) );
+        SKP_memcpy(   psCNG->CNG_exc_buf_Q10, &psDec->exc_Q10[ subfr * psDec->subfr_length ], psDec->subfr_length * sizeof( SKP_int32 ) );
+
+        /* Smooth gains */
+        for( i = 0; i < NB_SUBFR; i++ ) {
+            psCNG->CNG_smth_Gain_Q16 += SKP_SMULWB( psDecCtrl->Gains_Q16[ i ] - psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_Q16 );
+        }
+    }
+
+    /* Add CNG when packet is lost and / or when low speech activity */
+    if( psDec->lossCnt ) {//|| psDec->vadFlag == NO_VOICE_ACTIVITY ) {
+
+        /* Generate CNG excitation */
+        SKP_Silk_CNG_exc( CNG_sig, psCNG->CNG_exc_buf_Q10, 
+                psCNG->CNG_smth_Gain_Q16, length, &psCNG->rand_seed );
+
+        /* Convert CNG NLSF to filter representation */
+        SKP_Silk_NLSF2A_stable( LPC_buf, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order );
+
+        Gain_Q26 = ( SKP_int32 )1 << 26; /* 1.0 */
+        
+        /* Generate CNG signal, by synthesis filtering */
+        if( psDec->LPC_order == 16 ) {
+            SKP_Silk_LPC_synthesis_order16( CNG_sig, LPC_buf, 
+                Gain_Q26, psCNG->CNG_synth_state, CNG_sig, length );
+        } else {
+            SKP_Silk_LPC_synthesis_filter( CNG_sig, LPC_buf, 
+                Gain_Q26, psCNG->CNG_synth_state, CNG_sig, length, psDec->LPC_order );
+        }
+        /* Mix with signal */
+        for( i = 0; i < length; i++ ) {
+            tmp_32 = signal[ i ] + CNG_sig[ i ];
+            signal[ i ] = SKP_SAT16( tmp_32 );
+        }
+    } else {
+        SKP_memset( psCNG->CNG_synth_state, 0, psDec->LPC_order *  sizeof( SKP_int32 ) );
+    }
+}
index bfef9c8ce242b08b1b27cca09da2eca0559b7836..22298b34964cd0596f18907994140e096c6a9a18 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-#include "SKP_Silk_tuning_parameters.h"\r
-\r
-#if HIGH_PASS_INPUT\r
-\r
-#define SKP_RADIANS_CONSTANT_Q19            1482    // 0.45f * 2.0f * 3.14159265359 / 1000\r
-#define SKP_LOG2_VARIABLE_HP_MIN_FREQ_Q7    809     // log(80) in Q7\r
-\r
-/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */\r
-void SKP_Silk_HP_variable_cutoff_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
-    SKP_int16                       *out,               /* O    high-pass filtered output signal            */\r
-    const SKP_int16                 *in                 /* I    input signal                                */\r
-)\r
-{\r
-    SKP_int   quality_Q15;\r
-    SKP_int32 B_Q28[ 3 ], A_Q28[ 2 ];\r
-    SKP_int32 Fc_Q19, r_Q28, r_Q22;\r
-    SKP_int32 pitch_freq_Hz_Q16, pitch_freq_log_Q7, delta_freq_Q7;\r
-\r
-    /*********************************************/\r
-    /* Estimate Low End of Pitch Frequency Range */\r
-    /*********************************************/\r
-    if( psEnc->sCmn.prev_sigtype == SIG_TYPE_VOICED ) {\r
-        /* difference, in log domain */\r
-        pitch_freq_Hz_Q16 = SKP_DIV32_16( SKP_LSHIFT( SKP_MUL( psEnc->sCmn.fs_kHz, 1000 ), 16 ), psEnc->sCmn.prevLag );\r
-        pitch_freq_log_Q7 = SKP_Silk_lin2log( pitch_freq_Hz_Q16 ) - ( 16 << 7 ); //0x70\r
-\r
-        /* adjustment based on quality */\r
-        quality_Q15 = psEncCtrl->input_quality_bands_Q15[ 0 ];\r
-        pitch_freq_log_Q7 = SKP_SUB32( pitch_freq_log_Q7, SKP_SMULWB( SKP_SMULWB( SKP_LSHIFT( quality_Q15, 2 ), quality_Q15 ), \r
-            pitch_freq_log_Q7 - SKP_LOG2_VARIABLE_HP_MIN_FREQ_Q7 ) );\r
-        pitch_freq_log_Q7 = SKP_ADD32( pitch_freq_log_Q7, SKP_RSHIFT( SKP_FIX_CONST( 0.6, 15 ) - quality_Q15, 9 ) );\r
-\r
-        //delta_freq = pitch_freq_log - psEnc->variable_HP_smth1;\r
-        delta_freq_Q7 = pitch_freq_log_Q7 - SKP_RSHIFT( psEnc->variable_HP_smth1_Q15, 8 );\r
-        if( delta_freq_Q7 < 0 ) {\r
-            /* less smoothing for decreasing pitch frequency, to track something close to the minimum */\r
-            delta_freq_Q7 = SKP_MUL( delta_freq_Q7, 3 );\r
-        }\r
-\r
-        /* limit delta, to reduce impact of outliers */\r
-        delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -SKP_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ), SKP_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ) );\r
-\r
-        /* update smoother */\r
-        psEnc->variable_HP_smth1_Q15 = SKP_SMLAWB( psEnc->variable_HP_smth1_Q15, \r
-            SKP_MUL( SKP_LSHIFT( psEnc->speech_activity_Q8, 1 ), delta_freq_Q7 ), SKP_FIX_CONST( VARIABLE_HP_SMTH_COEF1, 16 ) );\r
-    }\r
-    /* second smoother */\r
-    psEnc->variable_HP_smth2_Q15 = SKP_SMLAWB( psEnc->variable_HP_smth2_Q15, \r
-        psEnc->variable_HP_smth1_Q15 - psEnc->variable_HP_smth2_Q15, SKP_FIX_CONST( VARIABLE_HP_SMTH_COEF2, 16 ) );\r
-\r
-    /* convert from log scale to Hertz */\r
-    psEncCtrl->pitch_freq_low_Hz = SKP_Silk_log2lin( SKP_RSHIFT( psEnc->variable_HP_smth2_Q15, 8 ) );\r
-\r
-    /* limit frequency range */\r
-    psEncCtrl->pitch_freq_low_Hz = SKP_LIMIT_32( psEncCtrl->pitch_freq_low_Hz, \r
-        SKP_FIX_CONST( VARIABLE_HP_MIN_FREQ, 0 ), SKP_FIX_CONST( VARIABLE_HP_MAX_FREQ, 0 ) );\r
-\r
-    /********************************/\r
-    /* Compute Filter Coefficients  */\r
-    /********************************/\r
-    /* compute cut-off frequency, in radians */\r
-    //Fc_num   = (SKP_float)( 0.45f * 2.0f * 3.14159265359 * psEncCtrl->pitch_freq_low_Hz );\r
-    //Fc_denom = (SKP_float)( 1e3f * psEnc->sCmn.fs_kHz );\r
-    SKP_assert( psEncCtrl->pitch_freq_low_Hz <= SKP_int32_MAX / SKP_RADIANS_CONSTANT_Q19 );\r
-    Fc_Q19 = SKP_DIV32_16( SKP_SMULBB( SKP_RADIANS_CONSTANT_Q19, psEncCtrl->pitch_freq_low_Hz ), psEnc->sCmn.fs_kHz ); // range: 3704 - 27787, 11-15 bits\r
-    SKP_assert( Fc_Q19 >=  3704 );\r
-    SKP_assert( Fc_Q19 <= 27787 );\r
-\r
-    r_Q28 = SKP_FIX_CONST( 1.0, 28 ) - SKP_MUL( SKP_FIX_CONST( 0.92, 9 ), Fc_Q19 );\r
-    SKP_assert( r_Q28 >= 255347779 );\r
-    SKP_assert( r_Q28 <= 266690872 );\r
-\r
-    /* b = r * [ 1; -2; 1 ]; */\r
-    /* a = [ 1; -2 * r * ( 1 - 0.5 * Fc^2 ); r^2 ]; */\r
-    B_Q28[ 0 ] = r_Q28;\r
-    B_Q28[ 1 ] = SKP_LSHIFT( -r_Q28, 1 );\r
-    B_Q28[ 2 ] = r_Q28;\r
-    \r
-    // -r * ( 2 - Fc * Fc );\r
-    r_Q22  = SKP_RSHIFT( r_Q28, 6 );\r
-    A_Q28[ 0 ] = SKP_SMULWW( r_Q22, SKP_SMULWW( Fc_Q19, Fc_Q19 ) - SKP_FIX_CONST( 2.0,  22 ) );\r
-    A_Q28[ 1 ] = SKP_SMULWW( r_Q22, r_Q22 );\r
-\r
-    /********************************/\r
-    /* High-Pass Filter             */\r
-    /********************************/\r
-    SKP_Silk_biquad_alt( in, B_Q28, A_Q28, psEnc->sCmn.In_HP_State, out, psEnc->sCmn.frame_length );\r
-}\r
-\r
-#endif // HIGH_PASS_INPUT\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_tuning_parameters.h"
+
+#if HIGH_PASS_INPUT
+
+#define SKP_RADIANS_CONSTANT_Q19            1482    // 0.45f * 2.0f * 3.14159265359 / 1000
+#define SKP_LOG2_VARIABLE_HP_MIN_FREQ_Q7    809     // log(80) in Q7
+
+/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */
+void SKP_Silk_HP_variable_cutoff_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Encoder state FIX                           */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,         /* I/O  Encoder control FIX                         */
+    SKP_int16                       *out,               /* O    high-pass filtered output signal            */
+    const SKP_int16                 *in                 /* I    input signal                                */
+)
+{
+    SKP_int   quality_Q15;
+    SKP_int32 B_Q28[ 3 ], A_Q28[ 2 ];
+    SKP_int32 Fc_Q19, r_Q28, r_Q22;
+    SKP_int32 pitch_freq_Hz_Q16, pitch_freq_log_Q7, delta_freq_Q7;
+
+    /*********************************************/
+    /* Estimate Low End of Pitch Frequency Range */
+    /*********************************************/
+    if( psEnc->sCmn.prev_sigtype == SIG_TYPE_VOICED ) {
+        /* difference, in log domain */
+        pitch_freq_Hz_Q16 = SKP_DIV32_16( SKP_LSHIFT( SKP_MUL( psEnc->sCmn.fs_kHz, 1000 ), 16 ), psEnc->sCmn.prevLag );
+        pitch_freq_log_Q7 = SKP_Silk_lin2log( pitch_freq_Hz_Q16 ) - ( 16 << 7 ); //0x70
+
+        /* adjustment based on quality */
+        quality_Q15 = psEncCtrl->input_quality_bands_Q15[ 0 ];
+        pitch_freq_log_Q7 = SKP_SUB32( pitch_freq_log_Q7, SKP_SMULWB( SKP_SMULWB( SKP_LSHIFT( quality_Q15, 2 ), quality_Q15 ), 
+            pitch_freq_log_Q7 - SKP_LOG2_VARIABLE_HP_MIN_FREQ_Q7 ) );
+        pitch_freq_log_Q7 = SKP_ADD32( pitch_freq_log_Q7, SKP_RSHIFT( SKP_FIX_CONST( 0.6, 15 ) - quality_Q15, 9 ) );
+
+        //delta_freq = pitch_freq_log - psEnc->variable_HP_smth1;
+        delta_freq_Q7 = pitch_freq_log_Q7 - SKP_RSHIFT( psEnc->variable_HP_smth1_Q15, 8 );
+        if( delta_freq_Q7 < 0 ) {
+            /* less smoothing for decreasing pitch frequency, to track something close to the minimum */
+            delta_freq_Q7 = SKP_MUL( delta_freq_Q7, 3 );
+        }
+
+        /* limit delta, to reduce impact of outliers */
+        delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -SKP_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ), SKP_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ) );
+
+        /* update smoother */
+        psEnc->variable_HP_smth1_Q15 = SKP_SMLAWB( psEnc->variable_HP_smth1_Q15, 
+            SKP_MUL( SKP_LSHIFT( psEnc->speech_activity_Q8, 1 ), delta_freq_Q7 ), SKP_FIX_CONST( VARIABLE_HP_SMTH_COEF1, 16 ) );
+    }
+    /* second smoother */
+    psEnc->variable_HP_smth2_Q15 = SKP_SMLAWB( psEnc->variable_HP_smth2_Q15, 
+        psEnc->variable_HP_smth1_Q15 - psEnc->variable_HP_smth2_Q15, SKP_FIX_CONST( VARIABLE_HP_SMTH_COEF2, 16 ) );
+
+    /* convert from log scale to Hertz */
+    psEncCtrl->pitch_freq_low_Hz = SKP_Silk_log2lin( SKP_RSHIFT( psEnc->variable_HP_smth2_Q15, 8 ) );
+
+    /* limit frequency range */
+    psEncCtrl->pitch_freq_low_Hz = SKP_LIMIT_32( psEncCtrl->pitch_freq_low_Hz, 
+        SKP_FIX_CONST( VARIABLE_HP_MIN_FREQ, 0 ), SKP_FIX_CONST( VARIABLE_HP_MAX_FREQ, 0 ) );
+
+    /********************************/
+    /* Compute Filter Coefficients  */
+    /********************************/
+    /* compute cut-off frequency, in radians */
+    //Fc_num   = (SKP_float)( 0.45f * 2.0f * 3.14159265359 * psEncCtrl->pitch_freq_low_Hz );
+    //Fc_denom = (SKP_float)( 1e3f * psEnc->sCmn.fs_kHz );
+    SKP_assert( psEncCtrl->pitch_freq_low_Hz <= SKP_int32_MAX / SKP_RADIANS_CONSTANT_Q19 );
+    Fc_Q19 = SKP_DIV32_16( SKP_SMULBB( SKP_RADIANS_CONSTANT_Q19, psEncCtrl->pitch_freq_low_Hz ), psEnc->sCmn.fs_kHz ); // range: 3704 - 27787, 11-15 bits
+    SKP_assert( Fc_Q19 >=  3704 );
+    SKP_assert( Fc_Q19 <= 27787 );
+
+    r_Q28 = SKP_FIX_CONST( 1.0, 28 ) - SKP_MUL( SKP_FIX_CONST( 0.92, 9 ), Fc_Q19 );
+    SKP_assert( r_Q28 >= 255347779 );
+    SKP_assert( r_Q28 <= 266690872 );
+
+    /* b = r * [ 1; -2; 1 ]; */
+    /* a = [ 1; -2 * r * ( 1 - 0.5 * Fc^2 ); r^2 ]; */
+    B_Q28[ 0 ] = r_Q28;
+    B_Q28[ 1 ] = SKP_LSHIFT( -r_Q28, 1 );
+    B_Q28[ 2 ] = r_Q28;
+    
+    // -r * ( 2 - Fc * Fc );
+    r_Q22  = SKP_RSHIFT( r_Q28, 6 );
+    A_Q28[ 0 ] = SKP_SMULWW( r_Q22, SKP_SMULWW( Fc_Q19, Fc_Q19 ) - SKP_FIX_CONST( 2.0,  22 ) );
+    A_Q28[ 1 ] = SKP_SMULWW( r_Q22, r_Q22 );
+
+    /********************************/
+    /* High-Pass Filter             */
+    /********************************/
+    SKP_Silk_biquad_alt( in, B_Q28, A_Q28, psEnc->sCmn.In_HP_State, out, psEnc->sCmn.frame_length );
+}
+
+#endif // HIGH_PASS_INPUT
index fd6dec04de008329c428dd56a01b7bc318cb6a7b..2f4700fab7bc731fcb219980c8087f38f9a62a8c 100644 (file)
-/***********************************************************************\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
-/*! \file SKP_Silk_Inlines.h\r
- *  \brief SigProcFix_Inlines.h defines inline signal processing functions.\r
- */\r
-\r
-#ifndef _SKP_SILK_FIX_INLINES_H_\r
-#define _SKP_SILK_FIX_INLINES_H_\r
-\r
-#ifdef  __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-/* count leading zeros of SKP_int64 */\r
-SKP_INLINE SKP_int32 SKP_Silk_CLZ64(SKP_int64 in)\r
-{\r
-    SKP_int32 in_upper;\r
-\r
-    in_upper = (SKP_int32)SKP_RSHIFT64(in, 32);\r
-    if (in_upper == 0) {\r
-        /* Search in the lower 32 bits */\r
-        return 32 + SKP_Silk_CLZ32( (SKP_int32) in );\r
-    } else {\r
-        /* Search in the upper 32 bits */\r
-        return SKP_Silk_CLZ32( in_upper );\r
-    }\r
-}\r
-\r
-/* get number of leading zeros and fractional part (the bits right after the leading one */\r
-SKP_INLINE void SKP_Silk_CLZ_FRAC(SKP_int32 in,            /* I: input */\r
-                                    SKP_int32 *lz,           /* O: number of leading zeros */\r
-                                    SKP_int32 *frac_Q7)      /* O: the 7 bits right after the leading one */\r
-{\r
-    SKP_int32 lzeros = SKP_Silk_CLZ32(in);\r
-\r
-    * lz = lzeros;\r
-    * frac_Q7 = SKP_ROR32(in, 24 - lzeros) & 0x7f;\r
-}\r
-\r
-/* Approximation of square root                                          */\r
-/* Accuracy: < +/- 10%  for output values > 15                           */\r
-/*           < +/- 2.5% for output values > 120                          */\r
-SKP_INLINE SKP_int32 SKP_Silk_SQRT_APPROX(SKP_int32 x)\r
-{\r
-    SKP_int32 y, lz, frac_Q7;\r
-\r
-    if( x <= 0 ) {\r
-        return 0;\r
-    }\r
-\r
-    SKP_Silk_CLZ_FRAC(x, &lz, &frac_Q7);\r
-\r
-    if( lz & 1 ) {\r
-        y = 32768;\r
-    } else {\r
-        y = 46214;        /* 46214 = sqrt(2) * 32768 */\r
-    }\r
-\r
-    /* get scaling right */\r
-    y >>= SKP_RSHIFT(lz, 1);\r
-\r
-    /* increment using fractional part of input */\r
-    y = SKP_SMLAWB(y, y, SKP_SMULBB(213, frac_Q7));\r
-\r
-    return y;\r
-}\r
-\r
-/* returns the number of left shifts before overflow for a 16 bit number (ITU definition with norm(0)=0) */\r
-SKP_INLINE SKP_int32 SKP_Silk_norm16(SKP_int16 a) {\r
-\r
-  SKP_int32 a32;\r
-\r
-  /* if ((a == 0) || (a == SKP_int16_MIN)) return(0); */\r
-  if ((a << 1) == 0) return(0);\r
-\r
-  a32 = a;\r
-  /* if (a32 < 0) a32 = -a32 - 1; */\r
-  a32 ^= SKP_RSHIFT(a32, 31);\r
-\r
-  return SKP_Silk_CLZ32(a32) - 17;\r
-}\r
-\r
-/* returns the number of left shifts before overflow for a 32 bit number (ITU definition with norm(0)=0) */\r
-SKP_INLINE SKP_int32 SKP_Silk_norm32(SKP_int32 a) {\r
-  \r
-  /* if ((a == 0) || (a == SKP_int32_MIN)) return(0); */\r
-  if ((a << 1) == 0) return(0);\r
-\r
-  /* if (a < 0) a = -a - 1; */\r
-  a ^= SKP_RSHIFT(a, 31);\r
-\r
-  return SKP_Silk_CLZ32(a) - 1;\r
-}\r
-\r
-/* Divide two int32 values and return result as int32 in a given Q-domain */\r
-SKP_INLINE SKP_int32 SKP_DIV32_varQ(    /* O    returns a good approximation of "(a32 << Qres) / b32" */\r
-    const SKP_int32     a32,            /* I    numerator (Q0)                  */\r
-    const SKP_int32     b32,            /* I    denominator (Q0)                */\r
-    const SKP_int       Qres            /* I    Q-domain of result (>= 0)       */\r
-)\r
-{\r
-    SKP_int   a_headrm, b_headrm, lshift;\r
-    SKP_int32 b32_inv, a32_nrm, b32_nrm, result;\r
-\r
-    SKP_assert( b32 != 0 );\r
-    SKP_assert( Qres >= 0 );\r
-\r
-    /* Compute number of bits head room and normalize inputs */\r
-    a_headrm = SKP_Silk_CLZ32( SKP_abs(a32) ) - 1;\r
-    a32_nrm = SKP_LSHIFT(a32, a_headrm);                                    /* Q: a_headrm                    */\r
-    b_headrm = SKP_Silk_CLZ32( SKP_abs(b32) ) - 1;\r
-    b32_nrm = SKP_LSHIFT(b32, b_headrm);                                    /* Q: b_headrm                    */\r
-\r
-    /* Inverse of b32, with 14 bits of precision */\r
-    b32_inv = SKP_DIV32_16( SKP_int32_MAX >> 2, SKP_RSHIFT(b32_nrm, 16) );  /* Q: 29 + 16 - b_headrm        */\r
-\r
-    /* First approximation */\r
-    result = SKP_SMULWB(a32_nrm, b32_inv);                                  /* Q: 29 + a_headrm - b_headrm    */\r
-\r
-    /* Compute residual by subtracting product of denominator and first approximation */\r
-    a32_nrm -= SKP_LSHIFT_ovflw( SKP_SMMUL(b32_nrm, result), 3 );           /* Q: a_headrm                    */\r
-\r
-    /* Refinement */\r
-    result = SKP_SMLAWB(result, a32_nrm, b32_inv);                          /* Q: 29 + a_headrm - b_headrm    */\r
-\r
-    /* Convert to Qres domain */\r
-    lshift = 29 + a_headrm - b_headrm - Qres;\r
-    if( lshift <= 0 ) {\r
-        return SKP_LSHIFT_SAT32(result, -lshift);\r
-    } else {\r
-        if( lshift < 32){\r
-            return SKP_RSHIFT(result, lshift);\r
-        } else {\r
-            /* Avoid undefined result */\r
-            return 0;\r
-        }\r
-    }\r
-}\r
-\r
-/* Invert int32 value and return result as int32 in a given Q-domain */\r
-SKP_INLINE SKP_int32 SKP_INVERSE32_varQ(    /* O    returns a good approximation of "(1 << Qres) / b32" */\r
-    const SKP_int32     b32,                /* I    denominator (Q0)                */\r
-    const SKP_int       Qres                /* I    Q-domain of result (> 0)        */\r
-)\r
-{\r
-    SKP_int   b_headrm, lshift;\r
-    SKP_int32 b32_inv, b32_nrm, err_Q32, result;\r
-\r
-    SKP_assert( b32 != 0 );\r
-    SKP_assert( b32 != SKP_int32_MIN ); /* SKP_int32_MIN is not handled by SKP_abs */\r
-    SKP_assert( Qres > 0 );\r
-\r
-    /* Compute number of bits head room and normalize input */\r
-    b_headrm = SKP_Silk_CLZ32( SKP_abs(b32) ) - 1;\r
-    b32_nrm = SKP_LSHIFT(b32, b_headrm);                                    /* Q: b_headrm                */\r
-\r
-    /* Inverse of b32, with 14 bits of precision */\r
-    b32_inv = SKP_DIV32_16( SKP_int32_MAX >> 2, SKP_RSHIFT(b32_nrm, 16) );  /* Q: 29 + 16 - b_headrm    */\r
-\r
-    /* First approximation */\r
-    result = SKP_LSHIFT(b32_inv, 16);                                       /* Q: 61 - b_headrm            */\r
-\r
-    /* Compute residual by subtracting product of denominator and first approximation from one */\r
-    err_Q32 = SKP_LSHIFT_ovflw( -SKP_SMULWB(b32_nrm, b32_inv), 3 );         /* Q32                        */\r
-\r
-    /* Refinement */\r
-    result = SKP_SMLAWW(result, err_Q32, b32_inv);                          /* Q: 61 - b_headrm            */\r
-\r
-    /* Convert to Qres domain */\r
-    lshift = 61 - b_headrm - Qres;\r
-    if( lshift <= 0 ) {\r
-        return SKP_LSHIFT_SAT32(result, -lshift);\r
-    } else {\r
-        if( lshift < 32){\r
-            return SKP_RSHIFT(result, lshift);\r
-        }else{\r
-            /* Avoid undefined result */\r
-            return 0;\r
-        }\r
-    }\r
-}\r
-\r
-#define SKP_SIN_APPROX_CONST0       (1073735400)\r
-#define SKP_SIN_APPROX_CONST1        (-82778932)\r
-#define SKP_SIN_APPROX_CONST2          (1059577)\r
-#define SKP_SIN_APPROX_CONST3            (-5013)\r
-\r
-/* Sine approximation; an input of 65536 corresponds to 2 * pi */\r
-/* Uses polynomial expansion of the input to the power 0, 2, 4 and 6 */\r
-/* The relative error is below 1e-5 */\r
-SKP_INLINE SKP_int32 SKP_Silk_SIN_APPROX_Q24(        /* O    returns approximately 2^24 * sin(x * 2 * pi / 65536) */\r
-    SKP_int32        x\r
-)\r
-{\r
-    SKP_int y_Q30;\r
-\r
-    /* Keep only bottom 16 bits (the function repeats itself with period 65536) */\r
-    x &= 65535;\r
-\r
-    /* Split range in four quadrants */\r
-    if( x <= 32768 ) {\r
-        if( x < 16384 ) {\r
-            /* Return cos(pi/2 - x) */\r
-            x = 16384 - x;\r
-        } else {\r
-            /* Return cos(x - pi/2) */\r
-            x -= 16384;\r
-        }\r
-        if( x < 1100 ) {\r
-            /* Special case: high accuracy */\r
-            return SKP_SMLAWB( 1 << 24, SKP_MUL( x, x ), -5053 );\r
-        }\r
-        x = SKP_SMULWB( SKP_LSHIFT( x, 8 ), x );        /* contains x^2 in Q20 */\r
-        y_Q30 = SKP_SMLAWB( SKP_SIN_APPROX_CONST2, x, SKP_SIN_APPROX_CONST3 );\r
-        y_Q30 = SKP_SMLAWW( SKP_SIN_APPROX_CONST1, x, y_Q30 );\r
-        y_Q30 = SKP_SMLAWW( SKP_SIN_APPROX_CONST0 + 66, x, y_Q30 );\r
-    } else {\r
-        if( x < 49152 ) {\r
-            /* Return -cos(3*pi/2 - x) */\r
-            x = 49152 - x;\r
-        } else {\r
-            /* Return -cos(x - 3*pi/2) */\r
-            x -= 49152;\r
-        }\r
-        if( x < 1100 ) {\r
-            /* Special case: high accuracy */\r
-            return SKP_SMLAWB( -1 << 24, SKP_MUL( x, x ), 5053 );\r
-        }\r
-        x = SKP_SMULWB( SKP_LSHIFT( x, 8 ), x );        /* contains x^2 in Q20 */\r
-        y_Q30 = SKP_SMLAWB( -SKP_SIN_APPROX_CONST2, x, -SKP_SIN_APPROX_CONST3 );\r
-        y_Q30 = SKP_SMLAWW( -SKP_SIN_APPROX_CONST1, x, y_Q30 );\r
-        y_Q30 = SKP_SMLAWW( -SKP_SIN_APPROX_CONST0, x, y_Q30 );\r
-    }\r
-    return SKP_RSHIFT_ROUND( y_Q30, 6 );\r
-}\r
-\r
-/* Cosine approximation; an input of 65536 corresponds to 2 * pi */\r
-/* The relative error is below 1e-5 */\r
-SKP_INLINE SKP_int32 SKP_Silk_COS_APPROX_Q24(        /* O    returns approximately 2^24 * cos(x * 2 * pi / 65536) */\r
-    SKP_int32        x\r
-)\r
-{\r
-    return SKP_Silk_SIN_APPROX_Q24( x + 16384 );\r
-}\r
-\r
-#ifdef  __cplusplus\r
-}\r
-#endif\r
-\r
-#endif /*_SKP_SILK_FIX_INLINES_H_*/\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*! \file SKP_Silk_Inlines.h
+ *  \brief SigProcFix_Inlines.h defines inline signal processing functions.
+ */
+
+#ifndef _SKP_SILK_FIX_INLINES_H_
+#define _SKP_SILK_FIX_INLINES_H_
+
+#ifdef  __cplusplus
+extern "C"
+{
+#endif
+
+/* count leading zeros of SKP_int64 */
+SKP_INLINE SKP_int32 SKP_Silk_CLZ64(SKP_int64 in)
+{
+    SKP_int32 in_upper;
+
+    in_upper = (SKP_int32)SKP_RSHIFT64(in, 32);
+    if (in_upper == 0) {
+        /* Search in the lower 32 bits */
+        return 32 + SKP_Silk_CLZ32( (SKP_int32) in );
+    } else {
+        /* Search in the upper 32 bits */
+        return SKP_Silk_CLZ32( in_upper );
+    }
+}
+
+/* get number of leading zeros and fractional part (the bits right after the leading one */
+SKP_INLINE void SKP_Silk_CLZ_FRAC(SKP_int32 in,            /* I: input */
+                                    SKP_int32 *lz,           /* O: number of leading zeros */
+                                    SKP_int32 *frac_Q7)      /* O: the 7 bits right after the leading one */
+{
+    SKP_int32 lzeros = SKP_Silk_CLZ32(in);
+
+    * lz = lzeros;
+    * frac_Q7 = SKP_ROR32(in, 24 - lzeros) & 0x7f;
+}
+
+/* Approximation of square root                                          */
+/* Accuracy: < +/- 10%  for output values > 15                           */
+/*           < +/- 2.5% for output values > 120                          */
+SKP_INLINE SKP_int32 SKP_Silk_SQRT_APPROX(SKP_int32 x)
+{
+    SKP_int32 y, lz, frac_Q7;
+
+    if( x <= 0 ) {
+        return 0;
+    }
+
+    SKP_Silk_CLZ_FRAC(x, &lz, &frac_Q7);
+
+    if( lz & 1 ) {
+        y = 32768;
+    } else {
+        y = 46214;        /* 46214 = sqrt(2) * 32768 */
+    }
+
+    /* get scaling right */
+    y >>= SKP_RSHIFT(lz, 1);
+
+    /* increment using fractional part of input */
+    y = SKP_SMLAWB(y, y, SKP_SMULBB(213, frac_Q7));
+
+    return y;
+}
+
+/* returns the number of left shifts before overflow for a 16 bit number (ITU definition with norm(0)=0) */
+SKP_INLINE SKP_int32 SKP_Silk_norm16(SKP_int16 a) {
+
+  SKP_int32 a32;
+
+  /* if ((a == 0) || (a == SKP_int16_MIN)) return(0); */
+  if ((a << 1) == 0) return(0);
+
+  a32 = a;
+  /* if (a32 < 0) a32 = -a32 - 1; */
+  a32 ^= SKP_RSHIFT(a32, 31);
+
+  return SKP_Silk_CLZ32(a32) - 17;
+}
+
+/* returns the number of left shifts before overflow for a 32 bit number (ITU definition with norm(0)=0) */
+SKP_INLINE SKP_int32 SKP_Silk_norm32(SKP_int32 a) {
+  
+  /* if ((a == 0) || (a == SKP_int32_MIN)) return(0); */
+  if ((a << 1) == 0) return(0);
+
+  /* if (a < 0) a = -a - 1; */
+  a ^= SKP_RSHIFT(a, 31);
+
+  return SKP_Silk_CLZ32(a) - 1;
+}
+
+/* Divide two int32 values and return result as int32 in a given Q-domain */
+SKP_INLINE SKP_int32 SKP_DIV32_varQ(    /* O    returns a good approximation of "(a32 << Qres) / b32" */
+    const SKP_int32     a32,            /* I    numerator (Q0)                  */
+    const SKP_int32     b32,            /* I    denominator (Q0)                */
+    const SKP_int       Qres            /* I    Q-domain of result (>= 0)       */
+)
+{
+    SKP_int   a_headrm, b_headrm, lshift;
+    SKP_int32 b32_inv, a32_nrm, b32_nrm, result;
+
+    SKP_assert( b32 != 0 );
+    SKP_assert( Qres >= 0 );
+
+    /* Compute number of bits head room and normalize inputs */
+    a_headrm = SKP_Silk_CLZ32( SKP_abs(a32) ) - 1;
+    a32_nrm = SKP_LSHIFT(a32, a_headrm);                                    /* Q: a_headrm                    */
+    b_headrm = SKP_Silk_CLZ32( SKP_abs(b32) ) - 1;
+    b32_nrm = SKP_LSHIFT(b32, b_headrm);                                    /* Q: b_headrm                    */
+
+    /* Inverse of b32, with 14 bits of precision */
+    b32_inv = SKP_DIV32_16( SKP_int32_MAX >> 2, SKP_RSHIFT(b32_nrm, 16) );  /* Q: 29 + 16 - b_headrm        */
+
+    /* First approximation */
+    result = SKP_SMULWB(a32_nrm, b32_inv);                                  /* Q: 29 + a_headrm - b_headrm    */
+
+    /* Compute residual by subtracting product of denominator and first approximation */
+    a32_nrm -= SKP_LSHIFT_ovflw( SKP_SMMUL(b32_nrm, result), 3 );           /* Q: a_headrm                    */
+
+    /* Refinement */
+    result = SKP_SMLAWB(result, a32_nrm, b32_inv);                          /* Q: 29 + a_headrm - b_headrm    */
+
+    /* Convert to Qres domain */
+    lshift = 29 + a_headrm - b_headrm - Qres;
+    if( lshift <= 0 ) {
+        return SKP_LSHIFT_SAT32(result, -lshift);
+    } else {
+        if( lshift < 32){
+            return SKP_RSHIFT(result, lshift);
+        } else {
+            /* Avoid undefined result */
+            return 0;
+        }
+    }
+}
+
+/* Invert int32 value and return result as int32 in a given Q-domain */
+SKP_INLINE SKP_int32 SKP_INVERSE32_varQ(    /* O    returns a good approximation of "(1 << Qres) / b32" */
+    const SKP_int32     b32,                /* I    denominator (Q0)                */
+    const SKP_int       Qres                /* I    Q-domain of result (> 0)        */
+)
+{
+    SKP_int   b_headrm, lshift;
+    SKP_int32 b32_inv, b32_nrm, err_Q32, result;
+
+    SKP_assert( b32 != 0 );
+    SKP_assert( b32 != SKP_int32_MIN ); /* SKP_int32_MIN is not handled by SKP_abs */
+    SKP_assert( Qres > 0 );
+
+    /* Compute number of bits head room and normalize input */
+    b_headrm = SKP_Silk_CLZ32( SKP_abs(b32) ) - 1;
+    b32_nrm = SKP_LSHIFT(b32, b_headrm);                                    /* Q: b_headrm                */
+
+    /* Inverse of b32, with 14 bits of precision */
+    b32_inv = SKP_DIV32_16( SKP_int32_MAX >> 2, SKP_RSHIFT(b32_nrm, 16) );  /* Q: 29 + 16 - b_headrm    */
+
+    /* First approximation */
+    result = SKP_LSHIFT(b32_inv, 16);                                       /* Q: 61 - b_headrm            */
+
+    /* Compute residual by subtracting product of denominator and first approximation from one */
+    err_Q32 = SKP_LSHIFT_ovflw( -SKP_SMULWB(b32_nrm, b32_inv), 3 );         /* Q32                        */
+
+    /* Refinement */
+    result = SKP_SMLAWW(result, err_Q32, b32_inv);                          /* Q: 61 - b_headrm            */
+
+    /* Convert to Qres domain */
+    lshift = 61 - b_headrm - Qres;
+    if( lshift <= 0 ) {
+        return SKP_LSHIFT_SAT32(result, -lshift);
+    } else {
+        if( lshift < 32){
+            return SKP_RSHIFT(result, lshift);
+        }else{
+            /* Avoid undefined result */
+            return 0;
+        }
+    }
+}
+
+#define SKP_SIN_APPROX_CONST0       (1073735400)
+#define SKP_SIN_APPROX_CONST1        (-82778932)
+#define SKP_SIN_APPROX_CONST2          (1059577)
+#define SKP_SIN_APPROX_CONST3            (-5013)
+
+/* Sine approximation; an input of 65536 corresponds to 2 * pi */
+/* Uses polynomial expansion of the input to the power 0, 2, 4 and 6 */
+/* The relative error is below 1e-5 */
+SKP_INLINE SKP_int32 SKP_Silk_SIN_APPROX_Q24(        /* O    returns approximately 2^24 * sin(x * 2 * pi / 65536) */
+    SKP_int32        x
+)
+{
+    SKP_int y_Q30;
+
+    /* Keep only bottom 16 bits (the function repeats itself with period 65536) */
+    x &= 65535;
+
+    /* Split range in four quadrants */
+    if( x <= 32768 ) {
+        if( x < 16384 ) {
+            /* Return cos(pi/2 - x) */
+            x = 16384 - x;
+        } else {
+            /* Return cos(x - pi/2) */
+            x -= 16384;
+        }
+        if( x < 1100 ) {
+            /* Special case: high accuracy */
+            return SKP_SMLAWB( 1 << 24, SKP_MUL( x, x ), -5053 );
+        }
+        x = SKP_SMULWB( SKP_LSHIFT( x, 8 ), x );        /* contains x^2 in Q20 */
+        y_Q30 = SKP_SMLAWB( SKP_SIN_APPROX_CONST2, x, SKP_SIN_APPROX_CONST3 );
+        y_Q30 = SKP_SMLAWW( SKP_SIN_APPROX_CONST1, x, y_Q30 );
+        y_Q30 = SKP_SMLAWW( SKP_SIN_APPROX_CONST0 + 66, x, y_Q30 );
+    } else {
+        if( x < 49152 ) {
+            /* Return -cos(3*pi/2 - x) */
+            x = 49152 - x;
+        } else {
+            /* Return -cos(x - 3*pi/2) */
+            x -= 49152;
+        }
+        if( x < 1100 ) {
+            /* Special case: high accuracy */
+            return SKP_SMLAWB( -1 << 24, SKP_MUL( x, x ), 5053 );
+        }
+        x = SKP_SMULWB( SKP_LSHIFT( x, 8 ), x );        /* contains x^2 in Q20 */
+        y_Q30 = SKP_SMLAWB( -SKP_SIN_APPROX_CONST2, x, -SKP_SIN_APPROX_CONST3 );
+        y_Q30 = SKP_SMLAWW( -SKP_SIN_APPROX_CONST1, x, y_Q30 );
+        y_Q30 = SKP_SMLAWW( -SKP_SIN_APPROX_CONST0, x, y_Q30 );
+    }
+    return SKP_RSHIFT_ROUND( y_Q30, 6 );
+}
+
+/* Cosine approximation; an input of 65536 corresponds to 2 * pi */
+/* The relative error is below 1e-5 */
+SKP_INLINE SKP_int32 SKP_Silk_COS_APPROX_Q24(        /* O    returns approximately 2^24 * cos(x * 2 * pi / 65536) */
+    SKP_int32        x
+)
+{
+    return SKP_Silk_SIN_APPROX_Q24( x + 16384 );
+}
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif /*_SKP_SILK_FIX_INLINES_H_*/
index d1c2e9fe60867fb94ef5c0b6924358cfb8835d34..380a4543ceb616e44bdbeb624b6b9b017aa50ca8 100644 (file)
@@ -1,40 +1,40 @@
-/***********************************************************************\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
-/* Resets LBRR buffer, used if packet size changes */\r
-void SKP_Silk_LBRR_reset( \r
-    SKP_Silk_encoder_state      *psEncC             /* I/O  state                                       */\r
-)\r
-{\r
-    SKP_int i;\r
-\r
-    for( i = 0; i < MAX_LBRR_DELAY; i++ ) {\r
-        psEncC->LBRR_buffer[ i ].usage = SKP_SILK_NO_LBRR;\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Resets LBRR buffer, used if packet size changes */
+void SKP_Silk_LBRR_reset( 
+    SKP_Silk_encoder_state      *psEncC             /* I/O  state                                       */
+)
+{
+    SKP_int i;
+
+    for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
+        psEncC->LBRR_buffer[ i ].usage = SKP_SILK_NO_LBRR;
+    }
+}
index 4e40ccceb95cee7c99a8f990aa2928a630bf2940..4a4f3f0317bf1aacc185faca17c035a4113bc725 100644 (file)
-/***********************************************************************\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_LPC_inverse_pred_gain.c                                   *\r
- *                                                                      *\r
- * Compute inverse of LPC prediction gain, and                          *\r
- * test if LPC coefficients are stable (all poles within unit circle)   *\r
- *                                                                      *\r
- * Copyright 2008 (c), Skype Limited                                    *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-#define QA          16\r
-#define A_LIMIT     SKP_FIX_CONST( 0.99975, QA )\r
-\r
-/* Compute inverse of LPC prediction gain, and                          */\r
-/* test if LPC coefficients are stable (all poles within unit circle)   */\r
-static SKP_int LPC_inverse_pred_gain_QA(        /* O:   Returns 1 if unstable, otherwise 0          */\r
-    SKP_int32           *invGain_Q30,           /* O:   Inverse prediction gain, Q30 energy domain  */\r
-    SKP_int32           A_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ],         \r
-                                                /* I:   Prediction coefficients                     */\r
-    const SKP_int       order                   /* I:   Prediction order                            */\r
-)\r
-{\r
-    SKP_int   k, n, headrm;\r
-    SKP_int32 rc_Q31, rc_mult1_Q30, rc_mult2_Q16, tmp_QA;\r
-    SKP_int32 *Aold_QA, *Anew_QA;\r
-\r
-    Anew_QA = A_QA[ order & 1 ];\r
-\r
-    *invGain_Q30 = ( 1 << 30 );\r
-    for( k = order - 1; k > 0; k-- ) {\r
-        /* Check for stability */\r
-        if( ( Anew_QA[ k ] > A_LIMIT ) || ( Anew_QA[ k ] < -A_LIMIT ) ) {\r
-            return 1;\r
-        }\r
-\r
-        /* Set RC equal to negated AR coef */\r
-        rc_Q31 = -SKP_LSHIFT( Anew_QA[ k ], 31 - QA );\r
-        \r
-        /* rc_mult1_Q30 range: [ 1 : 2^30-1 ] */\r
-        rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 );\r
-        SKP_assert( rc_mult1_Q30 > ( 1 << 15 ) );                   /* reduce A_LIMIT if fails */\r
-        SKP_assert( rc_mult1_Q30 < ( 1 << 30 ) );\r
-\r
-        /* rc_mult2_Q16 range: [ 2^16 : SKP_int32_MAX ] */\r
-        rc_mult2_Q16 = SKP_INVERSE32_varQ( rc_mult1_Q30, 46 );      /* 16 = 46 - 30 */\r
-\r
-        /* Update inverse gain */\r
-        /* invGain_Q30 range: [ 0 : 2^30 ] */\r
-        *invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 );\r
-        SKP_assert( *invGain_Q30 >= 0           );\r
-        SKP_assert( *invGain_Q30 <= ( 1 << 30 ) );\r
-\r
-        /* Swap pointers */\r
-        Aold_QA = Anew_QA;\r
-        Anew_QA = A_QA[ k & 1 ];\r
-        \r
-        /* Update AR coefficient */\r
-        headrm = SKP_Silk_CLZ32( rc_mult2_Q16 ) - 1;\r
-        rc_mult2_Q16 = SKP_LSHIFT( rc_mult2_Q16, headrm );          /* Q: 16 + headrm */\r
-        for( n = 0; n < k; n++ ) {\r
-            tmp_QA = Aold_QA[ n ] - SKP_LSHIFT( SKP_SMMUL( Aold_QA[ k - n - 1 ], rc_Q31 ), 1 );\r
-            Anew_QA[ n ] = SKP_LSHIFT( SKP_SMMUL( tmp_QA, rc_mult2_Q16 ), 16 - headrm );\r
-        }\r
-    }\r
-\r
-    /* Check for stability */\r
-    if( ( Anew_QA[ 0 ] > A_LIMIT ) || ( Anew_QA[ 0 ] < -A_LIMIT ) ) {\r
-        return 1;\r
-    }\r
-\r
-    /* Set RC equal to negated AR coef */\r
-    rc_Q31 = -SKP_LSHIFT( Anew_QA[ 0 ], 31 - QA );\r
-\r
-    /* Range: [ 1 : 2^30 ] */\r
-    rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 );\r
-\r
-    /* Update inverse gain */\r
-    /* Range: [ 0 : 2^30 ] */\r
-    *invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 );\r
-    SKP_assert( *invGain_Q30 >= 0     );\r
-    SKP_assert( *invGain_Q30 <= 1<<30 );\r
-\r
-    return 0;\r
-}\r
-/* For input in Q12 domain */\r
-SKP_int SKP_Silk_LPC_inverse_pred_gain(       /* O:   Returns 1 if unstable, otherwise 0          */\r
-    SKP_int32           *invGain_Q30,           /* O:   Inverse prediction gain, Q30 energy domain  */\r
-    const SKP_int16     *A_Q12,                 /* I:   Prediction coefficients, Q12 [order]        */\r
-    const SKP_int       order                   /* I:   Prediction order                            */\r
-)\r
-{\r
-    SKP_int   k;\r
-    SKP_int32 Atmp_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ];\r
-    SKP_int32 *Anew_QA;\r
-\r
-    Anew_QA = Atmp_QA[ order & 1 ];\r
-\r
-    /* Increase Q domain of the AR coefficients */\r
-    for( k = 0; k < order; k++ ) {\r
-        Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q12[ k ], QA - 12 );\r
-    }\r
-\r
-    return LPC_inverse_pred_gain_QA( invGain_Q30, Atmp_QA, order );\r
-}\r
-\r
-/* For input in Q24 domain */\r
-SKP_int SKP_Silk_LPC_inverse_pred_gain_Q24(   /* O:   Returns 1 if unstable, otherwise 0          */\r
-    SKP_int32           *invGain_Q30,           /* O:   Inverse prediction gain, Q30 energy domain  */\r
-    const SKP_int32     *A_Q24,                 /* I:   Prediction coefficients, Q24 [order]        */\r
-    const SKP_int       order                   /* I:   Prediction order                            */\r
-)\r
-{\r
-    SKP_int   k;\r
-    SKP_int32 Atmp_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ];\r
-    SKP_int32 *Anew_QA;\r
-\r
-    Anew_QA = Atmp_QA[ order & 1 ];\r
-\r
-    /* Increase Q domain of the AR coefficients */\r
-    for( k = 0; k < order; k++ ) {\r
-        Anew_QA[ k ] = SKP_RSHIFT_ROUND( A_Q24[ k ], 24 - QA );\r
-    }\r
-\r
-    return LPC_inverse_pred_gain_QA( invGain_Q30, Atmp_QA, order );\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_LPC_inverse_pred_gain.c                                   *
+ *                                                                      *
+ * Compute inverse of LPC prediction gain, and                          *
+ * test if LPC coefficients are stable (all poles within unit circle)   *
+ *                                                                      *
+ * Copyright 2008 (c), Skype Limited                                    *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+#define QA          16
+#define A_LIMIT     SKP_FIX_CONST( 0.99975, QA )
+
+/* Compute inverse of LPC prediction gain, and                          */
+/* test if LPC coefficients are stable (all poles within unit circle)   */
+static SKP_int LPC_inverse_pred_gain_QA(        /* O:   Returns 1 if unstable, otherwise 0          */
+    SKP_int32           *invGain_Q30,           /* O:   Inverse prediction gain, Q30 energy domain  */
+    SKP_int32           A_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ],         
+                                                /* I:   Prediction coefficients                     */
+    const SKP_int       order                   /* I:   Prediction order                            */
+)
+{
+    SKP_int   k, n, headrm;
+    SKP_int32 rc_Q31, rc_mult1_Q30, rc_mult2_Q16, tmp_QA;
+    SKP_int32 *Aold_QA, *Anew_QA;
+
+    Anew_QA = A_QA[ order & 1 ];
+
+    *invGain_Q30 = ( 1 << 30 );
+    for( k = order - 1; k > 0; k-- ) {
+        /* Check for stability */
+        if( ( Anew_QA[ k ] > A_LIMIT ) || ( Anew_QA[ k ] < -A_LIMIT ) ) {
+            return 1;
+        }
+
+        /* Set RC equal to negated AR coef */
+        rc_Q31 = -SKP_LSHIFT( Anew_QA[ k ], 31 - QA );
+        
+        /* rc_mult1_Q30 range: [ 1 : 2^30-1 ] */
+        rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 );
+        SKP_assert( rc_mult1_Q30 > ( 1 << 15 ) );                   /* reduce A_LIMIT if fails */
+        SKP_assert( rc_mult1_Q30 < ( 1 << 30 ) );
+
+        /* rc_mult2_Q16 range: [ 2^16 : SKP_int32_MAX ] */
+        rc_mult2_Q16 = SKP_INVERSE32_varQ( rc_mult1_Q30, 46 );      /* 16 = 46 - 30 */
+
+        /* Update inverse gain */
+        /* invGain_Q30 range: [ 0 : 2^30 ] */
+        *invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 );
+        SKP_assert( *invGain_Q30 >= 0           );
+        SKP_assert( *invGain_Q30 <= ( 1 << 30 ) );
+
+        /* Swap pointers */
+        Aold_QA = Anew_QA;
+        Anew_QA = A_QA[ k & 1 ];
+        
+        /* Update AR coefficient */
+        headrm = SKP_Silk_CLZ32( rc_mult2_Q16 ) - 1;
+        rc_mult2_Q16 = SKP_LSHIFT( rc_mult2_Q16, headrm );          /* Q: 16 + headrm */
+        for( n = 0; n < k; n++ ) {
+            tmp_QA = Aold_QA[ n ] - SKP_LSHIFT( SKP_SMMUL( Aold_QA[ k - n - 1 ], rc_Q31 ), 1 );
+            Anew_QA[ n ] = SKP_LSHIFT( SKP_SMMUL( tmp_QA, rc_mult2_Q16 ), 16 - headrm );
+        }
+    }
+
+    /* Check for stability */
+    if( ( Anew_QA[ 0 ] > A_LIMIT ) || ( Anew_QA[ 0 ] < -A_LIMIT ) ) {
+        return 1;
+    }
+
+    /* Set RC equal to negated AR coef */
+    rc_Q31 = -SKP_LSHIFT( Anew_QA[ 0 ], 31 - QA );
+
+    /* Range: [ 1 : 2^30 ] */
+    rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 );
+
+    /* Update inverse gain */
+    /* Range: [ 0 : 2^30 ] */
+    *invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 );
+    SKP_assert( *invGain_Q30 >= 0     );
+    SKP_assert( *invGain_Q30 <= 1<<30 );
+
+    return 0;
+}
+/* For input in Q12 domain */
+SKP_int SKP_Silk_LPC_inverse_pred_gain(       /* O:   Returns 1 if unstable, otherwise 0          */
+    SKP_int32           *invGain_Q30,           /* O:   Inverse prediction gain, Q30 energy domain  */
+    const SKP_int16     *A_Q12,                 /* I:   Prediction coefficients, Q12 [order]        */
+    const SKP_int       order                   /* I:   Prediction order                            */
+)
+{
+    SKP_int   k;
+    SKP_int32 Atmp_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ];
+    SKP_int32 *Anew_QA;
+
+    Anew_QA = Atmp_QA[ order & 1 ];
+
+    /* Increase Q domain of the AR coefficients */
+    for( k = 0; k < order; k++ ) {
+        Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q12[ k ], QA - 12 );
+    }
+
+    return LPC_inverse_pred_gain_QA( invGain_Q30, Atmp_QA, order );
+}
+
+/* For input in Q24 domain */
+SKP_int SKP_Silk_LPC_inverse_pred_gain_Q24(   /* O:   Returns 1 if unstable, otherwise 0          */
+    SKP_int32           *invGain_Q30,           /* O:   Inverse prediction gain, Q30 energy domain  */
+    const SKP_int32     *A_Q24,                 /* I:   Prediction coefficients, Q24 [order]        */
+    const SKP_int       order                   /* I:   Prediction order                            */
+)
+{
+    SKP_int   k;
+    SKP_int32 Atmp_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ];
+    SKP_int32 *Anew_QA;
+
+    Anew_QA = Atmp_QA[ order & 1 ];
+
+    /* Increase Q domain of the AR coefficients */
+    for( k = 0; k < order; k++ ) {
+        Anew_QA[ k ] = SKP_RSHIFT_ROUND( A_Q24[ k ], 24 - QA );
+    }
+
+    return LPC_inverse_pred_gain_QA( invGain_Q30, Atmp_QA, order );
+}
+
index e5f8d24abbbbf43ace14ed99a6858d88d1d6c430..5559bf544107abe73b7c0cbdaa365e2721ed2a58 100644 (file)
@@ -1,84 +1,84 @@
-/***********************************************************************\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_LPC_synthesis_filter.c                                    *\r
- * Coefficients are in Q12                                              *\r
- *                                                                      *\r
- * even order AR filter                                                 *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* even order AR filter */\r
-void SKP_Silk_LPC_synthesis_filter(\r
-    const SKP_int16 *in,        /* I:   excitation signal */\r
-    const SKP_int16 *A_Q12,     /* I:   AR coefficients [Order], between -8_Q0 and 8_Q0 */\r
-    const SKP_int32 Gain_Q26,   /* I:   gain */\r
-    SKP_int32 *S,               /* I/O: state vector [Order] */\r
-    SKP_int16 *out,             /* O:   output signal */\r
-    const SKP_int32 len,        /* I:   signal length */\r
-    const SKP_int Order         /* I:   filter order, must be even */\r
-)\r
-{\r
-    SKP_int   k, j, idx, Order_half = SKP_RSHIFT( Order, 1 );\r
-    SKP_int32 SA, SB, out32_Q10, out32;\r
-\r
-    /* Order must be even */\r
-    SKP_assert( 2 * Order_half == Order );\r
-\r
-    /* S[] values are in Q14 */\r
-    for( k = 0; k < len; k++ ) {\r
-        SA = S[ Order - 1 ];\r
-        out32_Q10 = 0;\r
-        for( j = 0; j < ( Order_half - 1 ); j++ ) {\r
-            idx = SKP_SMULBB( 2, j ) + 1;\r
-            SB = S[ Order - 1 - idx ];\r
-            S[ Order - 1 - idx ] = SA;\r
-            out32_Q10 = SKP_SMLAWB( out32_Q10, SA, A_Q12[ ( j << 1 ) ] );\r
-            out32_Q10 = SKP_SMLAWB( out32_Q10, SB, A_Q12[ ( j << 1 ) + 1 ] );\r
-            SA = S[ Order - 2 - idx ];\r
-            S[ Order - 2 - idx ] = SB;\r
-        }\r
-\r
-        /* unrolled loop: epilog */\r
-        SB = S[ 0 ];\r
-        S[ 0 ] = SA;\r
-        out32_Q10 = SKP_SMLAWB( out32_Q10, SA, A_Q12[ Order - 2 ] );\r
-        out32_Q10 = SKP_SMLAWB( out32_Q10, SB, A_Q12[ Order - 1 ] );\r
-        /* apply gain to excitation signal and add to prediction */\r
-        out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[ k ] ) );\r
-\r
-        /* scale to Q0 */\r
-        out32 = SKP_RSHIFT_ROUND( out32_Q10, 10 );\r
-\r
-        /* saturate output */\r
-        out[ k ] = ( SKP_int16 )SKP_SAT16( out32 );\r
-\r
-        /* move result into delay line */\r
-        S[ Order - 1 ] = SKP_LSHIFT_SAT32( out32_Q10, 4 );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_LPC_synthesis_filter.c                                    *
+ * Coefficients are in Q12                                              *
+ *                                                                      *
+ * even order AR filter                                                 *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* even order AR filter */
+void SKP_Silk_LPC_synthesis_filter(
+    const SKP_int16 *in,        /* I:   excitation signal */
+    const SKP_int16 *A_Q12,     /* I:   AR coefficients [Order], between -8_Q0 and 8_Q0 */
+    const SKP_int32 Gain_Q26,   /* I:   gain */
+    SKP_int32 *S,               /* I/O: state vector [Order] */
+    SKP_int16 *out,             /* O:   output signal */
+    const SKP_int32 len,        /* I:   signal length */
+    const SKP_int Order         /* I:   filter order, must be even */
+)
+{
+    SKP_int   k, j, idx, Order_half = SKP_RSHIFT( Order, 1 );
+    SKP_int32 SA, SB, out32_Q10, out32;
+
+    /* Order must be even */
+    SKP_assert( 2 * Order_half == Order );
+
+    /* S[] values are in Q14 */
+    for( k = 0; k < len; k++ ) {
+        SA = S[ Order - 1 ];
+        out32_Q10 = 0;
+        for( j = 0; j < ( Order_half - 1 ); j++ ) {
+            idx = SKP_SMULBB( 2, j ) + 1;
+            SB = S[ Order - 1 - idx ];
+            S[ Order - 1 - idx ] = SA;
+            out32_Q10 = SKP_SMLAWB( out32_Q10, SA, A_Q12[ ( j << 1 ) ] );
+            out32_Q10 = SKP_SMLAWB( out32_Q10, SB, A_Q12[ ( j << 1 ) + 1 ] );
+            SA = S[ Order - 2 - idx ];
+            S[ Order - 2 - idx ] = SB;
+        }
+
+        /* unrolled loop: epilog */
+        SB = S[ 0 ];
+        S[ 0 ] = SA;
+        out32_Q10 = SKP_SMLAWB( out32_Q10, SA, A_Q12[ Order - 2 ] );
+        out32_Q10 = SKP_SMLAWB( out32_Q10, SB, A_Q12[ Order - 1 ] );
+        /* apply gain to excitation signal and add to prediction */
+        out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[ k ] ) );
+
+        /* scale to Q0 */
+        out32 = SKP_RSHIFT_ROUND( out32_Q10, 10 );
+
+        /* saturate output */
+        out[ k ] = ( SKP_int16 )SKP_SAT16( out32 );
+
+        /* move result into delay line */
+        S[ Order - 1 ] = SKP_LSHIFT_SAT32( out32_Q10, 4 );
+    }
+}
index 82d8afd9cd9397c0b27ac26a20439e31aa274b57..3dafaadafa5c3cfdb382219db74bbe006e1b30e5 100644 (file)
-/***********************************************************************\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_LPC_synthesis_order16.c                                   *\r
- * Coefficients are in Q12                                              *\r
- *                                                                      *\r
- * 16th order AR filter                                                 *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* 16th order AR filter */\r
-void SKP_Silk_LPC_synthesis_order16(const SKP_int16 *in,          /* I:   excitation signal */\r
-                                      const SKP_int16 *A_Q12,       /* I:   AR coefficients [16], between -8_Q0 and 8_Q0 */\r
-                                      const SKP_int32 Gain_Q26,     /* I:   gain */\r
-                                      SKP_int32 *S,                 /* I/O: state vector [16] */\r
-                                      SKP_int16 *out,               /* O:   output signal */\r
-                                      const SKP_int32 len           /* I:   signal length, must be multiple of 16 */\r
-)\r
-{\r
-    SKP_int   k;\r
-    SKP_int32 SA, SB, out32_Q10, out32;\r
-    for( k = 0; k < len; k++ ) {\r
-        /* unrolled loop: prolog */\r
-        /* multiply-add two prediction coefficients per iteration */\r
-        SA = S[ 15 ];\r
-        SB = S[ 14 ];\r
-        S[ 14 ] = SA;\r
-        out32_Q10 = SKP_SMULWB(                  SA, A_Q12[ 0 ] );\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 1 ] );\r
-        SA = S[ 13 ];\r
-        S[ 13 ] = SB;\r
-\r
-        /* unrolled loop: main loop */\r
-        SB = S[ 12 ];\r
-        S[ 12 ] = SA;\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 2 ] );\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 3 ] );\r
-        SA = S[ 11 ];\r
-        S[ 11 ] = SB;\r
-\r
-        SB = S[ 10 ];\r
-        S[ 10 ] = SA;\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 4 ] );\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 5 ] );\r
-        SA = S[ 9 ];\r
-        S[ 9 ] = SB;\r
-\r
-        SB = S[ 8 ];\r
-        S[ 8 ] = SA;\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 6 ] );\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 7 ] );\r
-        SA = S[ 7 ];\r
-        S[ 7 ] = SB;\r
-\r
-        SB = S[ 6 ];\r
-        S[ 6 ] = SA;\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 8 ] );\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 9 ] );\r
-        SA = S[ 5 ];\r
-        S[ 5 ] = SB;\r
-\r
-        SB = S[ 4 ];\r
-        S[ 4 ] = SA;\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 10 ] );\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 11 ] );\r
-        SA = S[ 3 ];\r
-        S[ 3 ] = SB;\r
-\r
-        SB = S[ 2 ];\r
-        S[ 2 ] = SA;\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 12 ] );\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 13 ] );\r
-        SA = S[ 1 ];\r
-        S[ 1 ] = SB;\r
-\r
-        /* unrolled loop: epilog */\r
-        SB = S[ 0 ];\r
-        S[ 0 ] = SA;\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 14 ] );\r
-        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 15 ] );\r
-\r
-        /* unrolled loop: end */\r
-        /* apply gain to excitation signal and add to prediction */\r
-        out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[ k ] ) );\r
-\r
-        /* scale to Q0 */\r
-        out32 = SKP_RSHIFT_ROUND( out32_Q10, 10 );\r
-\r
-        /* saturate output */\r
-        out[ k ] = ( SKP_int16 )SKP_SAT16( out32 );\r
-\r
-        /* move result into delay line */\r
-        S[ 15 ] = SKP_LSHIFT_SAT32( out32_Q10, 4 );\r
-    }\r
-}\r
-\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_LPC_synthesis_order16.c                                   *
+ * Coefficients are in Q12                                              *
+ *                                                                      *
+ * 16th order AR filter                                                 *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* 16th order AR filter */
+void SKP_Silk_LPC_synthesis_order16(const SKP_int16 *in,          /* I:   excitation signal */
+                                      const SKP_int16 *A_Q12,       /* I:   AR coefficients [16], between -8_Q0 and 8_Q0 */
+                                      const SKP_int32 Gain_Q26,     /* I:   gain */
+                                      SKP_int32 *S,                 /* I/O: state vector [16] */
+                                      SKP_int16 *out,               /* O:   output signal */
+                                      const SKP_int32 len           /* I:   signal length, must be multiple of 16 */
+)
+{
+    SKP_int   k;
+    SKP_int32 SA, SB, out32_Q10, out32;
+    for( k = 0; k < len; k++ ) {
+        /* unrolled loop: prolog */
+        /* multiply-add two prediction coefficients per iteration */
+        SA = S[ 15 ];
+        SB = S[ 14 ];
+        S[ 14 ] = SA;
+        out32_Q10 = SKP_SMULWB(                  SA, A_Q12[ 0 ] );
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 1 ] );
+        SA = S[ 13 ];
+        S[ 13 ] = SB;
+
+        /* unrolled loop: main loop */
+        SB = S[ 12 ];
+        S[ 12 ] = SA;
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 2 ] );
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 3 ] );
+        SA = S[ 11 ];
+        S[ 11 ] = SB;
+
+        SB = S[ 10 ];
+        S[ 10 ] = SA;
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 4 ] );
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 5 ] );
+        SA = S[ 9 ];
+        S[ 9 ] = SB;
+
+        SB = S[ 8 ];
+        S[ 8 ] = SA;
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 6 ] );
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 7 ] );
+        SA = S[ 7 ];
+        S[ 7 ] = SB;
+
+        SB = S[ 6 ];
+        S[ 6 ] = SA;
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 8 ] );
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 9 ] );
+        SA = S[ 5 ];
+        S[ 5 ] = SB;
+
+        SB = S[ 4 ];
+        S[ 4 ] = SA;
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 10 ] );
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 11 ] );
+        SA = S[ 3 ];
+        S[ 3 ] = SB;
+
+        SB = S[ 2 ];
+        S[ 2 ] = SA;
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 12 ] );
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 13 ] );
+        SA = S[ 1 ];
+        S[ 1 ] = SB;
+
+        /* unrolled loop: epilog */
+        SB = S[ 0 ];
+        S[ 0 ] = SA;
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 14 ] );
+        out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 15 ] );
+
+        /* unrolled loop: end */
+        /* apply gain to excitation signal and add to prediction */
+        out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[ k ] ) );
+
+        /* scale to Q0 */
+        out32 = SKP_RSHIFT_ROUND( out32_Q10, 10 );
+
+        /* saturate output */
+        out[ k ] = ( SKP_int16 )SKP_SAT16( out32 );
+
+        /* move result into delay line */
+        S[ 15 ] = SKP_LSHIFT_SAT32( out32_Q10, 4 );
+    }
+}
+
+
index e0717431a42281d8e7e4ed7eb578b44f0ba85d3c..a05388dcc1d96c750167088286f2abc727a9f882 100644 (file)
-/***********************************************************************\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
-\r
-    Elliptic/Cauer filters designed with 0.1 dB passband ripple, \r
-        80 dB minimum stopband attenuation, and\r
-        [0.95 : 0.15 : 0.35] normalized cut off frequencies.\r
-\r
-*/\r
-#include "SKP_Silk_main.h"\r
-\r
-#if SWITCH_TRANSITION_FILTERING\r
-\r
-/* Helper function, that 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
-    const SKP_int       ind,\r
-    const SKP_int32     fac_Q16\r
-)\r
-{\r
-    SKP_int nb, na;\r
-\r
-    if( ind < TRANSITION_INT_NUM - 1 ) {\r
-        if( fac_Q16 > 0 ) {\r
-            if( fac_Q16 == SKP_SAT16( fac_Q16 ) ) { /* fac_Q16 is in range of a 16-bit int */\r
-                /* Piece-wise linear interpolation of B and A */\r
-                for( nb = 0; nb < TRANSITION_NB; nb++ ) {\r
-                    B_Q28[ nb ] = SKP_SMLAWB(\r
-                        SKP_Silk_Transition_LP_B_Q28[ ind     ][ nb ],\r
-                        SKP_Silk_Transition_LP_B_Q28[ ind + 1 ][ nb ] -\r
-                        SKP_Silk_Transition_LP_B_Q28[ ind     ][ nb ],\r
-                        fac_Q16 );\r
-                }\r
-                for( na = 0; na < TRANSITION_NA; na++ ) {\r
-                    A_Q28[ na ] = SKP_SMLAWB(\r
-                        SKP_Silk_Transition_LP_A_Q28[ ind     ][ na ],\r
-                        SKP_Silk_Transition_LP_A_Q28[ ind + 1 ][ na ] -\r
-                        SKP_Silk_Transition_LP_A_Q28[ ind     ][ na ],\r
-                        fac_Q16 );\r
-                }\r
-            } else if( fac_Q16 == ( 1 << 15 ) ) { /* Neither fac_Q16 nor ( ( 1 << 16 ) - fac_Q16 ) is in range of a 16-bit int */\r
-\r
-                /* Piece-wise linear interpolation of B and A */\r
-                for( nb = 0; nb < TRANSITION_NB; nb++ ) {\r
-                    B_Q28[ nb ] = SKP_RSHIFT( \r
-                        SKP_Silk_Transition_LP_B_Q28[ ind     ][ nb ] +\r
-                        SKP_Silk_Transition_LP_B_Q28[ ind + 1 ][ nb ],\r
-                        1 );\r
-                }\r
-                for( na = 0; na < TRANSITION_NA; na++ ) {\r
-                    A_Q28[ na ] = SKP_RSHIFT( \r
-                        SKP_Silk_Transition_LP_A_Q28[ ind     ][ na ] + \r
-                        SKP_Silk_Transition_LP_A_Q28[ ind + 1 ][ na ], \r
-                        1 );\r
-                }\r
-            } else { /* ( ( 1 << 16 ) - fac_Q16 ) is in range of a 16-bit int */\r
-                \r
-                SKP_assert( ( ( 1 << 16 ) - fac_Q16 ) == SKP_SAT16( ( ( 1 << 16 ) - fac_Q16) ) );\r
-                /* Piece-wise linear interpolation of B and A */\r
-                for( nb = 0; nb < TRANSITION_NB; nb++ ) {\r
-                    B_Q28[ nb ] = SKP_SMLAWB(\r
-                        SKP_Silk_Transition_LP_B_Q28[ ind + 1 ][ nb ],\r
-                        SKP_Silk_Transition_LP_B_Q28[ ind     ][ nb ] -\r
-                        SKP_Silk_Transition_LP_B_Q28[ ind + 1 ][ nb ],\r
-                        ( 1 << 16 ) - fac_Q16 );\r
-                }\r
-                for( na = 0; na < TRANSITION_NA; na++ ) {\r
-                    A_Q28[ na ] = SKP_SMLAWB(\r
-                        SKP_Silk_Transition_LP_A_Q28[ ind + 1 ][ na ],\r
-                        SKP_Silk_Transition_LP_A_Q28[ ind     ][ na ] -\r
-                        SKP_Silk_Transition_LP_A_Q28[ ind + 1 ][ na ],\r
-                        ( 1 << 16 ) - fac_Q16 );\r
-                }\r
-            }\r
-        } else {\r
-            SKP_memcpy( B_Q28, SKP_Silk_Transition_LP_B_Q28[ ind ], TRANSITION_NB * sizeof( SKP_int32 ) );\r
-            SKP_memcpy( A_Q28, SKP_Silk_Transition_LP_A_Q28[ ind ], TRANSITION_NA * sizeof( SKP_int32 ) );\r
-        }\r
-    } else {\r
-        SKP_memcpy( B_Q28, SKP_Silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM - 1 ], TRANSITION_NB * sizeof( SKP_int32 ) );\r
-        SKP_memcpy( A_Q28, SKP_Silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM - 1 ], TRANSITION_NA * sizeof( SKP_int32 ) );\r
-    }\r
-}\r
-\r
-/* Low-pass filter with variable cutoff frequency based on  */\r
-/* piece-wise linear interpolation between elliptic filters */\r
-/* Start by setting psEncC->transition_frame_no = 1;            */\r
-/* Deactivate by setting psEncC->transition_frame_no = 0;   */\r
-void SKP_Silk_LP_variable_cutoff(\r
-    SKP_Silk_LP_state               *psLP,          /* I/O  LP filter state                     */\r
-    SKP_int16                       *out,           /* O    Low-pass filtered output signal     */\r
-    const SKP_int16                 *in,            /* I    Input signal                        */\r
-    const SKP_int                   frame_length    /* I    Frame length                        */\r
-)\r
-{\r
-    SKP_int32   B_Q28[ TRANSITION_NB ], A_Q28[ TRANSITION_NA ], fac_Q16 = 0;\r
-    SKP_int     ind = 0;\r
-\r
-    SKP_assert( psLP->transition_frame_no >= 0 );\r
-    SKP_assert( ( ( ( psLP->transition_frame_no <= TRANSITION_FRAMES_DOWN ) && ( psLP->mode == 0 ) ) || \r
-                  ( ( psLP->transition_frame_no <= TRANSITION_FRAMES_UP   ) && ( psLP->mode == 1 ) ) ) );\r
-\r
-    /* Interpolate filter coefficients if needed */\r
-    if( psLP->transition_frame_no > 0 ) {\r
-        if( psLP->mode == 0 ) {\r
-            if( psLP->transition_frame_no < TRANSITION_FRAMES_DOWN ) {\r
-                /* Calculate index and interpolation factor for interpolation */\r
-#if( TRANSITION_INT_STEPS_DOWN == 32 )\r
-                fac_Q16 = SKP_LSHIFT( psLP->transition_frame_no, 16 - 5 );\r
-#else\r
-                fac_Q16 = SKP_DIV32_16( SKP_LSHIFT( psLP->transition_frame_no, 16 ), TRANSITION_INT_STEPS_DOWN );\r
-#endif\r
-                ind      = SKP_RSHIFT( fac_Q16, 16 );\r
-                fac_Q16 -= SKP_LSHIFT( ind, 16 );\r
-\r
-                SKP_assert( ind >= 0 );\r
-                SKP_assert( ind < TRANSITION_INT_NUM );\r
-\r
-                /* Interpolate filter coefficients */\r
-                SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, ind, fac_Q16 );\r
-\r
-                /* Increment transition frame number for next frame */\r
-                psLP->transition_frame_no++;\r
-\r
-            } else {\r
-                SKP_assert( psLP->transition_frame_no == TRANSITION_FRAMES_DOWN );\r
-                /* End of transition phase */\r
-                SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, TRANSITION_INT_NUM - 1, 0 );\r
-            }\r
-        } else {\r
-            SKP_assert( psLP->mode == 1 );\r
-            if( psLP->transition_frame_no < TRANSITION_FRAMES_UP ) {\r
-                /* Calculate index and interpolation factor for interpolation */\r
-#if( TRANSITION_INT_STEPS_UP == 64 )\r
-                fac_Q16 = SKP_LSHIFT( TRANSITION_FRAMES_UP - psLP->transition_frame_no, 16 - 6 );\r
-#else\r
-                fac_Q16 = SKP_DIV32_16( SKP_LSHIFT( TRANSITION_FRAMES_UP - psLP->transition_frame_no, 16 ), TRANSITION_INT_STEPS_UP );\r
-#endif\r
-                ind      = SKP_RSHIFT( fac_Q16, 16 );\r
-                fac_Q16 -= SKP_LSHIFT( ind, 16 );\r
-\r
-                SKP_assert( ind >= 0 );\r
-                SKP_assert( ind < TRANSITION_INT_NUM );\r
-\r
-                /* Interpolate filter coefficients */\r
-                SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, ind, fac_Q16 );\r
-\r
-                /* Increment transition frame number for next frame */\r
-                psLP->transition_frame_no++;\r
-            \r
-            } else {\r
-                SKP_assert( psLP->transition_frame_no == TRANSITION_FRAMES_UP );\r
-                /* End of transition phase */\r
-                SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, 0, 0 );\r
-            }\r
-        }\r
-    } \r
-    \r
-    if( psLP->transition_frame_no > 0 ) {\r
-        /* ARMA low-pass filtering */\r
-        SKP_assert( TRANSITION_NB == 3 && TRANSITION_NA == 2 );\r
-        SKP_Silk_biquad_alt( in, B_Q28, A_Q28, psLP->In_LP_State, out, frame_length );\r
-    } else {\r
-        /* Instead of using the filter, copy input directly to output */\r
-        SKP_memcpy( out, in, frame_length * sizeof( SKP_int16 ) );\r
-    }\r
-}\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/* 
+
+    Elliptic/Cauer filters designed with 0.1 dB passband ripple, 
+        80 dB minimum stopband attenuation, and
+        [0.95 : 0.15 : 0.35] normalized cut off frequencies.
+
+*/
+#include "SKP_Silk_main.h"
+
+#if SWITCH_TRANSITION_FILTERING
+
+/* Helper function, that interpolates the filter taps */
+SKP_INLINE void SKP_Silk_LP_interpolate_filter_taps( 
+    SKP_int32           B_Q28[ TRANSITION_NB ], 
+    SKP_int32           A_Q28[ TRANSITION_NA ],
+    const SKP_int       ind,
+    const SKP_int32     fac_Q16
+)
+{
+    SKP_int nb, na;
+
+    if( ind < TRANSITION_INT_NUM - 1 ) {
+        if( fac_Q16 > 0 ) {
+            if( fac_Q16 == SKP_SAT16( fac_Q16 ) ) { /* fac_Q16 is in range of a 16-bit int */
+                /* Piece-wise linear interpolation of B and A */
+                for( nb = 0; nb < TRANSITION_NB; nb++ ) {
+                    B_Q28[ nb ] = SKP_SMLAWB(
+                        SKP_Silk_Transition_LP_B_Q28[ ind     ][ nb ],
+                        SKP_Silk_Transition_LP_B_Q28[ ind + 1 ][ nb ] -
+                        SKP_Silk_Transition_LP_B_Q28[ ind     ][ nb ],
+                        fac_Q16 );
+                }
+                for( na = 0; na < TRANSITION_NA; na++ ) {
+                    A_Q28[ na ] = SKP_SMLAWB(
+                        SKP_Silk_Transition_LP_A_Q28[ ind     ][ na ],
+                        SKP_Silk_Transition_LP_A_Q28[ ind + 1 ][ na ] -
+                        SKP_Silk_Transition_LP_A_Q28[ ind     ][ na ],
+                        fac_Q16 );
+                }
+            } else if( fac_Q16 == ( 1 << 15 ) ) { /* Neither fac_Q16 nor ( ( 1 << 16 ) - fac_Q16 ) is in range of a 16-bit int */
+
+                /* Piece-wise linear interpolation of B and A */
+                for( nb = 0; nb < TRANSITION_NB; nb++ ) {
+                    B_Q28[ nb ] = SKP_RSHIFT( 
+                        SKP_Silk_Transition_LP_B_Q28[ ind     ][ nb ] +
+                        SKP_Silk_Transition_LP_B_Q28[ ind + 1 ][ nb ],
+                        1 );
+                }
+                for( na = 0; na < TRANSITION_NA; na++ ) {
+                    A_Q28[ na ] = SKP_RSHIFT( 
+                        SKP_Silk_Transition_LP_A_Q28[ ind     ][ na ] + 
+                        SKP_Silk_Transition_LP_A_Q28[ ind + 1 ][ na ], 
+                        1 );
+                }
+            } else { /* ( ( 1 << 16 ) - fac_Q16 ) is in range of a 16-bit int */
+                
+                SKP_assert( ( ( 1 << 16 ) - fac_Q16 ) == SKP_SAT16( ( ( 1 << 16 ) - fac_Q16) ) );
+                /* Piece-wise linear interpolation of B and A */
+                for( nb = 0; nb < TRANSITION_NB; nb++ ) {
+                    B_Q28[ nb ] = SKP_SMLAWB(
+                        SKP_Silk_Transition_LP_B_Q28[ ind + 1 ][ nb ],
+                        SKP_Silk_Transition_LP_B_Q28[ ind     ][ nb ] -
+                        SKP_Silk_Transition_LP_B_Q28[ ind + 1 ][ nb ],
+                        ( 1 << 16 ) - fac_Q16 );
+                }
+                for( na = 0; na < TRANSITION_NA; na++ ) {
+                    A_Q28[ na ] = SKP_SMLAWB(
+                        SKP_Silk_Transition_LP_A_Q28[ ind + 1 ][ na ],
+                        SKP_Silk_Transition_LP_A_Q28[ ind     ][ na ] -
+                        SKP_Silk_Transition_LP_A_Q28[ ind + 1 ][ na ],
+                        ( 1 << 16 ) - fac_Q16 );
+                }
+            }
+        } else {
+            SKP_memcpy( B_Q28, SKP_Silk_Transition_LP_B_Q28[ ind ], TRANSITION_NB * sizeof( SKP_int32 ) );
+            SKP_memcpy( A_Q28, SKP_Silk_Transition_LP_A_Q28[ ind ], TRANSITION_NA * sizeof( SKP_int32 ) );
+        }
+    } else {
+        SKP_memcpy( B_Q28, SKP_Silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM - 1 ], TRANSITION_NB * sizeof( SKP_int32 ) );
+        SKP_memcpy( A_Q28, SKP_Silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM - 1 ], TRANSITION_NA * sizeof( SKP_int32 ) );
+    }
+}
+
+/* Low-pass filter with variable cutoff frequency based on  */
+/* piece-wise linear interpolation between elliptic filters */
+/* Start by setting psEncC->transition_frame_no = 1;            */
+/* Deactivate by setting psEncC->transition_frame_no = 0;   */
+void SKP_Silk_LP_variable_cutoff(
+    SKP_Silk_LP_state               *psLP,          /* I/O  LP filter state                     */
+    SKP_int16                       *out,           /* O    Low-pass filtered output signal     */
+    const SKP_int16                 *in,            /* I    Input signal                        */
+    const SKP_int                   frame_length    /* I    Frame length                        */
+)
+{
+    SKP_int32   B_Q28[ TRANSITION_NB ], A_Q28[ TRANSITION_NA ], fac_Q16 = 0;
+    SKP_int     ind = 0;
+
+    SKP_assert( psLP->transition_frame_no >= 0 );
+    SKP_assert( ( ( ( psLP->transition_frame_no <= TRANSITION_FRAMES_DOWN ) && ( psLP->mode == 0 ) ) || 
+                  ( ( psLP->transition_frame_no <= TRANSITION_FRAMES_UP   ) && ( psLP->mode == 1 ) ) ) );
+
+    /* Interpolate filter coefficients if needed */
+    if( psLP->transition_frame_no > 0 ) {
+        if( psLP->mode == 0 ) {
+            if( psLP->transition_frame_no < TRANSITION_FRAMES_DOWN ) {
+                /* Calculate index and interpolation factor for interpolation */
+#if( TRANSITION_INT_STEPS_DOWN == 32 )
+                fac_Q16 = SKP_LSHIFT( psLP->transition_frame_no, 16 - 5 );
+#else
+                fac_Q16 = SKP_DIV32_16( SKP_LSHIFT( psLP->transition_frame_no, 16 ), TRANSITION_INT_STEPS_DOWN );
+#endif
+                ind      = SKP_RSHIFT( fac_Q16, 16 );
+                fac_Q16 -= SKP_LSHIFT( ind, 16 );
+
+                SKP_assert( ind >= 0 );
+                SKP_assert( ind < TRANSITION_INT_NUM );
+
+                /* Interpolate filter coefficients */
+                SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, ind, fac_Q16 );
+
+                /* Increment transition frame number for next frame */
+                psLP->transition_frame_no++;
+
+            } else {
+                SKP_assert( psLP->transition_frame_no == TRANSITION_FRAMES_DOWN );
+                /* End of transition phase */
+                SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, TRANSITION_INT_NUM - 1, 0 );
+            }
+        } else {
+            SKP_assert( psLP->mode == 1 );
+            if( psLP->transition_frame_no < TRANSITION_FRAMES_UP ) {
+                /* Calculate index and interpolation factor for interpolation */
+#if( TRANSITION_INT_STEPS_UP == 64 )
+                fac_Q16 = SKP_LSHIFT( TRANSITION_FRAMES_UP - psLP->transition_frame_no, 16 - 6 );
+#else
+                fac_Q16 = SKP_DIV32_16( SKP_LSHIFT( TRANSITION_FRAMES_UP - psLP->transition_frame_no, 16 ), TRANSITION_INT_STEPS_UP );
+#endif
+                ind      = SKP_RSHIFT( fac_Q16, 16 );
+                fac_Q16 -= SKP_LSHIFT( ind, 16 );
+
+                SKP_assert( ind >= 0 );
+                SKP_assert( ind < TRANSITION_INT_NUM );
+
+                /* Interpolate filter coefficients */
+                SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, ind, fac_Q16 );
+
+                /* Increment transition frame number for next frame */
+                psLP->transition_frame_no++;
+            
+            } else {
+                SKP_assert( psLP->transition_frame_no == TRANSITION_FRAMES_UP );
+                /* End of transition phase */
+                SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, 0, 0 );
+            }
+        }
+    } 
+    
+    if( psLP->transition_frame_no > 0 ) {
+        /* ARMA low-pass filtering */
+        SKP_assert( TRANSITION_NB == 3 && TRANSITION_NA == 2 );
+        SKP_Silk_biquad_alt( in, B_Q28, A_Q28, psLP->In_LP_State, out, frame_length );
+    } else {
+        /* Instead of using the filter, copy input directly to output */
+        SKP_memcpy( out, in, frame_length * sizeof( SKP_int16 ) );
+    }
+}
+#endif
index 1fc87a7af0fc4fc76e34d01e4eab64e652720fff..01398e26c308c53e26e4d22bff81f5cf9803126d 100644 (file)
@@ -1,65 +1,65 @@
-/***********************************************************************\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_SigProc_FIX.h"\r
-\r
-// Q12 values (even)\r
-const SKP_int SKP_Silk_LSFCosTab_FIX_Q12[LSF_COS_TAB_SZ_FIX + 1] = {\r
-            8192,             8190,             8182,             8170,     \r
-            8152,             8130,             8104,             8072,     \r
-            8034,             7994,             7946,             7896,     \r
-            7840,             7778,             7714,             7644,     \r
-            7568,             7490,             7406,             7318,     \r
-            7226,             7128,             7026,             6922,     \r
-            6812,             6698,             6580,             6458,     \r
-            6332,             6204,             6070,             5934,     \r
-            5792,             5648,             5502,             5352,     \r
-            5198,             5040,             4880,             4718,     \r
-            4552,             4382,             4212,             4038,     \r
-            3862,             3684,             3502,             3320,     \r
-            3136,             2948,             2760,             2570,     \r
-            2378,             2186,             1990,             1794,     \r
-            1598,             1400,             1202,             1002,     \r
-             802,              602,              402,              202,     \r
-               0,             -202,             -402,             -602,     \r
-            -802,            -1002,            -1202,            -1400,     \r
-           -1598,            -1794,            -1990,            -2186,     \r
-           -2378,            -2570,            -2760,            -2948,     \r
-           -3136,            -3320,            -3502,            -3684,     \r
-           -3862,            -4038,            -4212,            -4382,     \r
-           -4552,            -4718,            -4880,            -5040,     \r
-           -5198,            -5352,            -5502,            -5648,     \r
-           -5792,            -5934,            -6070,            -6204,     \r
-           -6332,            -6458,            -6580,            -6698,     \r
-           -6812,            -6922,            -7026,            -7128,     \r
-           -7226,            -7318,            -7406,            -7490,     \r
-           -7568,            -7644,            -7714,            -7778,     \r
-           -7840,            -7896,            -7946,            -7994,     \r
-           -8034,            -8072,            -8104,            -8130,     \r
-           -8152,            -8170,            -8182,            -8190,     \r
-           -8192\r
-};\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+// Q12 values (even)
+const SKP_int SKP_Silk_LSFCosTab_FIX_Q12[LSF_COS_TAB_SZ_FIX + 1] = {
+            8192,             8190,             8182,             8170,     
+            8152,             8130,             8104,             8072,     
+            8034,             7994,             7946,             7896,     
+            7840,             7778,             7714,             7644,     
+            7568,             7490,             7406,             7318,     
+            7226,             7128,             7026,             6922,     
+            6812,             6698,             6580,             6458,     
+            6332,             6204,             6070,             5934,     
+            5792,             5648,             5502,             5352,     
+            5198,             5040,             4880,             4718,     
+            4552,             4382,             4212,             4038,     
+            3862,             3684,             3502,             3320,     
+            3136,             2948,             2760,             2570,     
+            2378,             2186,             1990,             1794,     
+            1598,             1400,             1202,             1002,     
+             802,              602,              402,              202,     
+               0,             -202,             -402,             -602,     
+            -802,            -1002,            -1202,            -1400,     
+           -1598,            -1794,            -1990,            -2186,     
+           -2378,            -2570,            -2760,            -2948,     
+           -3136,            -3320,            -3502,            -3684,     
+           -3862,            -4038,            -4212,            -4382,     
+           -4552,            -4718,            -4880,            -5040,     
+           -5198,            -5352,            -5502,            -5648,     
+           -5792,            -5934,            -6070,            -6204,     
+           -6332,            -6458,            -6580,            -6698,     
+           -6812,            -6922,            -7026,            -7128,     
+           -7226,            -7318,            -7406,            -7490,     
+           -7568,            -7644,            -7714,            -7778,     
+           -7840,            -7896,            -7946,            -7994,     
+           -8034,            -8072,            -8104,            -8130,     
+           -8152,            -8170,            -8182,            -8190,     
+           -8192
+};
index 5013214d77db3119331542b724bfc724c711a40f..9717d6b46e4028cd274c470dc184244dc9d5ab6a 100644 (file)
@@ -1,80 +1,80 @@
-/***********************************************************************\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_FIX.h"\r
-\r
-void SKP_Silk_LTP_analysis_filter_FIX(\r
-    SKP_int16       *LTP_res,                           /* O:   LTP residual signal of length NB_SUBFR * ( pre_length + subfr_length )  */\r
-    const SKP_int16 *x,                                 /* I:   Pointer to input signal with at least max( pitchL ) preceeding samples  */\r
-    const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],/* I:   LTP_ORDER LTP coefficients for each NB_SUBFR subframe                   */\r
-    const SKP_int   pitchL[ NB_SUBFR ],                 /* I:   Pitch lag, one for each subframe                                        */\r
-    const SKP_int32 invGains_Q16[ NB_SUBFR ],           /* I:   Inverse quantization gains, one for each subframe                       */\r
-    const SKP_int   subfr_length,                       /* I:   Length of each subframe                                                 */\r
-    const SKP_int   pre_length                          /* I:   Length of the preceeding samples starting at &x[0] for each subframe    */\r
-)\r
-{\r
-    const SKP_int16 *x_ptr, *x_lag_ptr;\r
-    SKP_int16   Btmp_Q14[ LTP_ORDER ];\r
-    SKP_int16   *LTP_res_ptr;\r
-    SKP_int     k, i, j;\r
-    SKP_int32   LTP_est;\r
-\r
-    x_ptr = x;\r
-    LTP_res_ptr = LTP_res;\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-\r
-        x_lag_ptr = x_ptr - pitchL[ k ];\r
-        for( i = 0; i < LTP_ORDER; i++ ) {\r
-            Btmp_Q14[ i ] = LTPCoef_Q14[ k * LTP_ORDER + i ];\r
-        }\r
-\r
-        /* LTP analysis FIR filter */\r
-        for( i = 0; i < subfr_length + pre_length; i++ ) {\r
-            LTP_res_ptr[ i ] = x_ptr[ i ];\r
-            \r
-            /* Long-term prediction */\r
-            LTP_est = SKP_SMULBB( x_lag_ptr[ LTP_ORDER / 2 ], Btmp_Q14[ 0 ] );\r
-            for( j = 1; j < LTP_ORDER; j++ ) {\r
-                LTP_est = SKP_SMLABB_ovflw( LTP_est, x_lag_ptr[ LTP_ORDER / 2 - j ], Btmp_Q14[ j ] );\r
-                       }\r
-            LTP_est = SKP_RSHIFT_ROUND( LTP_est, 14 ); // round and -> Q0\r
-\r
-            /* Subtract long-term prediction */\r
-            LTP_res_ptr[ i ] = ( SKP_int16 )SKP_SAT16( ( SKP_int32 )x_ptr[ i ] - LTP_est );\r
-\r
-            /* Scale residual */\r
-            LTP_res_ptr[ i ] = SKP_SMULWB( invGains_Q16[ k ], LTP_res_ptr[ i ] );\r
-\r
-            x_lag_ptr++;\r
-        }\r
-\r
-        /* Update pointers */\r
-        LTP_res_ptr += subfr_length + pre_length; \r
-        x_ptr       += subfr_length;\r
-    }\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+void SKP_Silk_LTP_analysis_filter_FIX(
+    SKP_int16       *LTP_res,                           /* O:   LTP residual signal of length NB_SUBFR * ( pre_length + subfr_length )  */
+    const SKP_int16 *x,                                 /* I:   Pointer to input signal with at least max( pitchL ) preceeding samples  */
+    const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],/* I:   LTP_ORDER LTP coefficients for each NB_SUBFR subframe                   */
+    const SKP_int   pitchL[ NB_SUBFR ],                 /* I:   Pitch lag, one for each subframe                                        */
+    const SKP_int32 invGains_Q16[ NB_SUBFR ],           /* I:   Inverse quantization gains, one for each subframe                       */
+    const SKP_int   subfr_length,                       /* I:   Length of each subframe                                                 */
+    const SKP_int   pre_length                          /* I:   Length of the preceeding samples starting at &x[0] for each subframe    */
+)
+{
+    const SKP_int16 *x_ptr, *x_lag_ptr;
+    SKP_int16   Btmp_Q14[ LTP_ORDER ];
+    SKP_int16   *LTP_res_ptr;
+    SKP_int     k, i, j;
+    SKP_int32   LTP_est;
+
+    x_ptr = x;
+    LTP_res_ptr = LTP_res;
+    for( k = 0; k < NB_SUBFR; k++ ) {
+
+        x_lag_ptr = x_ptr - pitchL[ k ];
+        for( i = 0; i < LTP_ORDER; i++ ) {
+            Btmp_Q14[ i ] = LTPCoef_Q14[ k * LTP_ORDER + i ];
+        }
+
+        /* LTP analysis FIR filter */
+        for( i = 0; i < subfr_length + pre_length; i++ ) {
+            LTP_res_ptr[ i ] = x_ptr[ i ];
+            
+            /* Long-term prediction */
+            LTP_est = SKP_SMULBB( x_lag_ptr[ LTP_ORDER / 2 ], Btmp_Q14[ 0 ] );
+            for( j = 1; j < LTP_ORDER; j++ ) {
+                LTP_est = SKP_SMLABB_ovflw( LTP_est, x_lag_ptr[ LTP_ORDER / 2 - j ], Btmp_Q14[ j ] );
+                       }
+            LTP_est = SKP_RSHIFT_ROUND( LTP_est, 14 ); // round and -> Q0
+
+            /* Subtract long-term prediction */
+            LTP_res_ptr[ i ] = ( SKP_int16 )SKP_SAT16( ( SKP_int32 )x_ptr[ i ] - LTP_est );
+
+            /* Scale residual */
+            LTP_res_ptr[ i ] = SKP_SMULWB( invGains_Q16[ k ], LTP_res_ptr[ i ] );
+
+            x_lag_ptr++;
+        }
+
+        /* Update pointers */
+        LTP_res_ptr += subfr_length + pre_length; 
+        x_ptr       += subfr_length;
+    }
+}
+
index be4520caeadc582fb425450da62b8f6704f546fa..a17d0ae41defc8ca451fdaffd5ada906e6c34b4b 100644 (file)
@@ -1,81 +1,81 @@
-/***********************************************************************\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_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, frames_per_packet;\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->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
-    psEncCtrl->sCmn.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 0% */\r
-    if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {\r
-        \r
-        frames_per_packet = SKP_DIV32_16( psEnc->sCmn.PacketSize_ms, FRAME_LENGTH_MS );\r
-\r
-        round_loss += frames_per_packet - 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
-            psEncCtrl->sCmn.LTP_scaleIndex = 2;\r
-        } else if( g_limit_Q15 > thrld2_Q15 ) {\r
-            /* Medium scaling */\r
-            psEncCtrl->sCmn.LTP_scaleIndex = 1;\r
-        }\r
-    }\r
-    psEncCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ psEncCtrl->sCmn.LTP_scaleIndex ];\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+#define NB_THRESHOLDS           11
+
+/* Table containing trained thresholds for LTP scaling */
+static const SKP_int16 LTPScaleThresholds_Q15[ NB_THRESHOLDS ] = 
+{
+    31129, 26214, 16384, 13107, 9830, 6554,
+     4915,  3276,  2621,  2458,    0
+};
+
+void SKP_Silk_LTP_scale_ctrl_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,     /* I/O  encoder state FIX                           */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl  /* I/O  encoder control FIX                         */
+)
+{
+    SKP_int round_loss, frames_per_packet;
+    SKP_int g_out_Q5, g_limit_Q15, thrld1_Q15, thrld2_Q15;
+
+    /* 1st order high-pass filter */
+    psEnc->HPLTPredCodGain_Q7 = SKP_max_int( psEncCtrl->LTPredCodGain_Q7 - psEnc->prevLTPredCodGain_Q7, 0 ) 
+        + SKP_RSHIFT_ROUND( psEnc->HPLTPredCodGain_Q7, 1 );
+    
+    psEnc->prevLTPredCodGain_Q7 = psEncCtrl->LTPredCodGain_Q7;
+
+    /* combine input and filtered input */
+    g_out_Q5    = SKP_RSHIFT_ROUND( SKP_RSHIFT( psEncCtrl->LTPredCodGain_Q7, 1 ) + SKP_RSHIFT( psEnc->HPLTPredCodGain_Q7, 1 ), 3 );
+    g_limit_Q15 = SKP_Silk_sigm_Q15( g_out_Q5 - ( 3 << 5 ) );
+            
+    /* Default is minimum scaling */
+    psEncCtrl->sCmn.LTP_scaleIndex = 0;
+
+    /* Round the loss measure to whole pct */
+    round_loss = ( SKP_int )psEnc->sCmn.PacketLoss_perc;
+
+    /* Only scale if first frame in packet 0% */
+    if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
+        
+        frames_per_packet = SKP_DIV32_16( psEnc->sCmn.PacketSize_ms, FRAME_LENGTH_MS );
+
+        round_loss += frames_per_packet - 1;
+        thrld1_Q15 = LTPScaleThresholds_Q15[ SKP_min_int( round_loss,     NB_THRESHOLDS - 1 ) ];
+        thrld2_Q15 = LTPScaleThresholds_Q15[ SKP_min_int( round_loss + 1, NB_THRESHOLDS - 1 ) ];
+    
+        if( g_limit_Q15 > thrld1_Q15 ) {
+            /* Maximum scaling */
+            psEncCtrl->sCmn.LTP_scaleIndex = 2;
+        } else if( g_limit_Q15 > thrld2_Q15 ) {
+            /* Medium scaling */
+            psEncCtrl->sCmn.LTP_scaleIndex = 1;
+        }
+    }
+    psEncCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ psEncCtrl->sCmn.LTP_scaleIndex ];
+}
index 1a12df9cff805d057c70d9eca3624482a55c5709..9f3c74e25b27daf4786f09b9f001bfc4771b841e 100644 (file)
-/***********************************************************************\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_MA.c                                                      *\r
- *                                                                      *\r
- * Variable order MA filter                                             *\r
- *                                                                      *\r
- * Copyright 2006 (c), Skype Limited                                    *\r
- * Date: 060221                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Variable order MA prediction error filter */\r
-void SKP_Silk_MA_Prediction(\r
-    const SKP_int16      *in,            /* I:   Input signal                                */\r
-    const SKP_int16      *B,             /* I:   MA prediction coefficients, Q12 [order]     */\r
-    SKP_int32            *S,             /* I/O: State vector [order]                        */\r
-    SKP_int16            *out,           /* O:   Output signal                               */\r
-    const SKP_int32      len,            /* I:   Signal length                               */\r
-    const SKP_int32      order           /* I:   Filter order                                */\r
-)\r
-{\r
-    SKP_int   k, d, in16;\r
-    SKP_int32 out32;\r
-\r
-    for( k = 0; k < len; k++ ) {\r
-        in16 = in[ k ];\r
-        out32 = SKP_LSHIFT( in16, 12 ) - S[ 0 ];\r
-        out32 = SKP_RSHIFT_ROUND( out32, 12 );\r
-        \r
-        for( d = 0; d < order - 1; d++ ) {\r
-            S[ d ] = SKP_SMLABB_ovflw( S[ d + 1 ], in16, B[ d ] );\r
-        }\r
-        S[ order - 1 ] = SKP_SMULBB( in16, B[ order - 1 ] );\r
-\r
-        /* Limit */\r
-        out[ k ] = (SKP_int16)SKP_SAT16( out32 );\r
-    }\r
-}\r
-\r
-\r
-void SKP_Silk_LPC_analysis_filter(\r
-    const SKP_int16      *in,            /* I:   Input signal                                */\r
-    const SKP_int16      *B,             /* I:   MA prediction coefficients, Q12 [order]     */\r
-    SKP_int16            *S,             /* I/O: State vector [order]                        */\r
-    SKP_int16            *out,           /* O:   Output signal                               */\r
-    const SKP_int32      len,            /* I:   Signal length                               */\r
-    const SKP_int32      Order           /* I:   Filter order                                */\r
-)\r
-{\r
-    SKP_int   k, j, idx, Order_half = SKP_RSHIFT( Order, 1 );\r
-    SKP_int32 out32_Q12, out32;\r
-    SKP_int16 SA, SB;\r
-    /* Order must be even */\r
-    SKP_assert( 2 * Order_half == Order );\r
-\r
-    /* S[] values are in Q0 */\r
-    for( k = 0; k < len; k++ ) {\r
-        SA = S[ 0 ];\r
-        out32_Q12 = 0;\r
-        for( j = 0; j < ( Order_half - 1 ); j++ ) {\r
-            idx = SKP_SMULBB( 2, j ) + 1;\r
-            /* Multiply-add two prediction coefficients for each loop */\r
-            SB = S[ idx ];\r
-            S[ idx ] = SA;\r
-            out32_Q12 = SKP_SMLABB( out32_Q12, SA, B[ idx - 1 ] );\r
-            out32_Q12 = SKP_SMLABB( out32_Q12, SB, B[ idx ] );\r
-            SA = S[ idx + 1 ];\r
-            S[ idx + 1 ] = SB;\r
-        }\r
-\r
-        /* Unrolled loop: epilog */\r
-        SB = S[ Order - 1 ];\r
-        S[ Order - 1 ] = SA;\r
-        out32_Q12 = SKP_SMLABB( out32_Q12, SA, B[ Order - 2 ] );\r
-        out32_Q12 = SKP_SMLABB( out32_Q12, SB, B[ Order - 1 ] );\r
-\r
-        /* Subtract prediction */\r
-        out32_Q12 = SKP_SUB_SAT32( SKP_LSHIFT( (SKP_int32)in[ k ], 12 ), out32_Q12 );\r
-\r
-        /* Scale to Q0 */\r
-        out32 = SKP_RSHIFT_ROUND( out32_Q12, 12 );\r
-\r
-        /* Saturate output */\r
-        out[ k ] = ( SKP_int16 )SKP_SAT16( out32 );\r
-\r
-        /* Move input line */\r
-        S[ 0 ] = in[ k ];\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_MA.c                                                      *
+ *                                                                      *
+ * Variable order MA filter                                             *
+ *                                                                      *
+ * Copyright 2006 (c), Skype Limited                                    *
+ * Date: 060221                                                         *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Variable order MA prediction error filter */
+void SKP_Silk_MA_Prediction(
+    const SKP_int16      *in,            /* I:   Input signal                                */
+    const SKP_int16      *B,             /* I:   MA prediction coefficients, Q12 [order]     */
+    SKP_int32            *S,             /* I/O: State vector [order]                        */
+    SKP_int16            *out,           /* O:   Output signal                               */
+    const SKP_int32      len,            /* I:   Signal length                               */
+    const SKP_int32      order           /* I:   Filter order                                */
+)
+{
+    SKP_int   k, d, in16;
+    SKP_int32 out32;
+
+    for( k = 0; k < len; k++ ) {
+        in16 = in[ k ];
+        out32 = SKP_LSHIFT( in16, 12 ) - S[ 0 ];
+        out32 = SKP_RSHIFT_ROUND( out32, 12 );
+        
+        for( d = 0; d < order - 1; d++ ) {
+            S[ d ] = SKP_SMLABB_ovflw( S[ d + 1 ], in16, B[ d ] );
+        }
+        S[ order - 1 ] = SKP_SMULBB( in16, B[ order - 1 ] );
+
+        /* Limit */
+        out[ k ] = (SKP_int16)SKP_SAT16( out32 );
+    }
+}
+
+
+void SKP_Silk_LPC_analysis_filter(
+    const SKP_int16      *in,            /* I:   Input signal                                */
+    const SKP_int16      *B,             /* I:   MA prediction coefficients, Q12 [order]     */
+    SKP_int16            *S,             /* I/O: State vector [order]                        */
+    SKP_int16            *out,           /* O:   Output signal                               */
+    const SKP_int32      len,            /* I:   Signal length                               */
+    const SKP_int32      Order           /* I:   Filter order                                */
+)
+{
+    SKP_int   k, j, idx, Order_half = SKP_RSHIFT( Order, 1 );
+    SKP_int32 out32_Q12, out32;
+    SKP_int16 SA, SB;
+    /* Order must be even */
+    SKP_assert( 2 * Order_half == Order );
+
+    /* S[] values are in Q0 */
+    for( k = 0; k < len; k++ ) {
+        SA = S[ 0 ];
+        out32_Q12 = 0;
+        for( j = 0; j < ( Order_half - 1 ); j++ ) {
+            idx = SKP_SMULBB( 2, j ) + 1;
+            /* Multiply-add two prediction coefficients for each loop */
+            SB = S[ idx ];
+            S[ idx ] = SA;
+            out32_Q12 = SKP_SMLABB( out32_Q12, SA, B[ idx - 1 ] );
+            out32_Q12 = SKP_SMLABB( out32_Q12, SB, B[ idx ] );
+            SA = S[ idx + 1 ];
+            S[ idx + 1 ] = SB;
+        }
+
+        /* Unrolled loop: epilog */
+        SB = S[ Order - 1 ];
+        S[ Order - 1 ] = SA;
+        out32_Q12 = SKP_SMLABB( out32_Q12, SA, B[ Order - 2 ] );
+        out32_Q12 = SKP_SMLABB( out32_Q12, SB, B[ Order - 1 ] );
+
+        /* Subtract prediction */
+        out32_Q12 = SKP_SUB_SAT32( SKP_LSHIFT( (SKP_int32)in[ k ], 12 ), out32_Q12 );
+
+        /* Scale to Q0 */
+        out32 = SKP_RSHIFT_ROUND( out32_Q12, 12 );
+
+        /* Saturate output */
+        out[ k ] = ( SKP_int16 )SKP_SAT16( out32 );
+
+        /* Move input line */
+        S[ 0 ] = in[ k ];
+    }
+}
index 21f825c20e3abfab0a4b53e274f1c0d8a378c283..dca157dff94f94c55dde6e494b893c8ee4c6e9cd 100644 (file)
-/***********************************************************************\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
-/* conversion between prediction filter coefficients and LSFs   */\r
-/* order should be even                                         */\r
-/* a piecewise linear approximation maps LSF <-> cos(LSF)       */\r
-/* therefore the result is not accurate LSFs, but the two       */\r
-/* function are accurate inverses of each other                 */\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* helper function for NLSF2A(..) */\r
-SKP_INLINE void SKP_Silk_NLSF2A_find_poly(\r
-    SKP_int32        *out,        /* o    intermediate polynomial, Q20            */\r
-    const SKP_int32    *cLSF,     /* i    vector of interleaved 2*cos(LSFs), Q20  */\r
-    SKP_int            dd         /* i    polynomial order (= 1/2 * filter order) */\r
-)\r
-{\r
-    SKP_int        k, n;\r
-    SKP_int32    ftmp;\r
-\r
-    out[0] = SKP_LSHIFT( 1, 20 );\r
-    out[1] = -cLSF[0];\r
-    for( k = 1; k < dd; k++ ) {\r
-        ftmp = cLSF[2*k];            // Q20\r
-        out[k+1] = SKP_LSHIFT( out[k-1], 1 ) - (SKP_int32)SKP_RSHIFT_ROUND64( SKP_SMULL( ftmp, out[k] ), 20 );\r
-        for( n = k; n > 1; n-- ) {\r
-            out[n] += out[n-2] - (SKP_int32)SKP_RSHIFT_ROUND64( SKP_SMULL( ftmp, out[n-1] ), 20 );\r
-        }\r
-        out[1] -= ftmp;\r
-    }\r
-}\r
-\r
-/* compute whitening filter coefficients from normalized line spectral frequencies */\r
-void SKP_Silk_NLSF2A(\r
-    SKP_int16       *a,               /* o    monic whitening filter coefficients in Q12,  [d]    */\r
-    const SKP_int    *NLSF,           /* i    normalized line spectral frequencies in Q15, [d]    */\r
-    const SKP_int    d                /* i    filter order (should be even)                       */\r
-)\r
-{\r
-    SKP_int k, i, dd;\r
-    SKP_int32 cos_LSF_Q20[SKP_Silk_MAX_ORDER_LPC];\r
-    SKP_int32 P[SKP_Silk_MAX_ORDER_LPC/2+1], Q[SKP_Silk_MAX_ORDER_LPC/2+1];\r
-    SKP_int32 Ptmp, Qtmp;\r
-    SKP_int32 f_int;\r
-    SKP_int32 f_frac;\r
-    SKP_int32 cos_val, delta;\r
-    SKP_int32 a_int32[SKP_Silk_MAX_ORDER_LPC];\r
-    SKP_int32 maxabs, absval, idx=0, sc_Q16; \r
-\r
-    SKP_assert(LSF_COS_TAB_SZ_FIX == 128);\r
-\r
-    /* convert LSFs to 2*cos(LSF(i)), using piecewise linear curve from table */\r
-    for( k = 0; k < d; k++ ) {\r
-        SKP_assert(NLSF[k] >= 0 );\r
-        SKP_assert(NLSF[k] <= 32767 );\r
-\r
-        /* f_int on a scale 0-127 (rounded down) */\r
-        f_int = SKP_RSHIFT( NLSF[k], 15 - 7 ); \r
-        \r
-        /* f_frac, range: 0..255 */\r
-        f_frac = NLSF[k] - SKP_LSHIFT( f_int, 15 - 7 ); \r
-\r
-        SKP_assert(f_int >= 0);\r
-        SKP_assert(f_int < LSF_COS_TAB_SZ_FIX );\r
-\r
-        /* Read start and end value from table */\r
-        cos_val = SKP_Silk_LSFCosTab_FIX_Q12[ f_int ];                /* Q12 */\r
-        delta   = SKP_Silk_LSFCosTab_FIX_Q12[ f_int + 1 ] - cos_val;  /* Q12, with a range of 0..200 */\r
-\r
-        /* Linear interpolation */\r
-        cos_LSF_Q20[k] = SKP_LSHIFT( cos_val, 8 ) + SKP_MUL( delta, f_frac ); /* Q20 */\r
-    }\r
-    \r
-    dd = SKP_RSHIFT( d, 1 );\r
-\r
-    /* generate even and odd polynomials using convolution */\r
-    SKP_Silk_NLSF2A_find_poly( P, &cos_LSF_Q20[0], dd );\r
-    SKP_Silk_NLSF2A_find_poly( Q, &cos_LSF_Q20[1], dd );\r
-\r
-    /* convert even and odd polynomials to SKP_int32 Q12 filter coefs */\r
-    for( k = 0; k < dd; k++ ) {\r
-        Ptmp = P[k+1] + P[k];\r
-        Qtmp = Q[k+1] - Q[k];\r
-\r
-        /* the Ptmp and Qtmp values at this stage need to fit in int32 */\r
-\r
-        a_int32[k]     = -SKP_RSHIFT_ROUND( Ptmp + Qtmp, 9 ); /* Q20 -> Q12 */\r
-        a_int32[d-k-1] =  SKP_RSHIFT_ROUND( Qtmp - Ptmp, 9 ); /* Q20 -> Q12 */\r
-    }\r
-\r
-    /* Limit the maximum absolute value of the prediction coefficients */\r
-    for( i = 0; i < 10; i++ ) {\r
-        /* Find maximum absolute value and its index */\r
-        maxabs = 0;\r
-        for( k = 0; k < d; k++ ) {\r
-            absval = SKP_abs( a_int32[k] );\r
-            if( absval > maxabs ) {\r
-                maxabs = absval;\r
-                idx       = k;\r
-            }    \r
-        }\r
-    \r
-        if( maxabs > SKP_int16_MAX ) {    \r
-            /* Reduce magnitude of prediction coefficients */\r
-            maxabs = SKP_min( maxabs, 98369 ); // ( SKP_int32_MAX / ( 65470 >> 2 ) ) + SKP_int16_MAX = 98369 \r
-            sc_Q16 = 65470 - SKP_DIV32( SKP_MUL( 65470 >> 2, maxabs - SKP_int16_MAX ), \r
-                                        SKP_RSHIFT32( SKP_MUL( maxabs, idx + 1), 2 ) );\r
-            SKP_Silk_bwexpander_32( a_int32, d, sc_Q16 );\r
-        } else {\r
-            break;\r
-        }\r
-    }    \r
-\r
-    /* Reached the last iteration */\r
-    if( i == 10 ) {\r
-        SKP_assert(0);\r
-        for( k = 0; k < d; k++ ) {\r
-            a_int32[k] = SKP_SAT16( a_int32[k] ); \r
-        }\r
-    }\r
-\r
-    /* Return as SKP_int16 Q12 coefficients */\r
-    for( k = 0; k < d; k++ ) {\r
-        a[k] = (SKP_int16)a_int32[k];\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/* conversion between prediction filter coefficients and LSFs   */
+/* order should be even                                         */
+/* a piecewise linear approximation maps LSF <-> cos(LSF)       */
+/* therefore the result is not accurate LSFs, but the two       */
+/* function are accurate inverses of each other                 */
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* helper function for NLSF2A(..) */
+SKP_INLINE void SKP_Silk_NLSF2A_find_poly(
+    SKP_int32        *out,        /* o    intermediate polynomial, Q20            */
+    const SKP_int32    *cLSF,     /* i    vector of interleaved 2*cos(LSFs), Q20  */
+    SKP_int            dd         /* i    polynomial order (= 1/2 * filter order) */
+)
+{
+    SKP_int        k, n;
+    SKP_int32    ftmp;
+
+    out[0] = SKP_LSHIFT( 1, 20 );
+    out[1] = -cLSF[0];
+    for( k = 1; k < dd; k++ ) {
+        ftmp = cLSF[2*k];            // Q20
+        out[k+1] = SKP_LSHIFT( out[k-1], 1 ) - (SKP_int32)SKP_RSHIFT_ROUND64( SKP_SMULL( ftmp, out[k] ), 20 );
+        for( n = k; n > 1; n-- ) {
+            out[n] += out[n-2] - (SKP_int32)SKP_RSHIFT_ROUND64( SKP_SMULL( ftmp, out[n-1] ), 20 );
+        }
+        out[1] -= ftmp;
+    }
+}
+
+/* compute whitening filter coefficients from normalized line spectral frequencies */
+void SKP_Silk_NLSF2A(
+    SKP_int16       *a,               /* o    monic whitening filter coefficients in Q12,  [d]    */
+    const SKP_int    *NLSF,           /* i    normalized line spectral frequencies in Q15, [d]    */
+    const SKP_int    d                /* i    filter order (should be even)                       */
+)
+{
+    SKP_int k, i, dd;
+    SKP_int32 cos_LSF_Q20[SKP_Silk_MAX_ORDER_LPC];
+    SKP_int32 P[SKP_Silk_MAX_ORDER_LPC/2+1], Q[SKP_Silk_MAX_ORDER_LPC/2+1];
+    SKP_int32 Ptmp, Qtmp;
+    SKP_int32 f_int;
+    SKP_int32 f_frac;
+    SKP_int32 cos_val, delta;
+    SKP_int32 a_int32[SKP_Silk_MAX_ORDER_LPC];
+    SKP_int32 maxabs, absval, idx=0, sc_Q16; 
+
+    SKP_assert(LSF_COS_TAB_SZ_FIX == 128);
+
+    /* convert LSFs to 2*cos(LSF(i)), using piecewise linear curve from table */
+    for( k = 0; k < d; k++ ) {
+        SKP_assert(NLSF[k] >= 0 );
+        SKP_assert(NLSF[k] <= 32767 );
+
+        /* f_int on a scale 0-127 (rounded down) */
+        f_int = SKP_RSHIFT( NLSF[k], 15 - 7 ); 
+        
+        /* f_frac, range: 0..255 */
+        f_frac = NLSF[k] - SKP_LSHIFT( f_int, 15 - 7 ); 
+
+        SKP_assert(f_int >= 0);
+        SKP_assert(f_int < LSF_COS_TAB_SZ_FIX );
+
+        /* Read start and end value from table */
+        cos_val = SKP_Silk_LSFCosTab_FIX_Q12[ f_int ];                /* Q12 */
+        delta   = SKP_Silk_LSFCosTab_FIX_Q12[ f_int + 1 ] - cos_val;  /* Q12, with a range of 0..200 */
+
+        /* Linear interpolation */
+        cos_LSF_Q20[k] = SKP_LSHIFT( cos_val, 8 ) + SKP_MUL( delta, f_frac ); /* Q20 */
+    }
+    
+    dd = SKP_RSHIFT( d, 1 );
+
+    /* generate even and odd polynomials using convolution */
+    SKP_Silk_NLSF2A_find_poly( P, &cos_LSF_Q20[0], dd );
+    SKP_Silk_NLSF2A_find_poly( Q, &cos_LSF_Q20[1], dd );
+
+    /* convert even and odd polynomials to SKP_int32 Q12 filter coefs */
+    for( k = 0; k < dd; k++ ) {
+        Ptmp = P[k+1] + P[k];
+        Qtmp = Q[k+1] - Q[k];
+
+        /* the Ptmp and Qtmp values at this stage need to fit in int32 */
+
+        a_int32[k]     = -SKP_RSHIFT_ROUND( Ptmp + Qtmp, 9 ); /* Q20 -> Q12 */
+        a_int32[d-k-1] =  SKP_RSHIFT_ROUND( Qtmp - Ptmp, 9 ); /* Q20 -> Q12 */
+    }
+
+    /* Limit the maximum absolute value of the prediction coefficients */
+    for( i = 0; i < 10; i++ ) {
+        /* Find maximum absolute value and its index */
+        maxabs = 0;
+        for( k = 0; k < d; k++ ) {
+            absval = SKP_abs( a_int32[k] );
+            if( absval > maxabs ) {
+                maxabs = absval;
+                idx       = k;
+            }    
+        }
+    
+        if( maxabs > SKP_int16_MAX ) {    
+            /* Reduce magnitude of prediction coefficients */
+            maxabs = SKP_min( maxabs, 98369 ); // ( SKP_int32_MAX / ( 65470 >> 2 ) ) + SKP_int16_MAX = 98369 
+            sc_Q16 = 65470 - SKP_DIV32( SKP_MUL( 65470 >> 2, maxabs - SKP_int16_MAX ), 
+                                        SKP_RSHIFT32( SKP_MUL( maxabs, idx + 1), 2 ) );
+            SKP_Silk_bwexpander_32( a_int32, d, sc_Q16 );
+        } else {
+            break;
+        }
+    }    
+
+    /* Reached the last iteration */
+    if( i == 10 ) {
+        SKP_assert(0);
+        for( k = 0; k < d; k++ ) {
+            a_int32[k] = SKP_SAT16( a_int32[k] ); 
+        }
+    }
+
+    /* Return as SKP_int16 Q12 coefficients */
+    for( k = 0; k < d; k++ ) {
+        a[k] = (SKP_int16)a_int32[k];
+    }
+}
index 22e83c3a95027714f4b9563e73c916432ee1cfe3..b295891b542ecd3034fc8719df799460044859a9 100644 (file)
@@ -1,58 +1,58 @@
-/***********************************************************************\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 NLSF parameters to stable AR prediction filter coefficients */\r
-void SKP_Silk_NLSF2A_stable(\r
-    SKP_int16                       pAR_Q12[ MAX_LPC_ORDER ],   /* O    Stabilized AR coefs [LPC_order]     */ \r
-    const SKP_int                   pNLSF[ MAX_LPC_ORDER ],     /* I    NLSF vector         [LPC_order]     */\r
-    const SKP_int                   LPC_order                   /* I    LPC/LSF order                       */\r
-)\r
-{\r
-    SKP_int   i;\r
-    SKP_int32 invGain_Q30;\r
-\r
-    SKP_Silk_NLSF2A( pAR_Q12, pNLSF, LPC_order );\r
-\r
-    /* Ensure stable LPCs */\r
-    for( i = 0; i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) {\r
-        if( SKP_Silk_LPC_inverse_pred_gain( &invGain_Q30, pAR_Q12, LPC_order ) == 1 ) {\r
-            SKP_Silk_bwexpander( pAR_Q12, LPC_order, 65536 - SKP_SMULBB( 10 + i, i ) );                /* 10_Q16 = 0.00015 */\r
-        } else {\r
-            break;\r
-        }\r
-    }\r
-\r
-    /* Reached the last iteration */\r
-    if( i == MAX_LPC_STABILIZE_ITERATIONS ) {\r
-        SKP_assert( 0 );\r
-        for( i = 0; i < LPC_order; i++ ) {\r
-            pAR_Q12[ i ] = 0;\r
-        }\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Convert NLSF parameters to stable AR prediction filter coefficients */
+void SKP_Silk_NLSF2A_stable(
+    SKP_int16                       pAR_Q12[ MAX_LPC_ORDER ],   /* O    Stabilized AR coefs [LPC_order]     */ 
+    const SKP_int                   pNLSF[ MAX_LPC_ORDER ],     /* I    NLSF vector         [LPC_order]     */
+    const SKP_int                   LPC_order                   /* I    LPC/LSF order                       */
+)
+{
+    SKP_int   i;
+    SKP_int32 invGain_Q30;
+
+    SKP_Silk_NLSF2A( pAR_Q12, pNLSF, LPC_order );
+
+    /* Ensure stable LPCs */
+    for( i = 0; i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) {
+        if( SKP_Silk_LPC_inverse_pred_gain( &invGain_Q30, pAR_Q12, LPC_order ) == 1 ) {
+            SKP_Silk_bwexpander( pAR_Q12, LPC_order, 65536 - SKP_SMULBB( 10 + i, i ) );                /* 10_Q16 = 0.00015 */
+        } else {
+            break;
+        }
+    }
+
+    /* Reached the last iteration */
+    if( i == MAX_LPC_STABILIZE_ITERATIONS ) {
+        SKP_assert( 0 );
+        for( i = 0; i < LPC_order; i++ ) {
+            pAR_Q12[ i ] = 0;
+        }
+    }
+}
index 7777c53726443595603913100903eb51ef0e4e34..6422877b89cc4977342c3c61d1d7fd41e89fe4f2 100644 (file)
@@ -1,91 +1,91 @@
-/***********************************************************************\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_int                   *NLSFIndices,   /* I    Pointer to NLSF indices          [nStages x 1]      */\r
-    const SKP_int                   LPC_order       /* I    LPC order used                                      */\r
-) \r
-{\r
-    const SKP_int16 *pCB_element;\r
-          SKP_int    s;\r
-          SKP_int    i;\r
-\r
-    /* Check that each 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_Q15[ SKP_MUL( NLSFIndices[ 0 ], LPC_order ) ];\r
-\r
-    /* Initialize with the codebook vector from stage 0 */\r
-    for( i = 0; i < LPC_order; i++ ) {\r
-        pNLSF_Q15[ i ] = ( SKP_int )pCB_element[ i ];\r
-    }\r
-          \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
-        if( LPC_order == 16 ) {\r
-            /* Point to the first vector element */\r
-            pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q15[ SKP_LSHIFT( NLSFIndices[ s ], 4 ) ];\r
-\r
-            /* Add the codebook vector from the current stage */\r
-            pNLSF_Q15[  0 ] += pCB_element[  0 ];\r
-            pNLSF_Q15[  1 ] += pCB_element[  1 ];\r
-            pNLSF_Q15[  2 ] += pCB_element[  2 ];\r
-            pNLSF_Q15[  3 ] += pCB_element[  3 ];\r
-            pNLSF_Q15[  4 ] += pCB_element[  4 ];\r
-            pNLSF_Q15[  5 ] += pCB_element[  5 ];\r
-            pNLSF_Q15[  6 ] += pCB_element[  6 ];\r
-            pNLSF_Q15[  7 ] += pCB_element[  7 ];\r
-            pNLSF_Q15[  8 ] += pCB_element[  8 ];\r
-            pNLSF_Q15[  9 ] += pCB_element[  9 ];\r
-            pNLSF_Q15[ 10 ] += pCB_element[ 10 ];\r
-            pNLSF_Q15[ 11 ] += pCB_element[ 11 ];\r
-            pNLSF_Q15[ 12 ] += pCB_element[ 12 ];\r
-            pNLSF_Q15[ 13 ] += pCB_element[ 13 ];\r
-            pNLSF_Q15[ 14 ] += pCB_element[ 14 ];\r
-            pNLSF_Q15[ 15 ] += pCB_element[ 15 ];\r
-        } else {\r
-            /* Point to the first vector element */\r
-            pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q15[ SKP_SMULBB( NLSFIndices[ s ], LPC_order ) ];\r
-\r
-            /* Add the codebook vector from the current stage */\r
-            for( i = 0; i < LPC_order; i++ ) {\r
-                pNLSF_Q15[ i ] += pCB_element[ i ];\r
-            }\r
-        }\r
-    }\r
-\r
-    /* NLSF stabilization */\r
-    SKP_Silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->NDeltaMin_Q15, LPC_order );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* NLSF vector decoder */
+void SKP_Silk_NLSF_MSVQ_decode(
+    SKP_int                         *pNLSF_Q15,     /* O    Pointer to decoded output vector [LPC_ORDER x 1]    */
+    const SKP_Silk_NLSF_CB_struct   *psNLSF_CB,     /* I    Pointer to NLSF codebook struct                     */
+    const SKP_int                   *NLSFIndices,   /* I    Pointer to NLSF indices          [nStages x 1]      */
+    const SKP_int                   LPC_order       /* I    LPC order used                                      */
+) 
+{
+    const SKP_int16 *pCB_element;
+          SKP_int    s;
+          SKP_int    i;
+
+    /* Check that each index is within valid range */
+    SKP_assert( 0 <= NLSFIndices[ 0 ] && NLSFIndices[ 0 ] < psNLSF_CB->CBStages[ 0 ].nVectors );
+
+    /* Point to the first vector element */
+    pCB_element = &psNLSF_CB->CBStages[ 0 ].CB_NLSF_Q15[ SKP_MUL( NLSFIndices[ 0 ], LPC_order ) ];
+
+    /* Initialize with the codebook vector from stage 0 */
+    for( i = 0; i < LPC_order; i++ ) {
+        pNLSF_Q15[ i ] = ( SKP_int )pCB_element[ i ];
+    }
+          
+    for( s = 1; s < psNLSF_CB->nStages; s++ ) {
+        /* Check that each index is within valid range */
+        SKP_assert( 0 <= NLSFIndices[ s ] && NLSFIndices[ s ] < psNLSF_CB->CBStages[ s ].nVectors );
+
+        if( LPC_order == 16 ) {
+            /* Point to the first vector element */
+            pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q15[ SKP_LSHIFT( NLSFIndices[ s ], 4 ) ];
+
+            /* Add the codebook vector from the current stage */
+            pNLSF_Q15[  0 ] += pCB_element[  0 ];
+            pNLSF_Q15[  1 ] += pCB_element[  1 ];
+            pNLSF_Q15[  2 ] += pCB_element[  2 ];
+            pNLSF_Q15[  3 ] += pCB_element[  3 ];
+            pNLSF_Q15[  4 ] += pCB_element[  4 ];
+            pNLSF_Q15[  5 ] += pCB_element[  5 ];
+            pNLSF_Q15[  6 ] += pCB_element[  6 ];
+            pNLSF_Q15[  7 ] += pCB_element[  7 ];
+            pNLSF_Q15[  8 ] += pCB_element[  8 ];
+            pNLSF_Q15[  9 ] += pCB_element[  9 ];
+            pNLSF_Q15[ 10 ] += pCB_element[ 10 ];
+            pNLSF_Q15[ 11 ] += pCB_element[ 11 ];
+            pNLSF_Q15[ 12 ] += pCB_element[ 12 ];
+            pNLSF_Q15[ 13 ] += pCB_element[ 13 ];
+            pNLSF_Q15[ 14 ] += pCB_element[ 14 ];
+            pNLSF_Q15[ 15 ] += pCB_element[ 15 ];
+        } else {
+            /* Point to the first vector element */
+            pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q15[ SKP_SMULBB( NLSFIndices[ s ], LPC_order ) ];
+
+            /* Add the codebook vector from the current stage */
+            for( i = 0; i < LPC_order; i++ ) {
+                pNLSF_Q15[ i ] += pCB_element[ i ];
+            }
+        }
+    }
+
+    /* NLSF stabilization */
+    SKP_Silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->NDeltaMin_Q15, LPC_order );
+}
index e9e858e59aa897eb36e82428d589f5c65462f839..41b5b2cdda0f819d0b3007c4da362db5f6ebcd85 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-\r
-/***********************/\r
-/* NLSF vector encoder */\r
-/***********************/\r
-void SKP_Silk_NLSF_MSVQ_encode_FIX(\r
-          SKP_int                   *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_Q6,                 /* 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
-#if( LOW_COMPLEXITY_ONLY == 1 )\r
-    SKP_int32   pRateDist_Q18[  NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED_LC_MODE ];\r
-    SKP_int32   pRate_Q5[       MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ];\r
-    SKP_int32   pRate_new_Q5[   MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ];\r
-    SKP_int     pTempIndices[   MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ];\r
-    SKP_int     pPath[          MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_CB_STAGES ];\r
-    SKP_int     pPath_new[      MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_CB_STAGES ];\r
-    SKP_int     pRes_Q15[       MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * MAX_LPC_ORDER ];\r
-    SKP_int     pRes_new_Q15[   MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * MAX_LPC_ORDER ];\r
-#else\r
-    SKP_int32   pRateDist_Q18[  NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED ];\r
-    SKP_int32   pRate_Q5[       MAX_NLSF_MSVQ_SURVIVORS ];\r
-    SKP_int32   pRate_new_Q5[   MAX_NLSF_MSVQ_SURVIVORS ];\r
-    SKP_int     pTempIndices[   MAX_NLSF_MSVQ_SURVIVORS ];\r
-    SKP_int     pPath[          MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ];\r
-    SKP_int     pPath_new[      MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ];\r
-    SKP_int     pRes_Q15[       MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ];\r
-    SKP_int     pRes_new_Q15[   MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ];\r
-#endif\r
-\r
-    const SKP_int   *pConstInt;\r
-          SKP_int   *pInt;\r
-    const SKP_int16 *pCB_element;\r
-    const SKP_Silk_NLSF_CBS *pCurrentCBStage;\r
-\r
-#ifdef USE_UNQUANTIZED_LSFS\r
-    SKP_int NLSF_orig[ MAX_LPC_ORDER ];\r
-    SKP_memcpy( NLSF_orig, pNLSF_Q15, LPC_order * sizeof( SKP_int ) );\r
-#endif\r
-\r
-    SKP_assert( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS );\r
-    SKP_assert( ( LOW_COMPLEXITY_ONLY == 0 ) || ( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ) );\r
-\r
-\r
-    /****************************************************/\r
-    /* Tree search for the multi-stage vector quantizer */\r
-    /****************************************************/\r
-\r
-    /* Clear accumulated rates */\r
-    SKP_memset( pRate_Q5, 0, NLSF_MSVQ_Survivors * sizeof( SKP_int32 ) );\r
-    \r
-    /* Copy NLSFs into residual signal vector */\r
-    for( i = 0; i < LPC_order; i++ ) {\r
-        pRes_Q15[ i ] = pNLSF_Q15[ i ];\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_FIX( pRateDist_Q18, pCurrentCBStage, pRes_Q15, pW_Q6, \r
-            pRate_Q5, NLSF_mu_Q15, prev_survivors, 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
-            pConstInt   = &pRes_Q15[ SKP_SMULBB( input_index, LPC_order ) ];\r
-            pCB_element = &pCurrentCBStage->CB_NLSF_Q15[ SKP_SMULBB( cb_index, LPC_order ) ];\r
-            pInt        = &pRes_new_Q15[ SKP_SMULBB( k, LPC_order ) ];\r
-            for( i = 0; i < LPC_order; i++ ) {\r
-                pInt[ i ] = pConstInt[ i ] - ( SKP_int )pCB_element[ i ];\r
-            }\r
-\r
-            /* Update accumulated rate for stage 1 to the current */\r
-            pRate_new_Q5[ k ] = pRate_Q5[ input_index ] + pCurrentCBStage->Rates_Q5[ cb_index ];\r
-\r
-            /* Copy paths from previous matrix, starting with the best path */\r
-            pConstInt = &pPath[ SKP_SMULBB( input_index, psNLSF_CB->nStages ) ];\r
-            pInt      = &pPath_new[ SKP_SMULBB( k, psNLSF_CB->nStages ) ];\r
-            for( i = 0; i < s; i++ ) {\r
-                pInt[ i ] = pConstInt[ i ];\r
-            }\r
-            /* Write the current stage indices for the 'cur_survivors' to the best path matrix */\r
-            pInt[ s ] = 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_int ) );\r
-\r
-            /* Copy rate vector for next stage */\r
-            SKP_memcpy( pRate_Q5, pRate_new_Q5, 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_int ) );\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_Q6[ 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_Q6[ 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_int ) );\r
-\r
-    /* Decode and stabilize the best survivor */\r
-    SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, NLSFIndices, LPC_order );\r
-\r
-#ifdef USE_UNQUANTIZED_LSFS\r
-    SKP_memcpy( pNLSF_Q15, NLSF_orig, LPC_order * sizeof( SKP_int ) );\r
-#endif\r
-\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+/***********************/
+/* NLSF vector encoder */
+/***********************/
+void SKP_Silk_NLSF_MSVQ_encode_FIX(
+          SKP_int                   *NLSFIndices,           /* O    Codebook path vector [ CB_STAGES ]      */
+          SKP_int                   *pNLSF_Q15,             /* I/O  Quantized NLSF vector [ LPC_ORDER ]     */
+    const SKP_Silk_NLSF_CB_struct   *psNLSF_CB,             /* I    Codebook object                         */
+    const SKP_int                   *pNLSF_q_Q15_prev,      /* I    Prev. quantized NLSF vector [LPC_ORDER] */
+    const SKP_int                   *pW_Q6,                 /* I    NLSF weight vector [ LPC_ORDER ]        */
+    const SKP_int                   NLSF_mu_Q15,            /* I    Rate weight for the RD optimization     */
+    const SKP_int                   NLSF_mu_fluc_red_Q16,   /* I    Fluctuation reduction error weight      */
+    const SKP_int                   NLSF_MSVQ_Survivors,    /* I    Max survivors from each stage           */
+    const SKP_int                   LPC_order,              /* I    LPC order                               */
+    const SKP_int                   deactivate_fluc_red     /* I    Deactivate fluctuation reduction        */
+)
+{
+    SKP_int     i, s, k, cur_survivors = 0, prev_survivors, min_survivors, input_index, cb_index, bestIndex;
+    SKP_int32   rateDistThreshold_Q18;
+#if( NLSF_MSVQ_FLUCTUATION_REDUCTION == 1 )
+    SKP_int32   se_Q15, wsse_Q20, bestRateDist_Q20;
+#endif
+
+#if( LOW_COMPLEXITY_ONLY == 1 )
+    SKP_int32   pRateDist_Q18[  NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED_LC_MODE ];
+    SKP_int32   pRate_Q5[       MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ];
+    SKP_int32   pRate_new_Q5[   MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ];
+    SKP_int     pTempIndices[   MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ];
+    SKP_int     pPath[          MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_CB_STAGES ];
+    SKP_int     pPath_new[      MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_CB_STAGES ];
+    SKP_int     pRes_Q15[       MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * MAX_LPC_ORDER ];
+    SKP_int     pRes_new_Q15[   MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * MAX_LPC_ORDER ];
+#else
+    SKP_int32   pRateDist_Q18[  NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED ];
+    SKP_int32   pRate_Q5[       MAX_NLSF_MSVQ_SURVIVORS ];
+    SKP_int32   pRate_new_Q5[   MAX_NLSF_MSVQ_SURVIVORS ];
+    SKP_int     pTempIndices[   MAX_NLSF_MSVQ_SURVIVORS ];
+    SKP_int     pPath[          MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ];
+    SKP_int     pPath_new[      MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ];
+    SKP_int     pRes_Q15[       MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ];
+    SKP_int     pRes_new_Q15[   MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ];
+#endif
+
+    const SKP_int   *pConstInt;
+          SKP_int   *pInt;
+    const SKP_int16 *pCB_element;
+    const SKP_Silk_NLSF_CBS *pCurrentCBStage;
+
+#ifdef USE_UNQUANTIZED_LSFS
+    SKP_int NLSF_orig[ MAX_LPC_ORDER ];
+    SKP_memcpy( NLSF_orig, pNLSF_Q15, LPC_order * sizeof( SKP_int ) );
+#endif
+
+    SKP_assert( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS );
+    SKP_assert( ( LOW_COMPLEXITY_ONLY == 0 ) || ( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ) );
+
+
+    /****************************************************/
+    /* Tree search for the multi-stage vector quantizer */
+    /****************************************************/
+
+    /* Clear accumulated rates */
+    SKP_memset( pRate_Q5, 0, NLSF_MSVQ_Survivors * sizeof( SKP_int32 ) );
+    
+    /* Copy NLSFs into residual signal vector */
+    for( i = 0; i < LPC_order; i++ ) {
+        pRes_Q15[ i ] = pNLSF_Q15[ i ];
+    }
+
+    /* Set first stage values */
+    prev_survivors = 1;
+
+    /* Minimum number of survivors */
+    min_survivors = NLSF_MSVQ_Survivors / 2;
+
+    /* Loop over all stages */
+    for( s = 0; s < psNLSF_CB->nStages; s++ ) {
+
+        /* Set a pointer to the current stage codebook */
+        pCurrentCBStage = &psNLSF_CB->CBStages[ s ];
+
+        /* Calculate the number of survivors in the current stage */
+        cur_survivors = SKP_min_32( NLSF_MSVQ_Survivors, SKP_SMULBB( prev_survivors, pCurrentCBStage->nVectors ) );
+
+#if( NLSF_MSVQ_FLUCTUATION_REDUCTION == 0 )
+        /* Find a single best survivor in the last stage, if we */
+        /* do not need candidates for fluctuation reduction     */
+        if( s == psNLSF_CB->nStages - 1 ) {
+            cur_survivors = 1;
+        }
+#endif
+
+        /* Nearest neighbor clustering for multiple input data vectors */
+        SKP_Silk_NLSF_VQ_rate_distortion_FIX( pRateDist_Q18, pCurrentCBStage, pRes_Q15, pW_Q6, 
+            pRate_Q5, NLSF_mu_Q15, prev_survivors, LPC_order );
+
+        /* Sort the rate-distortion errors */
+        SKP_Silk_insertion_sort_increasing( pRateDist_Q18, pTempIndices, 
+            prev_survivors * pCurrentCBStage->nVectors, cur_survivors );
+
+        /* Discard survivors with rate-distortion values too far above the best one */
+        if( pRateDist_Q18[ 0 ] < SKP_int32_MAX / MAX_NLSF_MSVQ_SURVIVORS ) {
+            rateDistThreshold_Q18 = SKP_SMLAWB( pRateDist_Q18[ 0 ], 
+                SKP_MUL( NLSF_MSVQ_Survivors, pRateDist_Q18[ 0 ] ), SKP_FIX_CONST( NLSF_MSVQ_SURV_MAX_REL_RD, 16 ) );
+            while( pRateDist_Q18[ cur_survivors - 1 ] > rateDistThreshold_Q18 && cur_survivors > min_survivors ) {
+                cur_survivors--;
+            }
+        }
+        /* Update accumulated codebook contributions for the 'cur_survivors' best codebook indices */
+        for( k = 0; k < cur_survivors; k++ ) { 
+            if( s > 0 ) {
+                /* Find the indices of the input and the codebook vector */
+                if( pCurrentCBStage->nVectors == 8 ) {
+                    input_index = SKP_RSHIFT( pTempIndices[ k ], 3 );
+                    cb_index    = pTempIndices[ k ] & 7;
+                } else {
+                    input_index = SKP_DIV32_16( pTempIndices[ k ], pCurrentCBStage->nVectors );  
+                    cb_index    = pTempIndices[ k ] - SKP_SMULBB( input_index, pCurrentCBStage->nVectors );
+                }
+            } else {
+                /* Find the indices of the input and the codebook vector */
+                input_index = 0;
+                cb_index    = pTempIndices[ k ];
+            }
+
+            /* Subtract new contribution from the previous residual vector for each of 'cur_survivors' */
+            pConstInt   = &pRes_Q15[ SKP_SMULBB( input_index, LPC_order ) ];
+            pCB_element = &pCurrentCBStage->CB_NLSF_Q15[ SKP_SMULBB( cb_index, LPC_order ) ];
+            pInt        = &pRes_new_Q15[ SKP_SMULBB( k, LPC_order ) ];
+            for( i = 0; i < LPC_order; i++ ) {
+                pInt[ i ] = pConstInt[ i ] - ( SKP_int )pCB_element[ i ];
+            }
+
+            /* Update accumulated rate for stage 1 to the current */
+            pRate_new_Q5[ k ] = pRate_Q5[ input_index ] + pCurrentCBStage->Rates_Q5[ cb_index ];
+
+            /* Copy paths from previous matrix, starting with the best path */
+            pConstInt = &pPath[ SKP_SMULBB( input_index, psNLSF_CB->nStages ) ];
+            pInt      = &pPath_new[ SKP_SMULBB( k, psNLSF_CB->nStages ) ];
+            for( i = 0; i < s; i++ ) {
+                pInt[ i ] = pConstInt[ i ];
+            }
+            /* Write the current stage indices for the 'cur_survivors' to the best path matrix */
+            pInt[ s ] = cb_index;
+        }
+
+        if( s < psNLSF_CB->nStages - 1 ) {
+            /* Copy NLSF residual matrix for next stage */
+            SKP_memcpy( pRes_Q15, pRes_new_Q15, SKP_SMULBB( cur_survivors, LPC_order ) * sizeof( SKP_int ) );
+
+            /* Copy rate vector for next stage */
+            SKP_memcpy( pRate_Q5, pRate_new_Q5, cur_survivors * sizeof( SKP_int32 ) );
+
+            /* Copy best path matrix for next stage */
+            SKP_memcpy( pPath, pPath_new, SKP_SMULBB( cur_survivors, psNLSF_CB->nStages ) * sizeof( SKP_int ) );
+        }
+
+        prev_survivors = cur_survivors;
+    }
+
+    /* (Preliminary) index of the best survivor, later to be decoded */
+    bestIndex = 0;
+
+#if( NLSF_MSVQ_FLUCTUATION_REDUCTION == 1 )
+    /******************************/
+    /* NLSF fluctuation reduction */
+    /******************************/
+    if( deactivate_fluc_red != 1 ) {
+    
+        /* Search among all survivors, now taking also weighted fluctuation errors into account */
+        bestRateDist_Q20 = SKP_int32_MAX;
+        for( s = 0; s < cur_survivors; s++ ) {
+            /* Decode survivor to compare with previous quantized NLSF vector */
+            SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, &pPath_new[ SKP_SMULBB( s, psNLSF_CB->nStages ) ], LPC_order );
+
+            /* Compare decoded NLSF vector with the previously quantized vector */ 
+            wsse_Q20 = 0;
+            for( i = 0; i < LPC_order; i += 2 ) {
+                /* Compute weighted squared quantization error for index i */
+                se_Q15 = pNLSF_Q15[ i ] - pNLSF_q_Q15_prev[ i ]; // range: [ -32767 : 32767 ]
+                wsse_Q20 = SKP_SMLAWB( wsse_Q20, SKP_SMULBB( se_Q15, se_Q15 ), pW_Q6[ i ] );
+
+                /* Compute weighted squared quantization error for index i + 1 */
+                se_Q15 = pNLSF_Q15[ i + 1 ] - pNLSF_q_Q15_prev[ i + 1 ]; // range: [ -32767 : 32767 ]
+                wsse_Q20 = SKP_SMLAWB( wsse_Q20, SKP_SMULBB( se_Q15, se_Q15 ), pW_Q6[ i + 1 ] );
+            }
+            SKP_assert( wsse_Q20 >= 0 );
+
+            /* Add the fluctuation reduction penalty to the rate distortion error */
+            wsse_Q20 = SKP_ADD_POS_SAT32( pRateDist_Q18[ s ], SKP_SMULWB( wsse_Q20, NLSF_mu_fluc_red_Q16 ) );
+
+            /* Keep index of best survivor */
+            if( wsse_Q20 < bestRateDist_Q20 ) {
+                bestRateDist_Q20 = wsse_Q20;
+                bestIndex = s;
+            }
+        }
+    }
+#endif
+
+    /* Copy best path to output argument */
+    SKP_memcpy( NLSFIndices, &pPath_new[ SKP_SMULBB( bestIndex, psNLSF_CB->nStages ) ], psNLSF_CB->nStages * sizeof( SKP_int ) );
+
+    /* Decode and stabilize the best survivor */
+    SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, NLSFIndices, LPC_order );
+
+#ifdef USE_UNQUANTIZED_LSFS
+    SKP_memcpy( pNLSF_Q15, NLSF_orig, LPC_order * sizeof( SKP_int ) );
+#endif
+
+}
index 6ab7bbbd008b7723e1e33fcc00e26c0114986504..c26b2da4e79fac6463048269e11f2f7ab54bad39 100644 (file)
@@ -1,61 +1,61 @@
-/***********************************************************************\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_FIX.h"\r
-\r
-/* Rate-Distortion calculations for multiple input data vectors */\r
-void SKP_Silk_NLSF_VQ_rate_distortion_FIX(\r
-    SKP_int32                       *pRD_Q20,           /* O    Rate-distortion values [psNLSF_CBS->nVectors*N] */\r
-    const SKP_Silk_NLSF_CBS         *psNLSF_CBS,        /* I    NLSF codebook stage struct                      */\r
-    const SKP_int                   *in_Q15,            /* I    Input vectors to be quantized                   */\r
-    const SKP_int                   *w_Q6,              /* I    Weight vector                                   */\r
-    const SKP_int32                 *rate_acc_Q5,       /* 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                   LPC_order           /* I    LPC order                                       */\r
-)\r
-{\r
-    SKP_int   i, n;\r
-    SKP_int32 *pRD_vec_Q20;\r
-\r
-    /* Compute weighted quantization errors for all input vectors over one codebook stage */\r
-    SKP_Silk_NLSF_VQ_sum_error_FIX( pRD_Q20, in_Q15, w_Q6, psNLSF_CBS->CB_NLSF_Q15, \r
-        N, psNLSF_CBS->nVectors, LPC_order );\r
-\r
-    /* Loop over input vectors */\r
-    pRD_vec_Q20 = pRD_Q20;\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_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ] >= 0 );\r
-            SKP_assert( rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ] <= SKP_int16_MAX );\r
-            pRD_vec_Q20[ i ] = SKP_SMLABB( pRD_vec_Q20[ i ], rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ], mu_Q15 );\r
-            SKP_assert( pRD_vec_Q20[ i ] >= 0 );\r
-        }\r
-        pRD_vec_Q20 += psNLSF_CBS->nVectors;\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+/* Rate-Distortion calculations for multiple input data vectors */
+void SKP_Silk_NLSF_VQ_rate_distortion_FIX(
+    SKP_int32                       *pRD_Q20,           /* O    Rate-distortion values [psNLSF_CBS->nVectors*N] */
+    const SKP_Silk_NLSF_CBS         *psNLSF_CBS,        /* I    NLSF codebook stage struct                      */
+    const SKP_int                   *in_Q15,            /* I    Input vectors to be quantized                   */
+    const SKP_int                   *w_Q6,              /* I    Weight vector                                   */
+    const SKP_int32                 *rate_acc_Q5,       /* I    Accumulated rates from previous stage           */
+    const SKP_int                   mu_Q15,             /* I    Weight between weighted error and rate          */
+    const SKP_int                   N,                  /* I    Number of input vectors to be quantized         */
+    const SKP_int                   LPC_order           /* I    LPC order                                       */
+)
+{
+    SKP_int   i, n;
+    SKP_int32 *pRD_vec_Q20;
+
+    /* Compute weighted quantization errors for all input vectors over one codebook stage */
+    SKP_Silk_NLSF_VQ_sum_error_FIX( pRD_Q20, in_Q15, w_Q6, psNLSF_CBS->CB_NLSF_Q15, 
+        N, psNLSF_CBS->nVectors, LPC_order );
+
+    /* Loop over input vectors */
+    pRD_vec_Q20 = pRD_Q20;
+    for( n = 0; n < N; n++ ) {
+        /* Add rate cost to error for each codebook vector */
+        for( i = 0; i < psNLSF_CBS->nVectors; i++ ) {
+            SKP_assert( rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ] >= 0 );
+            SKP_assert( rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ] <= SKP_int16_MAX );
+            pRD_vec_Q20[ i ] = SKP_SMLABB( pRD_vec_Q20[ i ], rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ], mu_Q15 );
+            SKP_assert( pRD_vec_Q20[ i ] >= 0 );
+        }
+        pRD_vec_Q20 += psNLSF_CBS->nVectors;
+    }
+}
index 0ca3eb34daf3fecb5c185776525c6256e18841f2..1aee617fdd0cf59a72cc0a2a93bf62326659af5f 100644 (file)
@@ -1,81 +1,81 @@
-/***********************************************************************\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_FIX.h"\r
-\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_FIX(\r
-    SKP_int32                       *err_Q20,           /* O    Weighted quantization errors  [N*K]         */\r
-    const SKP_int                   *in_Q15,            /* I    Input vectors to be quantized [N*LPC_order] */\r
-    const SKP_int                   *w_Q6,              /* I    Weighting vectors             [N*LPC_order] */\r
-    const SKP_int16                 *pCB_Q15,           /* 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                   LPC_order           /* I    Number of LPCs                              */\r
-)\r
-{\r
-    SKP_int         i, n, m;\r
-    SKP_int32       diff_Q15, sum_error, Wtmp_Q6;\r
-    SKP_int32       Wcpy_Q6[ MAX_LPC_ORDER / 2 ];\r
-    const SKP_int16 *cb_vec_Q15;\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_Q6[ m ] = w_Q6[ 2 * m ] | SKP_LSHIFT( ( SKP_int32 )w_Q6[ 2 * m + 1 ], 16 );\r
-    }\r
-\r
-    /* Loop over input vectors */\r
-    for( n = 0; n < N; n++ ) {\r
-        /* Loop over codebook */\r
-        cb_vec_Q15 = pCB_Q15;\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_Q6 = Wcpy_Q6[ SKP_RSHIFT( m, 1 ) ];\r
-\r
-                /* Compute weighted squared quantization error for index m */\r
-                diff_Q15 = in_Q15[ m ] - *cb_vec_Q15++; // range: [ -32767 : 32767 ]\r
-                sum_error = SKP_SMLAWB( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q6 );\r
-\r
-                /* Compute weighted squared quantization error for index m + 1 */\r
-                diff_Q15 = in_Q15[m + 1] - *cb_vec_Q15++; // range: [ -32767 : 32767 ]\r
-                sum_error = SKP_SMLAWT( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q6 );\r
-            }\r
-            SKP_assert( sum_error >= 0 );\r
-            err_Q20[ i ] = sum_error;\r
-        }\r
-        err_Q20 += K;\r
-        in_Q15 += LPC_order;\r
-    }\r
-}\r
-\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+
+/* Compute weighted quantization errors for an LPC_order element input vector, over one codebook stage */
+void SKP_Silk_NLSF_VQ_sum_error_FIX(
+    SKP_int32                       *err_Q20,           /* O    Weighted quantization errors  [N*K]         */
+    const SKP_int                   *in_Q15,            /* I    Input vectors to be quantized [N*LPC_order] */
+    const SKP_int                   *w_Q6,              /* I    Weighting vectors             [N*LPC_order] */
+    const SKP_int16                 *pCB_Q15,           /* I    Codebook vectors              [K*LPC_order] */
+    const SKP_int                   N,                  /* I    Number of input vectors                     */
+    const SKP_int                   K,                  /* I    Number of codebook vectors                  */
+    const SKP_int                   LPC_order           /* I    Number of LPCs                              */
+)
+{
+    SKP_int         i, n, m;
+    SKP_int32       diff_Q15, sum_error, Wtmp_Q6;
+    SKP_int32       Wcpy_Q6[ MAX_LPC_ORDER / 2 ];
+    const SKP_int16 *cb_vec_Q15;
+
+    SKP_assert( LPC_order <= 16 );
+    SKP_assert( ( LPC_order & 1 ) == 0 );
+
+    /* Copy to local stack and pack two weights per int32 */
+    for( m = 0; m < SKP_RSHIFT( LPC_order, 1 ); m++ ) {
+        Wcpy_Q6[ m ] = w_Q6[ 2 * m ] | SKP_LSHIFT( ( SKP_int32 )w_Q6[ 2 * m + 1 ], 16 );
+    }
+
+    /* Loop over input vectors */
+    for( n = 0; n < N; n++ ) {
+        /* Loop over codebook */
+        cb_vec_Q15 = pCB_Q15;
+        for( i = 0; i < K; i++ ) {
+            sum_error = 0;
+            for( m = 0; m < LPC_order; m += 2 ) {
+                /* Get two weights packed in an int32 */
+                Wtmp_Q6 = Wcpy_Q6[ SKP_RSHIFT( m, 1 ) ];
+
+                /* Compute weighted squared quantization error for index m */
+                diff_Q15 = in_Q15[ m ] - *cb_vec_Q15++; // range: [ -32767 : 32767 ]
+                sum_error = SKP_SMLAWB( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q6 );
+
+                /* Compute weighted squared quantization error for index m + 1 */
+                diff_Q15 = in_Q15[m + 1] - *cb_vec_Q15++; // range: [ -32767 : 32767 ]
+                sum_error = SKP_SMLAWT( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q6 );
+            }
+            SKP_assert( sum_error >= 0 );
+            err_Q20[ i ] = sum_error;
+        }
+        err_Q20 += K;
+        in_Q15 += LPC_order;
+    }
+}
+
+
index b6e44bc84884ffb33292d19bfd5ed1fb74e30017..e306d5615a41649c9ec62c55322a86ab505e7c22 100644 (file)
@@ -1,79 +1,79 @@
-/***********************************************************************\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_SigProc_FIX.h"\r
-\r
-/* \r
-R. Laroia, N. Phamdo and N. Farvardin, "Robust and Efficient Quantization of Speech LSP\r
-Parameters Using Structured Vector Quantization", Proc. IEEE Int. Conf. Acoust., Speech,\r
-Signal Processing, pp. 641-644, 1991.\r
-*/\r
-\r
-#define Q_OUT                       6\r
-#define MIN_NDELTA                  3\r
-\r
-/* Laroia low complexity NLSF weights */\r
-void SKP_Silk_NLSF_VQ_weights_laroia(\r
-    SKP_int             *pNLSFW_Q6,         /* O: Pointer to input vector weights           [D x 1]     */\r
-    const SKP_int       *pNLSF_Q15,         /* I: Pointer to input vector                   [D x 1]     */ \r
-    const SKP_int       D                   /* I: Input vector dimension (even)                         */\r
-)\r
-{\r
-    SKP_int   k;\r
-    SKP_int32 tmp1_int, tmp2_int;\r
-    \r
-    /* Check that we are guaranteed to end up within the required range */\r
-    SKP_assert( D > 0 );\r
-    SKP_assert( ( D & 1 ) == 0 );\r
-    \r
-    /* First value */\r
-    tmp1_int = SKP_max_int( pNLSF_Q15[ 0 ], MIN_NDELTA );\r
-    tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );\r
-    tmp2_int = SKP_max_int( pNLSF_Q15[ 1 ] - pNLSF_Q15[ 0 ], MIN_NDELTA );\r
-    tmp2_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp2_int );\r
-    pNLSFW_Q6[ 0 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );\r
-    SKP_assert( pNLSFW_Q6[ 0 ] > 0 );\r
-    \r
-    /* Main loop */\r
-    for( k = 1; k < D - 1; k += 2 ) {\r
-        tmp1_int = SKP_max_int( pNLSF_Q15[ k + 1 ] - pNLSF_Q15[ k ], MIN_NDELTA );\r
-        tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );\r
-        pNLSFW_Q6[ k ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );\r
-        SKP_assert( pNLSFW_Q6[ k ] > 0 );\r
-\r
-        tmp2_int = SKP_max_int( pNLSF_Q15[ k + 2 ] - pNLSF_Q15[ k + 1 ], MIN_NDELTA );\r
-        tmp2_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp2_int );\r
-        pNLSFW_Q6[ k + 1 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );\r
-        SKP_assert( pNLSFW_Q6[ k + 1 ] > 0 );\r
-    }\r
-    \r
-    /* Last value */\r
-    tmp1_int = SKP_max_int( ( 1 << 15 ) - pNLSF_Q15[ D - 1 ], MIN_NDELTA );\r
-    tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );\r
-    pNLSFW_Q6[ D - 1 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );\r
-    SKP_assert( pNLSFW_Q6[ D - 1 ] > 0 );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* 
+R. Laroia, N. Phamdo and N. Farvardin, "Robust and Efficient Quantization of Speech LSP
+Parameters Using Structured Vector Quantization", Proc. IEEE Int. Conf. Acoust., Speech,
+Signal Processing, pp. 641-644, 1991.
+*/
+
+#define Q_OUT                       6
+#define MIN_NDELTA                  3
+
+/* Laroia low complexity NLSF weights */
+void SKP_Silk_NLSF_VQ_weights_laroia(
+    SKP_int             *pNLSFW_Q6,         /* O: Pointer to input vector weights           [D x 1]     */
+    const SKP_int       *pNLSF_Q15,         /* I: Pointer to input vector                   [D x 1]     */ 
+    const SKP_int       D                   /* I: Input vector dimension (even)                         */
+)
+{
+    SKP_int   k;
+    SKP_int32 tmp1_int, tmp2_int;
+    
+    /* Check that we are guaranteed to end up within the required range */
+    SKP_assert( D > 0 );
+    SKP_assert( ( D & 1 ) == 0 );
+    
+    /* First value */
+    tmp1_int = SKP_max_int( pNLSF_Q15[ 0 ], MIN_NDELTA );
+    tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );
+    tmp2_int = SKP_max_int( pNLSF_Q15[ 1 ] - pNLSF_Q15[ 0 ], MIN_NDELTA );
+    tmp2_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp2_int );
+    pNLSFW_Q6[ 0 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
+    SKP_assert( pNLSFW_Q6[ 0 ] > 0 );
+    
+    /* Main loop */
+    for( k = 1; k < D - 1; k += 2 ) {
+        tmp1_int = SKP_max_int( pNLSF_Q15[ k + 1 ] - pNLSF_Q15[ k ], MIN_NDELTA );
+        tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );
+        pNLSFW_Q6[ k ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
+        SKP_assert( pNLSFW_Q6[ k ] > 0 );
+
+        tmp2_int = SKP_max_int( pNLSF_Q15[ k + 2 ] - pNLSF_Q15[ k + 1 ], MIN_NDELTA );
+        tmp2_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp2_int );
+        pNLSFW_Q6[ k + 1 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
+        SKP_assert( pNLSFW_Q6[ k + 1 ] > 0 );
+    }
+    
+    /* Last value */
+    tmp1_int = SKP_max_int( ( 1 << 15 ) - pNLSF_Q15[ D - 1 ], MIN_NDELTA );
+    tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );
+    pNLSFW_Q6[ D - 1 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
+    SKP_assert( pNLSFW_Q6[ D - 1 ] > 0 );
+}
index f13eb0021d8ab212f7354e6bdb43f485c6260c45..10dc9c9864f4884b121d38142b70215f987326c8 100644 (file)
-/***********************************************************************\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
-/* NLSF stabilizer:                                         */\r
-/*                                                          */\r
-/* - Moves NLSFs futher apart if they are too close         */\r
-/* - Moves NLSFs away from borders if they are too close    */\r
-/* - High effort to achieve a modification with minimum     */\r
-/*     Euclidean distance to input vector                   */\r
-/* - Output are sorted NLSF coefficients                    */\r
-/*                                                          */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Constant Definitions */\r
-#define MAX_LOOPS        20\r
-\r
-/* NLSF stabilizer, for a single input data vector */\r
-void SKP_Silk_NLSF_stabilize(\r
-          SKP_int    *NLSF_Q15,            /* I/O:  Unstable/stabilized normalized LSF vector in Q15 [L]                    */\r
-    const SKP_int    *NDeltaMin_Q15,       /* I:    Normalized delta min vector in Q15, NDeltaMin_Q15[L] must be >= 1 [L+1] */\r
-    const SKP_int     L                    /* I:    Number of NLSF parameters in the input vector                           */\r
-)\r
-{\r
-    SKP_int        center_freq_Q15, diff_Q15, min_center_Q15, max_center_Q15;\r
-    SKP_int32    min_diff_Q15;\r
-    SKP_int        loops;\r
-    SKP_int        i, I=0, k;\r
-\r
-    /* This is necessary to ensure an output within range of a SKP_int16 */\r
-    SKP_assert( NDeltaMin_Q15[L] >= 1 );\r
-\r
-    for( loops = 0; loops < MAX_LOOPS; loops++ ) {\r
-        /**************************/\r
-        /* Find smallest distance */\r
-        /**************************/\r
-        /* First element */\r
-        min_diff_Q15 = NLSF_Q15[0] - NDeltaMin_Q15[0];\r
-        I = 0;\r
-        /* Middle elements */\r
-        for( i = 1; i <= L-1; i++ ) {\r
-            diff_Q15 = NLSF_Q15[i] - ( NLSF_Q15[i-1] + NDeltaMin_Q15[i] );\r
-            if( diff_Q15 < min_diff_Q15 ) {\r
-                min_diff_Q15 = diff_Q15;\r
-                I = i;\r
-            }\r
-        }\r
-        /* Last element */\r
-        diff_Q15 = (1<<15) - ( NLSF_Q15[L-1] + NDeltaMin_Q15[L] );\r
-        if( diff_Q15 < min_diff_Q15 ) {\r
-            min_diff_Q15 = diff_Q15;\r
-            I = L;\r
-        }\r
-\r
-        /***************************************************/\r
-        /* Now check if the smallest distance non-negative */\r
-        /***************************************************/\r
-        if (min_diff_Q15 >= 0) {\r
-            return;\r
-        }\r
-\r
-        if( I == 0 ) {\r
-            /* Move away from lower limit */\r
-            NLSF_Q15[0] = NDeltaMin_Q15[0];\r
-        \r
-        } else if( I == L) {\r
-            /* Move away from higher limit */\r
-            NLSF_Q15[L-1] = (1<<15) - NDeltaMin_Q15[L];\r
-        \r
-        } else {\r
-            /* Find the lower extreme for the location of the current center frequency */ \r
-            min_center_Q15 = 0;\r
-            for( k = 0; k < I; k++ ) {\r
-                min_center_Q15 += NDeltaMin_Q15[k];\r
-            }\r
-            min_center_Q15 += SKP_RSHIFT( NDeltaMin_Q15[I], 1 );\r
-\r
-            /* Find the upper extreme for the location of the current center frequency */\r
-            max_center_Q15 = (1<<15);\r
-            for( k = L; k > I; k-- ) {\r
-                max_center_Q15 -= NDeltaMin_Q15[k];\r
-            }\r
-            max_center_Q15 -= ( NDeltaMin_Q15[I] - SKP_RSHIFT( NDeltaMin_Q15[I], 1 ) );\r
-\r
-            /* Move apart, sorted by value, keeping the same center frequency */\r
-            center_freq_Q15 = SKP_LIMIT_32( SKP_RSHIFT_ROUND( (SKP_int32)NLSF_Q15[I-1] + (SKP_int32)NLSF_Q15[I], 1 ),\r
-                min_center_Q15, max_center_Q15 );\r
-            NLSF_Q15[I-1] = center_freq_Q15 - SKP_RSHIFT( NDeltaMin_Q15[I], 1 );\r
-            NLSF_Q15[I] = NLSF_Q15[I-1] + NDeltaMin_Q15[I];\r
-        }\r
-    }\r
-\r
-    /* Safe and simple fall back method, which is less ideal than the above */\r
-    if( loops == MAX_LOOPS )\r
-    {\r
-        /* Insertion sort (fast for already almost sorted arrays):   */\r
-        /* Best case:  O(n)   for an already sorted array            */\r
-        /* Worst case: O(n^2) for an inversely sorted array          */\r
-        SKP_Silk_insertion_sort_increasing_all_values(&NLSF_Q15[0], L);\r
-            \r
-        /* First NLSF should be no less than NDeltaMin[0] */\r
-        NLSF_Q15[0] = SKP_max_int( NLSF_Q15[0], NDeltaMin_Q15[0] );\r
-        \r
-        /* Keep delta_min distance between the NLSFs */\r
-        for( i = 1; i < L; i++ )\r
-            NLSF_Q15[i] = SKP_max_int( NLSF_Q15[i], NLSF_Q15[i-1] + NDeltaMin_Q15[i] );\r
-\r
-        /* Last NLSF should be no higher than 1 - NDeltaMin[L] */\r
-        NLSF_Q15[L-1] = SKP_min_int( NLSF_Q15[L-1], (1<<15) - NDeltaMin_Q15[L] );\r
-\r
-        /* Keep NDeltaMin distance between the NLSFs */\r
-        for( i = L-2; i >= 0; i-- ) \r
-            NLSF_Q15[i] = SKP_min_int( NLSF_Q15[i], NLSF_Q15[i+1] - NDeltaMin_Q15[i+1] );\r
-    }\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/* NLSF stabilizer:                                         */
+/*                                                          */
+/* - Moves NLSFs futher apart if they are too close         */
+/* - Moves NLSFs away from borders if they are too close    */
+/* - High effort to achieve a modification with minimum     */
+/*     Euclidean distance to input vector                   */
+/* - Output are sorted NLSF coefficients                    */
+/*                                                          */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Constant Definitions */
+#define MAX_LOOPS        20
+
+/* NLSF stabilizer, for a single input data vector */
+void SKP_Silk_NLSF_stabilize(
+          SKP_int    *NLSF_Q15,            /* I/O:  Unstable/stabilized normalized LSF vector in Q15 [L]                    */
+    const SKP_int    *NDeltaMin_Q15,       /* I:    Normalized delta min vector in Q15, NDeltaMin_Q15[L] must be >= 1 [L+1] */
+    const SKP_int     L                    /* I:    Number of NLSF parameters in the input vector                           */
+)
+{
+    SKP_int        center_freq_Q15, diff_Q15, min_center_Q15, max_center_Q15;
+    SKP_int32    min_diff_Q15;
+    SKP_int        loops;
+    SKP_int        i, I=0, k;
+
+    /* This is necessary to ensure an output within range of a SKP_int16 */
+    SKP_assert( NDeltaMin_Q15[L] >= 1 );
+
+    for( loops = 0; loops < MAX_LOOPS; loops++ ) {
+        /**************************/
+        /* Find smallest distance */
+        /**************************/
+        /* First element */
+        min_diff_Q15 = NLSF_Q15[0] - NDeltaMin_Q15[0];
+        I = 0;
+        /* Middle elements */
+        for( i = 1; i <= L-1; i++ ) {
+            diff_Q15 = NLSF_Q15[i] - ( NLSF_Q15[i-1] + NDeltaMin_Q15[i] );
+            if( diff_Q15 < min_diff_Q15 ) {
+                min_diff_Q15 = diff_Q15;
+                I = i;
+            }
+        }
+        /* Last element */
+        diff_Q15 = (1<<15) - ( NLSF_Q15[L-1] + NDeltaMin_Q15[L] );
+        if( diff_Q15 < min_diff_Q15 ) {
+            min_diff_Q15 = diff_Q15;
+            I = L;
+        }
+
+        /***************************************************/
+        /* Now check if the smallest distance non-negative */
+        /***************************************************/
+        if (min_diff_Q15 >= 0) {
+            return;
+        }
+
+        if( I == 0 ) {
+            /* Move away from lower limit */
+            NLSF_Q15[0] = NDeltaMin_Q15[0];
+        
+        } else if( I == L) {
+            /* Move away from higher limit */
+            NLSF_Q15[L-1] = (1<<15) - NDeltaMin_Q15[L];
+        
+        } else {
+            /* Find the lower extreme for the location of the current center frequency */ 
+            min_center_Q15 = 0;
+            for( k = 0; k < I; k++ ) {
+                min_center_Q15 += NDeltaMin_Q15[k];
+            }
+            min_center_Q15 += SKP_RSHIFT( NDeltaMin_Q15[I], 1 );
+
+            /* Find the upper extreme for the location of the current center frequency */
+            max_center_Q15 = (1<<15);
+            for( k = L; k > I; k-- ) {
+                max_center_Q15 -= NDeltaMin_Q15[k];
+            }
+            max_center_Q15 -= ( NDeltaMin_Q15[I] - SKP_RSHIFT( NDeltaMin_Q15[I], 1 ) );
+
+            /* Move apart, sorted by value, keeping the same center frequency */
+            center_freq_Q15 = SKP_LIMIT_32( SKP_RSHIFT_ROUND( (SKP_int32)NLSF_Q15[I-1] + (SKP_int32)NLSF_Q15[I], 1 ),
+                min_center_Q15, max_center_Q15 );
+            NLSF_Q15[I-1] = center_freq_Q15 - SKP_RSHIFT( NDeltaMin_Q15[I], 1 );
+            NLSF_Q15[I] = NLSF_Q15[I-1] + NDeltaMin_Q15[I];
+        }
+    }
+
+    /* Safe and simple fall back method, which is less ideal than the above */
+    if( loops == MAX_LOOPS )
+    {
+        /* Insertion sort (fast for already almost sorted arrays):   */
+        /* Best case:  O(n)   for an already sorted array            */
+        /* Worst case: O(n^2) for an inversely sorted array          */
+        SKP_Silk_insertion_sort_increasing_all_values(&NLSF_Q15[0], L);
+            
+        /* First NLSF should be no less than NDeltaMin[0] */
+        NLSF_Q15[0] = SKP_max_int( NLSF_Q15[0], NDeltaMin_Q15[0] );
+        
+        /* Keep delta_min distance between the NLSFs */
+        for( i = 1; i < L; i++ )
+            NLSF_Q15[i] = SKP_max_int( NLSF_Q15[i], NLSF_Q15[i-1] + NDeltaMin_Q15[i] );
+
+        /* Last NLSF should be no higher than 1 - NDeltaMin[L] */
+        NLSF_Q15[L-1] = SKP_min_int( NLSF_Q15[L-1], (1<<15) - NDeltaMin_Q15[L] );
+
+        /* Keep NDeltaMin distance between the NLSFs */
+        for( i = L-2; i >= 0; i-- ) 
+            NLSF_Q15[i] = SKP_min_int( NLSF_Q15[i], NLSF_Q15[i+1] - NDeltaMin_Q15[i+1] );
+    }
+}
+
index 939a9af968f8668677affc2366bafe290d0e0938..316de1a9fd484582047fec9dbc3f2dd27a2a433a 100644 (file)
-/***********************************************************************\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
-SKP_INLINE void SKP_Silk_nsq_scale_states(\r
-    SKP_Silk_nsq_state  *NSQ,               /* I/O NSQ state                        */\r
-    const SKP_int16     x[],                /* I input in Q0                        */\r
-    SKP_int32           x_sc_Q10[],         /* O input scaled with 1/Gain           */\r
-    SKP_int             subfr_length,       /* I length of input                    */\r
-    const SKP_int16     sLTP[],             /* I re-whitened LTP state in Q0        */\r
-    SKP_int32           sLTP_Q16[],         /* O LTP state matching scaled input    */\r
-    SKP_int             subfr,              /* I subframe number                    */\r
-    const SKP_int       LTP_scale_Q14,      /* I                                    */\r
-    const SKP_int32     Gains_Q16[ NB_SUBFR ], /* I                                 */\r
-    const SKP_int       pitchL[ NB_SUBFR ]  /* I                                    */\r
-);\r
-\r
-SKP_INLINE void SKP_Silk_noise_shape_quantizer(\r
-    SKP_Silk_nsq_state  *NSQ,               /* I/O  NSQ state                       */\r
-    SKP_int             sigtype,            /* I    Signal type                     */\r
-    const SKP_int32     x_sc_Q10[],         /* I                                    */\r
-    SKP_int8            q[],                /* O                                    */\r
-    SKP_int16           xq[],               /* O                                    */\r
-    SKP_int32           sLTP_Q16[],         /* I/O  LTP state                       */\r
-    const SKP_int16     a_Q12[],            /* I    Short term prediction coefs     */\r
-    const SKP_int16     b_Q14[],            /* I    Long term prediction coefs      */\r
-    const SKP_int16     AR_shp_Q13[],       /* I    Noise shaping AR coefs          */\r
-    SKP_int             lag,                /* I    Pitch lag                       */\r
-    SKP_int32           HarmShapeFIRPacked_Q14, /* I                                */\r
-    SKP_int             Tilt_Q14,           /* I    Spectral tilt                   */\r
-    SKP_int32           LF_shp_Q14,         /* I                                    */\r
-    SKP_int32           Gain_Q16,           /* I                                    */\r
-    SKP_int             Lambda_Q10,         /* I                                    */\r
-    SKP_int             offset_Q10,         /* I                                    */\r
-    SKP_int             length,             /* I    Input length                    */\r
-    SKP_int             shapingLPCOrder,    /* I    Noise shaping AR filter order   */\r
-    SKP_int             predictLPCOrder     /* I    Prediction filter order         */\r
-);\r
-\r
-void SKP_Silk_NSQ(\r
-    SKP_Silk_encoder_state          *psEncC,                                    /* I/O  Encoder State                       */\r
-    SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */\r
-    SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */\r
-    const SKP_int16                 x[],                                        /* I    prefiltered input signal            */\r
-    SKP_int8                        q[],                                        /* O    quantized qulse signal              */\r
-    const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */\r
-    const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Short term prediction coefficients  */\r
-    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    Long term prediction coefficients   */\r
-    const SKP_int16                 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ],  /* I                                        */\r
-    const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */\r
-    const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */\r
-    const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */\r
-    const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */\r
-    const SKP_int                   Lambda_Q10,                                 /* I                                        */\r
-    const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */\r
-)\r
-{\r
-    SKP_int     k, lag, start_idx, subfr_length, LSF_interpolation_flag;\r
-    const SKP_int16 *A_Q12, *B_Q14, *AR_shp_Q13;\r
-    SKP_int16   *pxq;\r
-    SKP_int32   sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];\r
-    SKP_int16   sLTP[     2 * MAX_FRAME_LENGTH ];\r
-    SKP_int32   HarmShapeFIRPacked_Q14;\r
-    SKP_int     offset_Q10;\r
-    SKP_int32   FiltState[ MAX_LPC_ORDER ];\r
-    SKP_int32   x_sc_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ];\r
-\r
-    subfr_length = psEncC->frame_length / NB_SUBFR;\r
-\r
-    NSQ->rand_seed  =  psEncCtrlC->Seed;\r
-    /* Set unvoiced lag to the previous one, overwrite later for voiced */\r
-    lag             = NSQ->lagPrev;\r
-\r
-    SKP_assert( NSQ->prev_inv_gain_Q16 != 0 );\r
-\r
-    offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrlC->sigtype ][ psEncCtrlC->QuantOffsetType ];\r
-\r
-    if( LSFInterpFactor_Q2 == ( 1 << 2 ) ) {\r
-        LSF_interpolation_flag = 0;\r
-    } else {\r
-        LSF_interpolation_flag = 1;\r
-    }\r
-\r
-    /* Setup pointers to start of sub frame */\r
-    NSQ->sLTP_shp_buf_idx = psEncC->frame_length;\r
-    NSQ->sLTP_buf_idx     = psEncC->frame_length;\r
-    pxq                   = &NSQ->xq[ psEncC->frame_length ];\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        A_Q12      = &PredCoef_Q12[ (( k >> 1 ) | ( 1 - LSF_interpolation_flag )) * MAX_LPC_ORDER ];\r
-        B_Q14      = &LTPCoef_Q14[ k * LTP_ORDER ];\r
-        AR_shp_Q13 = &AR2_Q13[     k * MAX_SHAPE_LPC_ORDER ];\r
-\r
-        /* Noise shape parameters */\r
-        SKP_assert( HarmShapeGain_Q14[ k ] >= 0 );\r
-        HarmShapeFIRPacked_Q14  =                          SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 );\r
-        HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 );\r
-\r
-        NSQ->rewhite_flag = 0;\r
-        if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {\r
-            /* Voiced */\r
-            lag = psEncCtrlC->pitchL[ k ];\r
-\r
-            /* Re-whitening */\r
-            if( ( k & ( 3 - SKP_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) {\r
-\r
-                /* Rewhiten with new A coefs */\r
-                start_idx = psEncC->frame_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2;\r
-                SKP_assert( start_idx >= 0 );\r
-                SKP_assert( start_idx <= psEncC->frame_length - psEncC->predictLPCOrder );\r
-\r
-                SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) );\r
-                SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * ( psEncC->frame_length >> 2 ) ], \r
-                    A_Q12, FiltState, sLTP + start_idx, psEncC->frame_length - start_idx, psEncC->predictLPCOrder );\r
-\r
-                NSQ->rewhite_flag = 1;\r
-                NSQ->sLTP_buf_idx = psEncC->frame_length;\r
-            }\r
-        }\r
-        \r
-        SKP_Silk_nsq_scale_states( NSQ, x, x_sc_Q10, psEncC->subfr_length, sLTP, \r
-            sLTP_Q16, k, LTP_scale_Q14, Gains_Q16, psEncCtrlC->pitchL );\r
-\r
-        SKP_Silk_noise_shape_quantizer( NSQ, psEncCtrlC->sigtype, x_sc_Q10, q, pxq, sLTP_Q16, A_Q12, B_Q14, \r
-            AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], Lambda_Q10, \r
-            offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder\r
-        );\r
-\r
-        x          += psEncC->subfr_length;\r
-        q          += psEncC->subfr_length;\r
-        pxq        += psEncC->subfr_length;\r
-    }\r
-\r
-    /* Update lagPrev for next frame */\r
-    NSQ->lagPrev = psEncCtrlC->pitchL[ NB_SUBFR - 1 ];\r
-\r
-    /* Save quantized speech and noise shaping signals */\r
-    SKP_memcpy( NSQ->xq,           &NSQ->xq[           psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) );\r
-    SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) );\r
-\r
-#ifdef USE_UNQUANTIZED_LSFS\r
-    DEBUG_STORE_DATA( xq_unq_lsfs.pcm, NSQ->xq, psEncC->frame_length * sizeof( SKP_int16 ) );\r
-#endif\r
-\r
-}\r
-\r
-/***********************************/\r
-/* SKP_Silk_noise_shape_quantizer  */\r
-/***********************************/\r
-SKP_INLINE void SKP_Silk_noise_shape_quantizer(\r
-    SKP_Silk_nsq_state  *NSQ,               /* I/O  NSQ state                       */\r
-    SKP_int             sigtype,            /* I    Signal type                     */\r
-    const SKP_int32     x_sc_Q10[],         /* I                                    */\r
-    SKP_int8            q[],                /* O                                    */\r
-    SKP_int16           xq[],               /* O                                    */\r
-    SKP_int32           sLTP_Q16[],         /* I/O  LTP state                       */\r
-    const SKP_int16     a_Q12[],            /* I    Short term prediction coefs     */\r
-    const SKP_int16     b_Q14[],            /* I    Long term prediction coefs      */\r
-    const SKP_int16     AR_shp_Q13[],       /* I    Noise shaping AR coefs          */\r
-    SKP_int             lag,                /* I    Pitch lag                       */\r
-    SKP_int32           HarmShapeFIRPacked_Q14, /* I                                */\r
-    SKP_int             Tilt_Q14,           /* I    Spectral tilt                   */\r
-    SKP_int32           LF_shp_Q14,         /* I                                    */\r
-    SKP_int32           Gain_Q16,           /* I                                    */\r
-    SKP_int             Lambda_Q10,         /* I                                    */\r
-    SKP_int             offset_Q10,         /* I                                    */\r
-    SKP_int             length,             /* I    Input length                    */\r
-    SKP_int             shapingLPCOrder,    /* I    Noise shaping AR filter order   */\r
-    SKP_int             predictLPCOrder     /* I    Prediction filter order         */\r
-)\r
-{\r
-    SKP_int     i, j;\r
-    SKP_int32   LTP_pred_Q14, LPC_pred_Q10, n_AR_Q10, n_LTP_Q14;\r
-    SKP_int32   n_LF_Q10, r_Q10, q_Q0, q_Q10;\r
-    SKP_int32   thr1_Q10, thr2_Q10, thr3_Q10;\r
-    SKP_int32   dither, exc_Q10, LPC_exc_Q10, xq_Q10;\r
-    SKP_int32   tmp1, tmp2, sLF_AR_shp_Q10;\r
-    SKP_int32   *psLPC_Q14, *shp_lag_ptr, *pred_lag_ptr;\r
-\r
-    shp_lag_ptr  = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ];\r
-    pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ];\r
-    \r
-    /* Setup short term AR state */\r
-    psLPC_Q14 = &NSQ->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 ];\r
-\r
-    /* Quantization thresholds */\r
-    thr1_Q10 = SKP_SUB_RSHIFT32( -1536, Lambda_Q10, 1 );\r
-    thr2_Q10 = SKP_SUB_RSHIFT32(  -512, Lambda_Q10, 1 );\r
-    thr2_Q10 = SKP_ADD_RSHIFT32( thr2_Q10, SKP_SMULBB( offset_Q10, Lambda_Q10 ), 10 );\r
-    thr3_Q10 = SKP_ADD_RSHIFT32(   512, Lambda_Q10, 1 );\r
-\r
-    for( i = 0; i < length; i++ ) {\r
-        /* Generate dither */\r
-        NSQ->rand_seed = SKP_RAND( NSQ->rand_seed );\r
-\r
-        /* dither = rand_seed < 0 ? 0xFFFFFFFF : 0; */\r
-        dither = SKP_RSHIFT( NSQ->rand_seed, 31 );\r
-                \r
-        /* Short-term prediction */\r
-        SKP_assert( ( predictLPCOrder  & 1 ) == 0 );    /* check that order is even */\r
-        /* check that array starts at 4-byte aligned address */\r
-        SKP_assert( ( ( SKP_int64 )( ( SKP_int8* )a_Q12 - ( SKP_int8* )0 ) & 3 ) == 0 );\r
-        SKP_assert( predictLPCOrder >= 10 );            /* check that unrolling works */\r
-        /* Partially unrolled */\r
-        LPC_pred_Q10 = SKP_SMULWB(               psLPC_Q14[  0 ], a_Q12[ 0 ] );\r
-        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -1 ], a_Q12[ 1 ] );\r
-        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], a_Q12[ 2 ] );\r
-        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -3 ], a_Q12[ 3 ] );\r
-        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], a_Q12[ 4 ] );\r
-        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -5 ], a_Q12[ 5 ] );\r
-        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], a_Q12[ 6 ] );\r
-        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -7 ], a_Q12[ 7 ] );\r
-        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], a_Q12[ 8 ] );\r
-        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -9 ], a_Q12[ 9 ] );\r
-        for( j = 10; j < predictLPCOrder; j ++ ) {\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], a_Q12[ j ] );\r
-        }\r
-        /* Long-term prediction */\r
-        if( sigtype == SIG_TYPE_VOICED ) {\r
-            /* Unrolled loop */\r
-            LTP_pred_Q14 = SKP_SMULWB(               pred_lag_ptr[  0 ], b_Q14[ 0 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], b_Q14[ 1 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], b_Q14[ 2 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], b_Q14[ 3 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], b_Q14[ 4 ] );\r
-            pred_lag_ptr++;\r
-        } else {\r
-            LTP_pred_Q14 = 0;\r
-        }\r
-\r
-        /* Noise shape feedback */\r
-        SKP_assert( ( shapingLPCOrder & 1 ) == 0 );   /* check that order is even */\r
-        tmp2 = psLPC_Q14[ 0 ];\r
-        tmp1 = NSQ->sAR2_Q14[ 0 ];\r
-        NSQ->sAR2_Q14[ 0 ] = tmp2;\r
-        n_AR_Q10 = SKP_SMULWB( tmp2, AR_shp_Q13[ 0 ] );\r
-        for( j = 2; j < shapingLPCOrder; j += 2 ) {\r
-            tmp2 = NSQ->sAR2_Q14[ j - 1 ];\r
-            NSQ->sAR2_Q14[ j - 1 ] = tmp1;\r
-            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ j - 1 ] );\r
-            tmp1 = NSQ->sAR2_Q14[ j + 0 ];\r
-            NSQ->sAR2_Q14[ j + 0 ] = tmp2;\r
-            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp2, AR_shp_Q13[ j ] );\r
-        }\r
-        NSQ->sAR2_Q14[ shapingLPCOrder - 1 ] = tmp1;\r
-        n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ shapingLPCOrder - 1 ] );\r
-\r
-        n_AR_Q10 = SKP_RSHIFT( n_AR_Q10, 1 );   /* Q11 -> Q10 */\r
-        n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, NSQ->sLF_AR_shp_Q12, Tilt_Q14 );\r
-\r
-        n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - 1 ], LF_shp_Q14 ), 2 ); \r
-        n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, NSQ->sLF_AR_shp_Q12, LF_shp_Q14 );\r
-\r
-        SKP_assert( lag > 0 || sigtype == SIG_TYPE_UNVOICED );\r
-\r
-        /* Long-term shaping */\r
-        if( lag > 0 ) {\r
-            /* Symmetric, packed FIR coefficients */\r
-            n_LTP_Q14 = SKP_SMULWB( SKP_ADD32( shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ] ), HarmShapeFIRPacked_Q14 );\r
-            n_LTP_Q14 = SKP_SMLAWT( n_LTP_Q14, shp_lag_ptr[ -1 ],                     HarmShapeFIRPacked_Q14 );\r
-            n_LTP_Q14 = SKP_LSHIFT( n_LTP_Q14, 6 );\r
-            shp_lag_ptr++;\r
-        } else {\r
-            n_LTP_Q14 = 0;\r
-        }\r
-\r
-        /* Input minus prediction plus noise feedback  */\r
-        //r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP;\r
-        tmp1  = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 );                       /* Add Q14 stuff */\r
-        tmp1  = SKP_RSHIFT( tmp1, 4 );                                      /* convert to Q10  */\r
-        tmp1  = SKP_ADD32( tmp1, LPC_pred_Q10 );                            /* add Q10 stuff */ \r
-        tmp1  = SKP_SUB32( tmp1, n_AR_Q10 );                                /* subtract Q10 stuff */ \r
-        tmp1  = SKP_SUB32( tmp1, n_LF_Q10 );                                /* subtract Q10 stuff */ \r
-        r_Q10 = SKP_SUB32( x_sc_Q10[ i ], tmp1 );\r
-\r
-        /* Flip sign depending on dither */\r
-        r_Q10 = ( r_Q10 ^ dither ) - dither;\r
-        r_Q10 = SKP_SUB32( r_Q10, offset_Q10 );\r
-        r_Q10 = SKP_LIMIT_32( r_Q10, -64 << 10, 64 << 10 );\r
-\r
-        /* Quantize */\r
-        q_Q0 = 0;\r
-        q_Q10 = 0;\r
-        if( r_Q10 < thr2_Q10 ) {\r
-            if( r_Q10 < thr1_Q10 ) {\r
-                q_Q0 = SKP_RSHIFT_ROUND( SKP_ADD_RSHIFT32( r_Q10, Lambda_Q10, 1 ), 10 );\r
-                q_Q10 = SKP_LSHIFT( q_Q0, 10 );\r
-            } else {\r
-                q_Q0 = -1;\r
-                q_Q10 = -1024;\r
-            }\r
-        } else {\r
-            if( r_Q10 > thr3_Q10 ) {\r
-                q_Q0 = SKP_RSHIFT_ROUND( SKP_SUB_RSHIFT32( r_Q10, Lambda_Q10, 1 ), 10 );\r
-                q_Q10 = SKP_LSHIFT( q_Q0, 10 );\r
-            }\r
-        }\r
-        q[ i ] = ( SKP_int8 )q_Q0; /* No saturation needed because max is 64 */\r
-\r
-        /* Excitation */\r
-        exc_Q10 = SKP_ADD32( q_Q10, offset_Q10 );\r
-        exc_Q10 = ( exc_Q10 ^ dither ) - dither;\r
-\r
-        /* Add predictions */\r
-        LPC_exc_Q10 = SKP_ADD32( exc_Q10, SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) );\r
-        xq_Q10      = SKP_ADD32( LPC_exc_Q10, LPC_pred_Q10 );\r
-        \r
-        /* Scale XQ back to normal level before saving */\r
-        xq[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( xq_Q10, Gain_Q16 ), 10 ) );\r
-        \r
-        \r
-        /* Update states */\r
-        psLPC_Q14++;\r
-        *psLPC_Q14 = SKP_LSHIFT( xq_Q10, 4 );\r
-        sLF_AR_shp_Q10 = SKP_SUB32( xq_Q10, n_AR_Q10 );\r
-        NSQ->sLF_AR_shp_Q12 = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );\r
-\r
-        NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx ] = SKP_SUB32( sLF_AR_shp_Q10, n_LF_Q10 );\r
-        sLTP_Q16[ NSQ->sLTP_buf_idx ] = SKP_LSHIFT( LPC_exc_Q10, 6 );\r
-        NSQ->sLTP_shp_buf_idx++;\r
-        NSQ->sLTP_buf_idx++;\r
-\r
-        /* Make dither dependent on quantized signal */\r
-        NSQ->rand_seed += q[ i ];\r
-    }\r
-\r
-    /* Update LPC synth buffer */\r
-    SKP_memcpy( NSQ->sLPC_Q14, &NSQ->sLPC_Q14[ length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );\r
-}\r
-\r
-SKP_INLINE void SKP_Silk_nsq_scale_states(\r
-    SKP_Silk_nsq_state  *NSQ,               /* I/O NSQ state                        */\r
-    const SKP_int16     x[],                /* I input in Q0                        */\r
-    SKP_int32           x_sc_Q10[],         /* O input scaled with 1/Gain           */\r
-    SKP_int             subfr_length,       /* I length of input                    */\r
-    const SKP_int16     sLTP[],             /* I re-whitened LTP state in Q0        */\r
-    SKP_int32           sLTP_Q16[],         /* O LTP state matching scaled input    */\r
-    SKP_int             subfr,              /* I subframe number                    */\r
-    const SKP_int       LTP_scale_Q14,      /* I                                    */\r
-    const SKP_int32     Gains_Q16[ NB_SUBFR ], /* I                                 */\r
-    const SKP_int       pitchL[ NB_SUBFR ]  /* I                                    */\r
-)\r
-{\r
-    SKP_int   i, lag;\r
-    SKP_int32 inv_gain_Q16, gain_adj_Q16, inv_gain_Q32;\r
-\r
-    inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gains_Q16[ subfr ], 1 ), 32 );\r
-    inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );\r
-    lag          = pitchL[ subfr ];\r
-\r
-    /* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */\r
-    if( NSQ->rewhite_flag ) {\r
-        inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 );\r
-        if( subfr == 0 ) {\r
-            /* Do LTP downscaling */\r
-            inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, LTP_scale_Q14 ), 2 );\r
-        }\r
-        for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {\r
-            SKP_assert( i < MAX_FRAME_LENGTH );\r
-            sLTP_Q16[ i ] = SKP_SMULWB( inv_gain_Q32, sLTP[ i ] );\r
-        }\r
-    }\r
-\r
-    /* Adjust for changing gain */\r
-    if( inv_gain_Q16 != NSQ->prev_inv_gain_Q16 ) {\r
-        gain_adj_Q16 = SKP_DIV32_varQ( inv_gain_Q16, NSQ->prev_inv_gain_Q16, 16 );\r
-\r
-        /* Scale long-term shaping state */\r
-        for( i = NSQ->sLTP_shp_buf_idx - subfr_length * NB_SUBFR; i < NSQ->sLTP_shp_buf_idx; i++ ) {\r
-            NSQ->sLTP_shp_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q10[ i ] );\r
-        }\r
-\r
-        /* Scale long-term prediction state */\r
-        if( NSQ->rewhite_flag == 0 ) {\r
-            for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {\r
-                sLTP_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, sLTP_Q16[ i ] );\r
-            }\r
-        }\r
-\r
-        NSQ->sLF_AR_shp_Q12 = SKP_SMULWW( gain_adj_Q16, NSQ->sLF_AR_shp_Q12 );\r
-\r
-        /* Scale short-term prediction and shaping states */\r
-        for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) {\r
-            NSQ->sLPC_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLPC_Q14[ i ] );\r
-        }\r
-        for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) {\r
-            NSQ->sAR2_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sAR2_Q14[ i ] );\r
-        }\r
-    }\r
-\r
-    /* Scale input */\r
-    for( i = 0; i < subfr_length; i++ ) {\r
-        x_sc_Q10[ i ] = SKP_RSHIFT( SKP_SMULBB( x[ i ], ( SKP_int16 )inv_gain_Q16 ), 6 );\r
-    }\r
-\r
-    /* save inv_gain */\r
-    SKP_assert( inv_gain_Q16 != 0 );\r
-    NSQ->prev_inv_gain_Q16 = inv_gain_Q16;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+SKP_INLINE void SKP_Silk_nsq_scale_states(
+    SKP_Silk_nsq_state  *NSQ,               /* I/O NSQ state                        */
+    const SKP_int16     x[],                /* I input in Q0                        */
+    SKP_int32           x_sc_Q10[],         /* O input scaled with 1/Gain           */
+    SKP_int             subfr_length,       /* I length of input                    */
+    const SKP_int16     sLTP[],             /* I re-whitened LTP state in Q0        */
+    SKP_int32           sLTP_Q16[],         /* O LTP state matching scaled input    */
+    SKP_int             subfr,              /* I subframe number                    */
+    const SKP_int       LTP_scale_Q14,      /* I                                    */
+    const SKP_int32     Gains_Q16[ NB_SUBFR ], /* I                                 */
+    const SKP_int       pitchL[ NB_SUBFR ]  /* I                                    */
+);
+
+SKP_INLINE void SKP_Silk_noise_shape_quantizer(
+    SKP_Silk_nsq_state  *NSQ,               /* I/O  NSQ state                       */
+    SKP_int             sigtype,            /* I    Signal type                     */
+    const SKP_int32     x_sc_Q10[],         /* I                                    */
+    SKP_int8            q[],                /* O                                    */
+    SKP_int16           xq[],               /* O                                    */
+    SKP_int32           sLTP_Q16[],         /* I/O  LTP state                       */
+    const SKP_int16     a_Q12[],            /* I    Short term prediction coefs     */
+    const SKP_int16     b_Q14[],            /* I    Long term prediction coefs      */
+    const SKP_int16     AR_shp_Q13[],       /* I    Noise shaping AR coefs          */
+    SKP_int             lag,                /* I    Pitch lag                       */
+    SKP_int32           HarmShapeFIRPacked_Q14, /* I                                */
+    SKP_int             Tilt_Q14,           /* I    Spectral tilt                   */
+    SKP_int32           LF_shp_Q14,         /* I                                    */
+    SKP_int32           Gain_Q16,           /* I                                    */
+    SKP_int             Lambda_Q10,         /* I                                    */
+    SKP_int             offset_Q10,         /* I                                    */
+    SKP_int             length,             /* I    Input length                    */
+    SKP_int             shapingLPCOrder,    /* I    Noise shaping AR filter order   */
+    SKP_int             predictLPCOrder     /* I    Prediction filter order         */
+);
+
+void SKP_Silk_NSQ(
+    SKP_Silk_encoder_state          *psEncC,                                    /* I/O  Encoder State                       */
+    SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */
+    SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */
+    const SKP_int16                 x[],                                        /* I    prefiltered input signal            */
+    SKP_int8                        q[],                                        /* O    quantized qulse signal              */
+    const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */
+    const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Short term prediction coefficients  */
+    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    Long term prediction coefficients   */
+    const SKP_int16                 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ],  /* I                                        */
+    const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */
+    const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */
+    const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */
+    const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */
+    const SKP_int                   Lambda_Q10,                                 /* I                                        */
+    const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */
+)
+{
+    SKP_int     k, lag, start_idx, subfr_length, LSF_interpolation_flag;
+    const SKP_int16 *A_Q12, *B_Q14, *AR_shp_Q13;
+    SKP_int16   *pxq;
+    SKP_int32   sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];
+    SKP_int16   sLTP[     2 * MAX_FRAME_LENGTH ];
+    SKP_int32   HarmShapeFIRPacked_Q14;
+    SKP_int     offset_Q10;
+    SKP_int32   FiltState[ MAX_LPC_ORDER ];
+    SKP_int32   x_sc_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ];
+
+    subfr_length = psEncC->frame_length / NB_SUBFR;
+
+    NSQ->rand_seed  =  psEncCtrlC->Seed;
+    /* Set unvoiced lag to the previous one, overwrite later for voiced */
+    lag             = NSQ->lagPrev;
+
+    SKP_assert( NSQ->prev_inv_gain_Q16 != 0 );
+
+    offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrlC->sigtype ][ psEncCtrlC->QuantOffsetType ];
+
+    if( LSFInterpFactor_Q2 == ( 1 << 2 ) ) {
+        LSF_interpolation_flag = 0;
+    } else {
+        LSF_interpolation_flag = 1;
+    }
+
+    /* Setup pointers to start of sub frame */
+    NSQ->sLTP_shp_buf_idx = psEncC->frame_length;
+    NSQ->sLTP_buf_idx     = psEncC->frame_length;
+    pxq                   = &NSQ->xq[ psEncC->frame_length ];
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        A_Q12      = &PredCoef_Q12[ (( k >> 1 ) | ( 1 - LSF_interpolation_flag )) * MAX_LPC_ORDER ];
+        B_Q14      = &LTPCoef_Q14[ k * LTP_ORDER ];
+        AR_shp_Q13 = &AR2_Q13[     k * MAX_SHAPE_LPC_ORDER ];
+
+        /* Noise shape parameters */
+        SKP_assert( HarmShapeGain_Q14[ k ] >= 0 );
+        HarmShapeFIRPacked_Q14  =                          SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 );
+        HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 );
+
+        NSQ->rewhite_flag = 0;
+        if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
+            /* Voiced */
+            lag = psEncCtrlC->pitchL[ k ];
+
+            /* Re-whitening */
+            if( ( k & ( 3 - SKP_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) {
+
+                /* Rewhiten with new A coefs */
+                start_idx = psEncC->frame_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2;
+                SKP_assert( start_idx >= 0 );
+                SKP_assert( start_idx <= psEncC->frame_length - psEncC->predictLPCOrder );
+
+                SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) );
+                SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * ( psEncC->frame_length >> 2 ) ], 
+                    A_Q12, FiltState, sLTP + start_idx, psEncC->frame_length - start_idx, psEncC->predictLPCOrder );
+
+                NSQ->rewhite_flag = 1;
+                NSQ->sLTP_buf_idx = psEncC->frame_length;
+            }
+        }
+        
+        SKP_Silk_nsq_scale_states( NSQ, x, x_sc_Q10, psEncC->subfr_length, sLTP, 
+            sLTP_Q16, k, LTP_scale_Q14, Gains_Q16, psEncCtrlC->pitchL );
+
+        SKP_Silk_noise_shape_quantizer( NSQ, psEncCtrlC->sigtype, x_sc_Q10, q, pxq, sLTP_Q16, A_Q12, B_Q14, 
+            AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], Lambda_Q10, 
+            offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder
+        );
+
+        x          += psEncC->subfr_length;
+        q          += psEncC->subfr_length;
+        pxq        += psEncC->subfr_length;
+    }
+
+    /* Update lagPrev for next frame */
+    NSQ->lagPrev = psEncCtrlC->pitchL[ NB_SUBFR - 1 ];
+
+    /* Save quantized speech and noise shaping signals */
+    SKP_memcpy( NSQ->xq,           &NSQ->xq[           psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) );
+    SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) );
+
+#ifdef USE_UNQUANTIZED_LSFS
+    DEBUG_STORE_DATA( xq_unq_lsfs.pcm, NSQ->xq, psEncC->frame_length * sizeof( SKP_int16 ) );
+#endif
+
+}
+
+/***********************************/
+/* SKP_Silk_noise_shape_quantizer  */
+/***********************************/
+SKP_INLINE void SKP_Silk_noise_shape_quantizer(
+    SKP_Silk_nsq_state  *NSQ,               /* I/O  NSQ state                       */
+    SKP_int             sigtype,            /* I    Signal type                     */
+    const SKP_int32     x_sc_Q10[],         /* I                                    */
+    SKP_int8            q[],                /* O                                    */
+    SKP_int16           xq[],               /* O                                    */
+    SKP_int32           sLTP_Q16[],         /* I/O  LTP state                       */
+    const SKP_int16     a_Q12[],            /* I    Short term prediction coefs     */
+    const SKP_int16     b_Q14[],            /* I    Long term prediction coefs      */
+    const SKP_int16     AR_shp_Q13[],       /* I    Noise shaping AR coefs          */
+    SKP_int             lag,                /* I    Pitch lag                       */
+    SKP_int32           HarmShapeFIRPacked_Q14, /* I                                */
+    SKP_int             Tilt_Q14,           /* I    Spectral tilt                   */
+    SKP_int32           LF_shp_Q14,         /* I                                    */
+    SKP_int32           Gain_Q16,           /* I                                    */
+    SKP_int             Lambda_Q10,         /* I                                    */
+    SKP_int             offset_Q10,         /* I                                    */
+    SKP_int             length,             /* I    Input length                    */
+    SKP_int             shapingLPCOrder,    /* I    Noise shaping AR filter order   */
+    SKP_int             predictLPCOrder     /* I    Prediction filter order         */
+)
+{
+    SKP_int     i, j;
+    SKP_int32   LTP_pred_Q14, LPC_pred_Q10, n_AR_Q10, n_LTP_Q14;
+    SKP_int32   n_LF_Q10, r_Q10, q_Q0, q_Q10;
+    SKP_int32   thr1_Q10, thr2_Q10, thr3_Q10;
+    SKP_int32   dither, exc_Q10, LPC_exc_Q10, xq_Q10;
+    SKP_int32   tmp1, tmp2, sLF_AR_shp_Q10;
+    SKP_int32   *psLPC_Q14, *shp_lag_ptr, *pred_lag_ptr;
+
+    shp_lag_ptr  = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ];
+    pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ];
+    
+    /* Setup short term AR state */
+    psLPC_Q14 = &NSQ->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 ];
+
+    /* Quantization thresholds */
+    thr1_Q10 = SKP_SUB_RSHIFT32( -1536, Lambda_Q10, 1 );
+    thr2_Q10 = SKP_SUB_RSHIFT32(  -512, Lambda_Q10, 1 );
+    thr2_Q10 = SKP_ADD_RSHIFT32( thr2_Q10, SKP_SMULBB( offset_Q10, Lambda_Q10 ), 10 );
+    thr3_Q10 = SKP_ADD_RSHIFT32(   512, Lambda_Q10, 1 );
+
+    for( i = 0; i < length; i++ ) {
+        /* Generate dither */
+        NSQ->rand_seed = SKP_RAND( NSQ->rand_seed );
+
+        /* dither = rand_seed < 0 ? 0xFFFFFFFF : 0; */
+        dither = SKP_RSHIFT( NSQ->rand_seed, 31 );
+                
+        /* Short-term prediction */
+        SKP_assert( ( predictLPCOrder  & 1 ) == 0 );    /* check that order is even */
+        /* check that array starts at 4-byte aligned address */
+        SKP_assert( ( ( SKP_int64 )( ( SKP_int8* )a_Q12 - ( SKP_int8* )0 ) & 3 ) == 0 );
+        SKP_assert( predictLPCOrder >= 10 );            /* check that unrolling works */
+        /* Partially unrolled */
+        LPC_pred_Q10 = SKP_SMULWB(               psLPC_Q14[  0 ], a_Q12[ 0 ] );
+        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -1 ], a_Q12[ 1 ] );
+        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], a_Q12[ 2 ] );
+        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -3 ], a_Q12[ 3 ] );
+        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], a_Q12[ 4 ] );
+        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -5 ], a_Q12[ 5 ] );
+        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], a_Q12[ 6 ] );
+        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -7 ], a_Q12[ 7 ] );
+        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], a_Q12[ 8 ] );
+        LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -9 ], a_Q12[ 9 ] );
+        for( j = 10; j < predictLPCOrder; j ++ ) {
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], a_Q12[ j ] );
+        }
+        /* Long-term prediction */
+        if( sigtype == SIG_TYPE_VOICED ) {
+            /* Unrolled loop */
+            LTP_pred_Q14 = SKP_SMULWB(               pred_lag_ptr[  0 ], b_Q14[ 0 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], b_Q14[ 1 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], b_Q14[ 2 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], b_Q14[ 3 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], b_Q14[ 4 ] );
+            pred_lag_ptr++;
+        } else {
+            LTP_pred_Q14 = 0;
+        }
+
+        /* Noise shape feedback */
+        SKP_assert( ( shapingLPCOrder & 1 ) == 0 );   /* check that order is even */
+        tmp2 = psLPC_Q14[ 0 ];
+        tmp1 = NSQ->sAR2_Q14[ 0 ];
+        NSQ->sAR2_Q14[ 0 ] = tmp2;
+        n_AR_Q10 = SKP_SMULWB( tmp2, AR_shp_Q13[ 0 ] );
+        for( j = 2; j < shapingLPCOrder; j += 2 ) {
+            tmp2 = NSQ->sAR2_Q14[ j - 1 ];
+            NSQ->sAR2_Q14[ j - 1 ] = tmp1;
+            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ j - 1 ] );
+            tmp1 = NSQ->sAR2_Q14[ j + 0 ];
+            NSQ->sAR2_Q14[ j + 0 ] = tmp2;
+            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp2, AR_shp_Q13[ j ] );
+        }
+        NSQ->sAR2_Q14[ shapingLPCOrder - 1 ] = tmp1;
+        n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ shapingLPCOrder - 1 ] );
+
+        n_AR_Q10 = SKP_RSHIFT( n_AR_Q10, 1 );   /* Q11 -> Q10 */
+        n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, NSQ->sLF_AR_shp_Q12, Tilt_Q14 );
+
+        n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - 1 ], LF_shp_Q14 ), 2 ); 
+        n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, NSQ->sLF_AR_shp_Q12, LF_shp_Q14 );
+
+        SKP_assert( lag > 0 || sigtype == SIG_TYPE_UNVOICED );
+
+        /* Long-term shaping */
+        if( lag > 0 ) {
+            /* Symmetric, packed FIR coefficients */
+            n_LTP_Q14 = SKP_SMULWB( SKP_ADD32( shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ] ), HarmShapeFIRPacked_Q14 );
+            n_LTP_Q14 = SKP_SMLAWT( n_LTP_Q14, shp_lag_ptr[ -1 ],                     HarmShapeFIRPacked_Q14 );
+            n_LTP_Q14 = SKP_LSHIFT( n_LTP_Q14, 6 );
+            shp_lag_ptr++;
+        } else {
+            n_LTP_Q14 = 0;
+        }
+
+        /* Input minus prediction plus noise feedback  */
+        //r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP;
+        tmp1  = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 );                       /* Add Q14 stuff */
+        tmp1  = SKP_RSHIFT( tmp1, 4 );                                      /* convert to Q10  */
+        tmp1  = SKP_ADD32( tmp1, LPC_pred_Q10 );                            /* add Q10 stuff */ 
+        tmp1  = SKP_SUB32( tmp1, n_AR_Q10 );                                /* subtract Q10 stuff */ 
+        tmp1  = SKP_SUB32( tmp1, n_LF_Q10 );                                /* subtract Q10 stuff */ 
+        r_Q10 = SKP_SUB32( x_sc_Q10[ i ], tmp1 );
+
+        /* Flip sign depending on dither */
+        r_Q10 = ( r_Q10 ^ dither ) - dither;
+        r_Q10 = SKP_SUB32( r_Q10, offset_Q10 );
+        r_Q10 = SKP_LIMIT_32( r_Q10, -64 << 10, 64 << 10 );
+
+        /* Quantize */
+        q_Q0 = 0;
+        q_Q10 = 0;
+        if( r_Q10 < thr2_Q10 ) {
+            if( r_Q10 < thr1_Q10 ) {
+                q_Q0 = SKP_RSHIFT_ROUND( SKP_ADD_RSHIFT32( r_Q10, Lambda_Q10, 1 ), 10 );
+                q_Q10 = SKP_LSHIFT( q_Q0, 10 );
+            } else {
+                q_Q0 = -1;
+                q_Q10 = -1024;
+            }
+        } else {
+            if( r_Q10 > thr3_Q10 ) {
+                q_Q0 = SKP_RSHIFT_ROUND( SKP_SUB_RSHIFT32( r_Q10, Lambda_Q10, 1 ), 10 );
+                q_Q10 = SKP_LSHIFT( q_Q0, 10 );
+            }
+        }
+        q[ i ] = ( SKP_int8 )q_Q0; /* No saturation needed because max is 64 */
+
+        /* Excitation */
+        exc_Q10 = SKP_ADD32( q_Q10, offset_Q10 );
+        exc_Q10 = ( exc_Q10 ^ dither ) - dither;
+
+        /* Add predictions */
+        LPC_exc_Q10 = SKP_ADD32( exc_Q10, SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) );
+        xq_Q10      = SKP_ADD32( LPC_exc_Q10, LPC_pred_Q10 );
+        
+        /* Scale XQ back to normal level before saving */
+        xq[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( xq_Q10, Gain_Q16 ), 10 ) );
+        
+        
+        /* Update states */
+        psLPC_Q14++;
+        *psLPC_Q14 = SKP_LSHIFT( xq_Q10, 4 );
+        sLF_AR_shp_Q10 = SKP_SUB32( xq_Q10, n_AR_Q10 );
+        NSQ->sLF_AR_shp_Q12 = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );
+
+        NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx ] = SKP_SUB32( sLF_AR_shp_Q10, n_LF_Q10 );
+        sLTP_Q16[ NSQ->sLTP_buf_idx ] = SKP_LSHIFT( LPC_exc_Q10, 6 );
+        NSQ->sLTP_shp_buf_idx++;
+        NSQ->sLTP_buf_idx++;
+
+        /* Make dither dependent on quantized signal */
+        NSQ->rand_seed += q[ i ];
+    }
+
+    /* Update LPC synth buffer */
+    SKP_memcpy( NSQ->sLPC_Q14, &NSQ->sLPC_Q14[ length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
+}
+
+SKP_INLINE void SKP_Silk_nsq_scale_states(
+    SKP_Silk_nsq_state  *NSQ,               /* I/O NSQ state                        */
+    const SKP_int16     x[],                /* I input in Q0                        */
+    SKP_int32           x_sc_Q10[],         /* O input scaled with 1/Gain           */
+    SKP_int             subfr_length,       /* I length of input                    */
+    const SKP_int16     sLTP[],             /* I re-whitened LTP state in Q0        */
+    SKP_int32           sLTP_Q16[],         /* O LTP state matching scaled input    */
+    SKP_int             subfr,              /* I subframe number                    */
+    const SKP_int       LTP_scale_Q14,      /* I                                    */
+    const SKP_int32     Gains_Q16[ NB_SUBFR ], /* I                                 */
+    const SKP_int       pitchL[ NB_SUBFR ]  /* I                                    */
+)
+{
+    SKP_int   i, lag;
+    SKP_int32 inv_gain_Q16, gain_adj_Q16, inv_gain_Q32;
+
+    inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gains_Q16[ subfr ], 1 ), 32 );
+    inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );
+    lag          = pitchL[ subfr ];
+
+    /* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */
+    if( NSQ->rewhite_flag ) {
+        inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 );
+        if( subfr == 0 ) {
+            /* Do LTP downscaling */
+            inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, LTP_scale_Q14 ), 2 );
+        }
+        for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
+            SKP_assert( i < MAX_FRAME_LENGTH );
+            sLTP_Q16[ i ] = SKP_SMULWB( inv_gain_Q32, sLTP[ i ] );
+        }
+    }
+
+    /* Adjust for changing gain */
+    if( inv_gain_Q16 != NSQ->prev_inv_gain_Q16 ) {
+        gain_adj_Q16 = SKP_DIV32_varQ( inv_gain_Q16, NSQ->prev_inv_gain_Q16, 16 );
+
+        /* Scale long-term shaping state */
+        for( i = NSQ->sLTP_shp_buf_idx - subfr_length * NB_SUBFR; i < NSQ->sLTP_shp_buf_idx; i++ ) {
+            NSQ->sLTP_shp_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q10[ i ] );
+        }
+
+        /* Scale long-term prediction state */
+        if( NSQ->rewhite_flag == 0 ) {
+            for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
+                sLTP_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, sLTP_Q16[ i ] );
+            }
+        }
+
+        NSQ->sLF_AR_shp_Q12 = SKP_SMULWW( gain_adj_Q16, NSQ->sLF_AR_shp_Q12 );
+
+        /* Scale short-term prediction and shaping states */
+        for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) {
+            NSQ->sLPC_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLPC_Q14[ i ] );
+        }
+        for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) {
+            NSQ->sAR2_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sAR2_Q14[ i ] );
+        }
+    }
+
+    /* Scale input */
+    for( i = 0; i < subfr_length; i++ ) {
+        x_sc_Q10[ i ] = SKP_RSHIFT( SKP_SMULBB( x[ i ], ( SKP_int16 )inv_gain_Q16 ), 6 );
+    }
+
+    /* save inv_gain */
+    SKP_assert( inv_gain_Q16 != 0 );
+    NSQ->prev_inv_gain_Q16 = inv_gain_Q16;
+}
index 2ef9539a1d1f761256dd5df00df28de04116964b..198b4f572645d3042f40d9edfaedb1eee51c9744 100644 (file)
-/***********************************************************************\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
-typedef struct {\r
-    SKP_int32 RandState[ DECISION_DELAY ];\r
-    SKP_int32 Q_Q10[     DECISION_DELAY ];\r
-    SKP_int32 Xq_Q10[    DECISION_DELAY ];\r
-    SKP_int32 Pred_Q16[  DECISION_DELAY ];\r
-    SKP_int32 Shape_Q10[ DECISION_DELAY ];\r
-    SKP_int32 Gain_Q16[  DECISION_DELAY ];\r
-    SKP_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ];\r
-    SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / NB_SUBFR + NSQ_LPC_BUF_LENGTH ];\r
-    SKP_int32 LF_AR_Q12;\r
-    SKP_int32 Seed;\r
-    SKP_int32 SeedInit;\r
-    SKP_int32 RD_Q10;\r
-} NSQ_del_dec_struct;\r
-\r
-typedef struct {\r
-    SKP_int32 Q_Q10;\r
-    SKP_int32 RD_Q10;\r
-    SKP_int32 xq_Q14;\r
-    SKP_int32 LF_AR_Q12;\r
-    SKP_int32 sLTP_shp_Q10;\r
-    SKP_int32 LPC_exc_Q16;\r
-} NSQ_sample_struct;\r
-\r
-SKP_INLINE void SKP_Silk_copy_del_dec_state(\r
-    NSQ_del_dec_struct  *DD_dst,                /* I    Dst del dec state                   */\r
-    NSQ_del_dec_struct  *DD_src,                /* I    Src del dec state                   */\r
-    SKP_int             LPC_state_idx           /* I    Index to LPC buffer                 */\r
-);\r
-\r
-SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(\r
-    SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */\r
-    NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */\r
-    const SKP_int16     x[],                    /* I    Input in Q0                         */\r
-    SKP_int32           x_sc_Q10[],             /* O    Input scaled with 1/Gain in Q10     */\r
-    SKP_int             subfr_length,           /* I    Length of input                     */\r
-    const SKP_int16     sLTP[],                 /* I    Re-whitened LTP state in Q0         */\r
-    SKP_int32           sLTP_Q16[],             /* O    LTP state matching scaled input     */\r
-    SKP_int             subfr,                  /* I    Subframe number                     */\r
-    SKP_int             nStatesDelayedDecision, /* I    Number of del dec states            */\r
-    SKP_int             smpl_buf_idx,           /* I    Index to newest samples in buffers  */\r
-    const SKP_int       LTP_scale_Q14,          /* I    LTP state scaling                   */\r
-    const SKP_int32     Gains_Q16[ NB_SUBFR ],  /* I                                        */\r
-    const SKP_int       pitchL[ NB_SUBFR ]      /* I    Pitch lag                           */\r
-);\r
-\r
-/******************************************/\r
-/* Noise shape quantizer for one subframe */\r
-/******************************************/\r
-SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(\r
-    SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */\r
-    NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */\r
-    SKP_int             sigtype,                /* I    Signal type                         */\r
-    const SKP_int32     x_Q10[],                /* I                                        */\r
-    SKP_int8            q[],                    /* O                                        */\r
-    SKP_int16           xq[],                   /* O                                        */\r
-    SKP_int32           sLTP_Q16[],             /* I/O  LTP filter state                    */\r
-    const SKP_int16     a_Q12[],                /* I    Short term prediction coefs         */\r
-    const SKP_int16     b_Q14[],                /* I    Long term prediction coefs          */\r
-    const SKP_int16     AR_shp_Q13[],           /* I    Noise shaping coefs                 */\r
-    SKP_int             lag,                    /* I    Pitch lag                           */\r
-    SKP_int32           HarmShapeFIRPacked_Q14, /* I                                        */\r
-    SKP_int             Tilt_Q14,               /* I    Spectral tilt                       */\r
-    SKP_int32           LF_shp_Q14,             /* I                                        */\r
-    SKP_int32           Gain_Q16,               /* I                                        */\r
-    SKP_int             Lambda_Q10,             /* I                                        */\r
-    SKP_int             offset_Q10,             /* I                                        */\r
-    SKP_int             length,                 /* I    Input length                        */\r
-    SKP_int             subfr,                  /* I    Subframe number                     */\r
-    SKP_int             shapingLPCOrder,        /* I    Shaping LPC filter order            */\r
-    SKP_int             predictLPCOrder,        /* I    Prediction filter order             */\r
-    SKP_int             warping_Q16,            /* I                                        */\r
-    SKP_int             nStatesDelayedDecision, /* I    Number of states in decision tree   */\r
-    SKP_int             *smpl_buf_idx,          /* I    Index to newest samples in buffers  */\r
-    SKP_int             decisionDelay           /* I                                        */\r
-);\r
-\r
-void SKP_Silk_NSQ_del_dec(\r
-    SKP_Silk_encoder_state          *psEncC,                                    /* I/O  Encoder State                       */\r
-    SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */\r
-    SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */\r
-    const SKP_int16                 x[],                                        /* I    Prefiltered input signal            */\r
-    SKP_int8                        q[],                                        /* O    Quantized pulse signal              */\r
-    const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */\r
-    const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Prediction coefs                    */\r
-    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    LT prediction coefs                 */\r
-    const SKP_int16                 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ],  /* I                                        */\r
-    const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */\r
-    const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */\r
-    const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */\r
-    const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */\r
-    const SKP_int                   Lambda_Q10,                                 /* I                                        */\r
-    const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */\r
-)\r
-{\r
-    SKP_int     i, k, lag, start_idx, LSF_interpolation_flag, Winner_ind, subfr;\r
-    SKP_int     last_smple_idx, smpl_buf_idx, decisionDelay, subfr_length;\r
-    const SKP_int16 *A_Q12, *B_Q14, *AR_shp_Q13;\r
-    SKP_int16   *pxq;\r
-    SKP_int32   sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];\r
-    SKP_int16   sLTP[     2 * MAX_FRAME_LENGTH ];\r
-    SKP_int32   HarmShapeFIRPacked_Q14;\r
-    SKP_int     offset_Q10;\r
-    SKP_int32   FiltState[ MAX_LPC_ORDER ], RDmin_Q10;\r
-    SKP_int32   x_sc_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ];\r
-    NSQ_del_dec_struct psDelDec[ MAX_DEL_DEC_STATES ];\r
-    NSQ_del_dec_struct *psDD;\r
-\r
-    subfr_length = psEncC->frame_length / NB_SUBFR;\r
-\r
-    /* Set unvoiced lag to the previous one, overwrite later for voiced */\r
-    lag = NSQ->lagPrev;\r
-\r
-    SKP_assert( NSQ->prev_inv_gain_Q16 != 0 );\r
-\r
-    /* Initialize delayed decision states */\r
-    SKP_memset( psDelDec, 0, psEncC->nStatesDelayedDecision * sizeof( NSQ_del_dec_struct ) );\r
-    for( k = 0; k < psEncC->nStatesDelayedDecision; k++ ) {\r
-        psDD                 = &psDelDec[ k ];\r
-        psDD->Seed           = ( k + psEncCtrlC->Seed ) & 3;\r
-        psDD->SeedInit       = psDD->Seed;\r
-        psDD->RD_Q10         = 0;\r
-        psDD->LF_AR_Q12      = NSQ->sLF_AR_shp_Q12;\r
-        psDD->Shape_Q10[ 0 ] = NSQ->sLTP_shp_Q10[ psEncC->frame_length - 1 ];\r
-        SKP_memcpy( psDD->sLPC_Q14, NSQ->sLPC_Q14, NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );\r
-        SKP_memcpy( psDD->sAR2_Q14, NSQ->sAR2_Q14, sizeof( NSQ->sAR2_Q14 ) );\r
-    }\r
-\r
-    offset_Q10   = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrlC->sigtype ][ psEncCtrlC->QuantOffsetType ];\r
-    smpl_buf_idx = 0; /* index of oldest samples */\r
-\r
-    decisionDelay = SKP_min_int( DECISION_DELAY, subfr_length );\r
-\r
-    /* For voiced frames limit the decision delay to lower than the pitch lag */\r
-    if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {\r
-        for( k = 0; k < NB_SUBFR; k++ ) {\r
-            decisionDelay = SKP_min_int( decisionDelay, psEncCtrlC->pitchL[ k ] - LTP_ORDER / 2 - 1 );\r
-        }\r
-    } else {\r
-        if( lag > 0 ) {\r
-            decisionDelay = SKP_min_int( decisionDelay, lag - LTP_ORDER / 2 - 1 );\r
-        }\r
-    }\r
-\r
-    if( LSFInterpFactor_Q2 == ( 1 << 2 ) ) {\r
-        LSF_interpolation_flag = 0;\r
-    } else {\r
-        LSF_interpolation_flag = 1;\r
-    }\r
-\r
-    /* Setup pointers to start of sub frame */\r
-    pxq                   = &NSQ->xq[ psEncC->frame_length ];\r
-    NSQ->sLTP_shp_buf_idx = psEncC->frame_length;\r
-    NSQ->sLTP_buf_idx     = psEncC->frame_length;\r
-    subfr = 0;\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        A_Q12      = &PredCoef_Q12[ ( ( k >> 1 ) | ( 1 - LSF_interpolation_flag ) ) * MAX_LPC_ORDER ];\r
-        B_Q14      = &LTPCoef_Q14[ k * LTP_ORDER           ];\r
-        AR_shp_Q13 = &AR2_Q13[     k * MAX_SHAPE_LPC_ORDER ];\r
-\r
-        /* Noise shape parameters */\r
-        SKP_assert( HarmShapeGain_Q14[ k ] >= 0 );\r
-        HarmShapeFIRPacked_Q14  =                          SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 );\r
-        HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 );\r
-\r
-        NSQ->rewhite_flag = 0;\r
-        if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {\r
-            /* Voiced */\r
-            lag = psEncCtrlC->pitchL[ k ];\r
-\r
-            /* Re-whitening */\r
-            if( ( k & ( 3 - SKP_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) {\r
-                if( k == 2 ) {\r
-                    /* RESET DELAYED DECISIONS */\r
-                    /* Find winner */\r
-                    RDmin_Q10 = psDelDec[ 0 ].RD_Q10;\r
-                    Winner_ind = 0;\r
-                    for( i = 1; i < psEncC->nStatesDelayedDecision; i++ ) {\r
-                        if( psDelDec[ i ].RD_Q10 < RDmin_Q10 ) {\r
-                            RDmin_Q10 = psDelDec[ i ].RD_Q10;\r
-                            Winner_ind = i;\r
-                        }\r
-                    }\r
-                    for( i = 0; i < psEncC->nStatesDelayedDecision; i++ ) {\r
-                        if( i != Winner_ind ) {\r
-                            psDelDec[ i ].RD_Q10 += ( SKP_int32_MAX >> 4 );\r
-                            SKP_assert( psDelDec[ i ].RD_Q10 >= 0 );\r
-                        }\r
-                    }\r
-                    \r
-                    /* Copy final part of signals from winner state to output and long-term filter states */\r
-                    psDD = &psDelDec[ Winner_ind ];\r
-                    last_smple_idx = smpl_buf_idx + decisionDelay;\r
-                    for( i = 0; i < decisionDelay; i++ ) {\r
-                        last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;\r
-                        q[   i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );\r
-                        pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( \r
-                            SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], \r
-                            psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );\r
-                        NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];\r
-                    }\r
-\r
-                    subfr = 0;\r
-                }\r
-\r
-                /* Rewhiten with new A coefs */\r
-                start_idx = psEncC->frame_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2;\r
-                SKP_assert( start_idx >= 0 );\r
-                SKP_assert( start_idx <= psEncC->frame_length - psEncC->predictLPCOrder );\r
-\r
-                SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) );\r
-                SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * psEncC->subfr_length ], \r
-                    A_Q12, FiltState, sLTP + start_idx, psEncC->frame_length - start_idx, psEncC->predictLPCOrder );\r
-\r
-                NSQ->sLTP_buf_idx = psEncC->frame_length;\r
-                NSQ->rewhite_flag = 1;\r
-            }\r
-        }\r
-\r
-        SKP_Silk_nsq_del_dec_scale_states( NSQ, psDelDec, x, x_sc_Q10, \r
-            subfr_length, sLTP, sLTP_Q16, k, psEncC->nStatesDelayedDecision, smpl_buf_idx,\r
-            LTP_scale_Q14, Gains_Q16, psEncCtrlC->pitchL );\r
-\r
-        SKP_Silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psEncCtrlC->sigtype, x_sc_Q10, q, pxq, sLTP_Q16,\r
-            A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], \r
-            Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder, psEncC->predictLPCOrder, \r
-            psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay );\r
-        \r
-        x   += psEncC->subfr_length;\r
-        q   += psEncC->subfr_length;\r
-        pxq += psEncC->subfr_length;\r
-    }\r
-\r
-    /* Find winner */\r
-    RDmin_Q10 = psDelDec[ 0 ].RD_Q10;\r
-    Winner_ind = 0;\r
-    for( k = 1; k < psEncC->nStatesDelayedDecision; k++ ) {\r
-        if( psDelDec[ k ].RD_Q10 < RDmin_Q10 ) {\r
-            RDmin_Q10 = psDelDec[ k ].RD_Q10;\r
-            Winner_ind = k;\r
-        }\r
-    }\r
-    \r
-    /* Copy final part of signals from winner state to output and long-term filter states */\r
-    psDD = &psDelDec[ Winner_ind ];\r
-    psEncCtrlC->Seed = psDD->SeedInit;\r
-    last_smple_idx = smpl_buf_idx + decisionDelay;\r
-    for( i = 0; i < decisionDelay; i++ ) {\r
-        last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;\r
-        q[   i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );\r
-        pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( \r
-            SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );\r
-        NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];\r
-        sLTP_Q16[          NSQ->sLTP_buf_idx     - decisionDelay + i ] = psDD->Pred_Q16[  last_smple_idx ];\r
-    }\r
-    SKP_memcpy( NSQ->sLPC_Q14, &psDD->sLPC_Q14[ psEncC->subfr_length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );\r
-    SKP_memcpy( NSQ->sAR2_Q14, psDD->sAR2_Q14, sizeof( psDD->sAR2_Q14 ) );\r
-\r
-    /* Update states */\r
-    NSQ->sLF_AR_shp_Q12 = psDD->LF_AR_Q12;\r
-    NSQ->lagPrev        = psEncCtrlC->pitchL[ NB_SUBFR - 1 ];\r
-\r
-    /* Save quantized speech and noise shaping signals */\r
-    SKP_memcpy( NSQ->xq,           &NSQ->xq[           psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) );\r
-    SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) );\r
-\r
-#ifdef USE_UNQUANTIZED_LSFS\r
-    DEBUG_STORE_DATA( xq_unq_lsfs.pcm, NSQ->xq, psEncC->frame_length * sizeof( SKP_int16 ) );\r
-#endif\r
-\r
-}\r
-\r
-/******************************************/\r
-/* Noise shape quantizer for one subframe */\r
-/******************************************/\r
-SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(\r
-    SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */\r
-    NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */\r
-    SKP_int             sigtype,                /* I    Signal type                         */\r
-    const SKP_int32     x_Q10[],                /* I                                        */\r
-    SKP_int8            q[],                    /* O                                        */\r
-    SKP_int16           xq[],                   /* O                                        */\r
-    SKP_int32           sLTP_Q16[],             /* I/O  LTP filter state                    */\r
-    const SKP_int16     a_Q12[],                /* I    Short term prediction coefs         */\r
-    const SKP_int16     b_Q14[],                /* I    Long term prediction coefs          */\r
-    const SKP_int16     AR_shp_Q13[],           /* I    Noise shaping coefs                 */\r
-    SKP_int             lag,                    /* I    Pitch lag                           */\r
-    SKP_int32           HarmShapeFIRPacked_Q14, /* I                                        */\r
-    SKP_int             Tilt_Q14,               /* I    Spectral tilt                       */\r
-    SKP_int32           LF_shp_Q14,             /* I                                        */\r
-    SKP_int32           Gain_Q16,               /* I                                        */\r
-    SKP_int             Lambda_Q10,             /* I                                        */\r
-    SKP_int             offset_Q10,             /* I                                        */\r
-    SKP_int             length,                 /* I    Input length                        */\r
-    SKP_int             subfr,                  /* I    Subframe number                     */\r
-    SKP_int             shapingLPCOrder,        /* I    Shaping LPC filter order            */\r
-    SKP_int             predictLPCOrder,        /* I    Prediction filter order             */\r
-    SKP_int             warping_Q16,            /* I                                        */\r
-    SKP_int             nStatesDelayedDecision, /* I    Number of states in decision tree   */\r
-    SKP_int             *smpl_buf_idx,          /* I    Index to newest samples in buffers  */\r
-    SKP_int             decisionDelay           /* I                                        */\r
-)\r
-{\r
-    SKP_int     i, j, k, Winner_ind, RDmin_ind, RDmax_ind, last_smple_idx;\r
-    SKP_int32   Winner_rand_state;\r
-    SKP_int32   LTP_pred_Q14, LPC_pred_Q10, n_AR_Q10, n_LTP_Q14;\r
-    SKP_int32   n_LF_Q10, r_Q10, rr_Q20, rd1_Q10, rd2_Q10, RDmin_Q10, RDmax_Q10;\r
-    SKP_int32   q1_Q10, q2_Q10, dither, exc_Q10, LPC_exc_Q10, xq_Q10;\r
-    SKP_int32   tmp1, tmp2, sLF_AR_shp_Q10;\r
-    SKP_int32   *pred_lag_ptr, *shp_lag_ptr, *psLPC_Q14;\r
-    NSQ_sample_struct  psSampleState[ MAX_DEL_DEC_STATES ][ 2 ];\r
-    NSQ_del_dec_struct *psDD;\r
-    NSQ_sample_struct  *psSS;\r
-\r
-    shp_lag_ptr  = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ];\r
-    pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ];\r
-\r
-    for( i = 0; i < length; i++ ) {\r
-        /* Perform common calculations used in all states */\r
-\r
-        /* Long-term prediction */\r
-        if( sigtype == SIG_TYPE_VOICED ) {\r
-            /* Unrolled loop */\r
-            LTP_pred_Q14 = SKP_SMULWB(               pred_lag_ptr[  0 ], b_Q14[ 0 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], b_Q14[ 1 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], b_Q14[ 2 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], b_Q14[ 3 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], b_Q14[ 4 ] );\r
-            pred_lag_ptr++;\r
-        } else {\r
-            LTP_pred_Q14 = 0;\r
-        }\r
-\r
-        /* Long-term shaping */\r
-        if( lag > 0 ) {\r
-            /* Symmetric, packed FIR coefficients */\r
-            n_LTP_Q14 = SKP_SMULWB( SKP_ADD32( shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ] ), HarmShapeFIRPacked_Q14 );\r
-            n_LTP_Q14 = SKP_SMLAWT( n_LTP_Q14, shp_lag_ptr[ -1 ],                     HarmShapeFIRPacked_Q14 );\r
-            n_LTP_Q14 = SKP_LSHIFT( n_LTP_Q14, 6 );\r
-            shp_lag_ptr++;\r
-        } else {\r
-            n_LTP_Q14 = 0;\r
-        }\r
-\r
-        for( k = 0; k < nStatesDelayedDecision; k++ ) {\r
-            /* Delayed decision state */\r
-            psDD = &psDelDec[ k ];\r
-\r
-            /* Sample state */\r
-            psSS = psSampleState[ k ];\r
-\r
-            /* Generate dither */\r
-            psDD->Seed = SKP_RAND( psDD->Seed );\r
-\r
-            /* dither = rand_seed < 0 ? 0xFFFFFFFF : 0; */\r
-            dither = SKP_RSHIFT( psDD->Seed, 31 );\r
-            \r
-            /* Pointer used in short term prediction and shaping */\r
-            psLPC_Q14 = &psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 + i ];\r
-            /* Short-term prediction */\r
-            SKP_assert( predictLPCOrder >= 10 );            /* check that unrolling works */\r
-            SKP_assert( ( predictLPCOrder  & 1 ) == 0 );    /* check that order is even */\r
-            SKP_assert( ( ( ( int )( ( char* )( a_Q12 ) - ( ( char* ) 0 ) ) ) & 3 ) == 0 );    /* check that array starts at 4-byte aligned address */\r
-            /* Partially unrolled */\r
-            LPC_pred_Q10 = SKP_SMULWB(               psLPC_Q14[  0 ], a_Q12[ 0 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -1 ], a_Q12[ 1 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], a_Q12[ 2 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -3 ], a_Q12[ 3 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], a_Q12[ 4 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -5 ], a_Q12[ 5 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], a_Q12[ 6 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -7 ], a_Q12[ 7 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], a_Q12[ 8 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -9 ], a_Q12[ 9 ] );\r
-            for( j = 10; j < predictLPCOrder; j ++ ) {\r
-                LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], a_Q12[ j ] );\r
-            }\r
-\r
-            /* Noise shape feedback */\r
-            SKP_assert( ( shapingLPCOrder & 1 ) == 0 );   /* check that order is even */\r
-            /* Output of lowpass section */\r
-            tmp2 = SKP_SMLAWB( psLPC_Q14[ 0 ], psDD->sAR2_Q14[ 0 ], warping_Q16 );\r
-            /* Output of allpass section */\r
-            tmp1 = SKP_SMLAWB( psDD->sAR2_Q14[ 0 ], psDD->sAR2_Q14[ 1 ] - tmp2, warping_Q16 );\r
-            psDD->sAR2_Q14[ 0 ] = tmp2;\r
-            n_AR_Q10 = SKP_SMULWB( tmp2, AR_shp_Q13[ 0 ] );\r
-            /* Loop over allpass sections */\r
-            for( j = 2; j < shapingLPCOrder; j += 2 ) {\r
-                /* Output of allpass section */\r
-                tmp2 = SKP_SMLAWB( psDD->sAR2_Q14[ j - 1 ], psDD->sAR2_Q14[ j + 0 ] - tmp1, warping_Q16 );\r
-                psDD->sAR2_Q14[ j - 1 ] = tmp1;\r
-                n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ j - 1 ] );\r
-                /* Output of allpass section */\r
-                tmp1 = SKP_SMLAWB( psDD->sAR2_Q14[ j + 0 ], psDD->sAR2_Q14[ j + 1 ] - tmp2, warping_Q16 );\r
-                psDD->sAR2_Q14[ j + 0 ] = tmp2;\r
-                n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp2, AR_shp_Q13[ j ] );\r
-            }\r
-            psDD->sAR2_Q14[ shapingLPCOrder - 1 ] = tmp1;\r
-            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ shapingLPCOrder - 1 ] );\r
-\r
-            n_AR_Q10 = SKP_RSHIFT( n_AR_Q10, 1 );           /* Q11 -> Q10 */\r
-            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psDD->LF_AR_Q12, Tilt_Q14 );\r
-\r
-            n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( psDD->Shape_Q10[ *smpl_buf_idx ], LF_shp_Q14 ), 2 ); \r
-            n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, psDD->LF_AR_Q12, LF_shp_Q14 );       \r
-\r
-            /* Input minus prediction plus noise feedback                       */\r
-            /* r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP  */\r
-            tmp1  = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 );                       /* Add Q14 stuff */\r
-            tmp1  = SKP_RSHIFT( tmp1, 4 );                                      /* convert to Q10 */\r
-            tmp1  = SKP_ADD32( tmp1, LPC_pred_Q10 );                            /* add Q10 stuff */ \r
-            tmp1  = SKP_SUB32( tmp1, n_AR_Q10 );                                /* subtract Q10 stuff */ \r
-            tmp1  = SKP_SUB32( tmp1, n_LF_Q10 );                                /* subtract Q10 stuff */ \r
-            r_Q10 = SKP_SUB32( x_Q10[ i ], tmp1 );                              /* residual error Q10 */\r
-            \r
-            /* Flip sign depending on dither */\r
-            r_Q10 = ( r_Q10 ^ dither ) - dither;\r
-            r_Q10 = SKP_SUB32( r_Q10, offset_Q10 );\r
-            r_Q10 = SKP_LIMIT_32( r_Q10, -64 << 10, 64 << 10 );\r
-\r
-            /* Find two quantization level candidates and measure their rate-distortion */\r
-            if( r_Q10 < -1536 ) {\r
-                q1_Q10  = SKP_LSHIFT( SKP_RSHIFT_ROUND( r_Q10, 10 ), 10 );\r
-                r_Q10   = SKP_SUB32( r_Q10, q1_Q10 );\r
-                rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( SKP_MUL( -SKP_ADD32( q1_Q10, offset_Q10 ), Lambda_Q10 ), r_Q10, r_Q10 ), 10 );\r
-                rd2_Q10 = SKP_ADD32( rd1_Q10, 1024 );\r
-                rd2_Q10 = SKP_SUB32( rd2_Q10, SKP_ADD_LSHIFT32( Lambda_Q10, r_Q10, 1 ) );\r
-                q2_Q10  = SKP_ADD32( q1_Q10, 1024 );\r
-            } else if( r_Q10 > 512 ) {\r
-                q1_Q10  = SKP_LSHIFT( SKP_RSHIFT_ROUND( r_Q10, 10 ), 10 );\r
-                r_Q10   = SKP_SUB32( r_Q10, q1_Q10 );\r
-                rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( SKP_MUL( SKP_ADD32( q1_Q10, offset_Q10 ), Lambda_Q10 ), r_Q10, r_Q10 ), 10 );\r
-                rd2_Q10 = SKP_ADD32( rd1_Q10, 1024 );\r
-                rd2_Q10 = SKP_SUB32( rd2_Q10, SKP_SUB_LSHIFT32( Lambda_Q10, r_Q10, 1 ) );\r
-                q2_Q10  = SKP_SUB32( q1_Q10, 1024 );\r
-            } else {            /* r_Q10 >= -1536 && q1_Q10 <= 512 */\r
-                rr_Q20  = SKP_SMULBB( offset_Q10, Lambda_Q10 );\r
-                rd2_Q10 = SKP_RSHIFT( SKP_SMLABB( rr_Q20, r_Q10, r_Q10 ), 10 );\r
-                rd1_Q10 = SKP_ADD32( rd2_Q10, 1024 );\r
-                rd1_Q10 = SKP_ADD32( rd1_Q10, SKP_SUB_RSHIFT32( SKP_ADD_LSHIFT32( Lambda_Q10, r_Q10, 1 ), rr_Q20, 9 ) );\r
-                q1_Q10  = -1024;\r
-                q2_Q10  = 0;\r
-            }\r
-\r
-            if( rd1_Q10 < rd2_Q10 ) {\r
-                psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 ); \r
-                psSS[ 1 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd2_Q10 );\r
-                psSS[ 0 ].Q_Q10 = q1_Q10;\r
-                psSS[ 1 ].Q_Q10 = q2_Q10;\r
-            } else {\r
-                psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd2_Q10 );\r
-                psSS[ 1 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 );\r
-                psSS[ 0 ].Q_Q10 = q2_Q10;\r
-                psSS[ 1 ].Q_Q10 = q1_Q10;\r
-            }\r
-\r
-            /* Update states for best quantization */\r
-\r
-            /* Quantized excitation */\r
-            exc_Q10 = SKP_ADD32( offset_Q10, psSS[ 0 ].Q_Q10 );\r
-            exc_Q10 = ( exc_Q10 ^ dither ) - dither;\r
-\r
-            /* Add predictions */\r
-            LPC_exc_Q10 = exc_Q10 + SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 );\r
-            xq_Q10      = SKP_ADD32( LPC_exc_Q10, LPC_pred_Q10 );\r
-\r
-            /* Update states */\r
-            sLF_AR_shp_Q10         = SKP_SUB32(  xq_Q10, n_AR_Q10 );\r
-            psSS[ 0 ].sLTP_shp_Q10 = SKP_SUB32(  sLF_AR_shp_Q10, n_LF_Q10 );\r
-            psSS[ 0 ].LF_AR_Q12    = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );\r
-            psSS[ 0 ].xq_Q14       = SKP_LSHIFT( xq_Q10,         4 );\r
-            psSS[ 0 ].LPC_exc_Q16  = SKP_LSHIFT( LPC_exc_Q10,    6 );\r
-\r
-            /* Update states for second best quantization */\r
-\r
-            /* Quantized excitation */\r
-            exc_Q10 = SKP_ADD32( offset_Q10, psSS[ 1 ].Q_Q10 );\r
-            exc_Q10 = ( exc_Q10 ^ dither ) - dither;\r
-\r
-            /* Add predictions */\r
-            LPC_exc_Q10 = exc_Q10 + SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 );\r
-            xq_Q10      = SKP_ADD32( LPC_exc_Q10, LPC_pred_Q10 );\r
-\r
-            /* Update states */\r
-            sLF_AR_shp_Q10         = SKP_SUB32(  xq_Q10, n_AR_Q10 );\r
-            psSS[ 1 ].sLTP_shp_Q10 = SKP_SUB32(  sLF_AR_shp_Q10, n_LF_Q10 );\r
-            psSS[ 1 ].LF_AR_Q12    = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );\r
-            psSS[ 1 ].xq_Q14       = SKP_LSHIFT( xq_Q10,         4 );\r
-            psSS[ 1 ].LPC_exc_Q16  = SKP_LSHIFT( LPC_exc_Q10,    6 );\r
-        }\r
-\r
-        *smpl_buf_idx  = ( *smpl_buf_idx - 1 ) & DECISION_DELAY_MASK;                   /* Index to newest samples              */\r
-        last_smple_idx = ( *smpl_buf_idx + decisionDelay ) & DECISION_DELAY_MASK;       /* Index to decisionDelay old samples   */\r
-\r
-        /* Find winner */\r
-        RDmin_Q10 = psSampleState[ 0 ][ 0 ].RD_Q10;\r
-        Winner_ind = 0;\r
-        for( k = 1; k < nStatesDelayedDecision; k++ ) {\r
-            if( psSampleState[ k ][ 0 ].RD_Q10 < RDmin_Q10 ) {\r
-                RDmin_Q10   = psSampleState[ k ][ 0 ].RD_Q10;\r
-                Winner_ind = k;\r
-            }\r
-        }\r
-\r
-        /* Increase RD values of expired states */\r
-        Winner_rand_state = psDelDec[ Winner_ind ].RandState[ last_smple_idx ];\r
-        for( k = 0; k < nStatesDelayedDecision; k++ ) {\r
-            if( psDelDec[ k ].RandState[ last_smple_idx ] != Winner_rand_state ) {\r
-                psSampleState[ k ][ 0 ].RD_Q10 = SKP_ADD32( psSampleState[ k ][ 0 ].RD_Q10, ( SKP_int32_MAX >> 4 ) );\r
-                psSampleState[ k ][ 1 ].RD_Q10 = SKP_ADD32( psSampleState[ k ][ 1 ].RD_Q10, ( SKP_int32_MAX >> 4 ) );\r
-                SKP_assert( psSampleState[ k ][ 0 ].RD_Q10 >= 0 );\r
-            }\r
-        }\r
-\r
-        /* Find worst in first set and best in second set */\r
-        RDmax_Q10  = psSampleState[ 0 ][ 0 ].RD_Q10;\r
-        RDmin_Q10  = psSampleState[ 0 ][ 1 ].RD_Q10;\r
-        RDmax_ind = 0;\r
-        RDmin_ind = 0;\r
-        for( k = 1; k < nStatesDelayedDecision; k++ ) {\r
-            /* find worst in first set */\r
-            if( psSampleState[ k ][ 0 ].RD_Q10 > RDmax_Q10 ) {\r
-                RDmax_Q10  = psSampleState[ k ][ 0 ].RD_Q10;\r
-                RDmax_ind = k;\r
-            }\r
-            /* find best in second set */\r
-            if( psSampleState[ k ][ 1 ].RD_Q10 < RDmin_Q10 ) {\r
-                RDmin_Q10  = psSampleState[ k ][ 1 ].RD_Q10;\r
-                RDmin_ind = k;\r
-            }\r
-        }\r
-\r
-        /* Replace a state if best from second set outperforms worst in first set */\r
-        if( RDmin_Q10 < RDmax_Q10 ) {\r
-            SKP_Silk_copy_del_dec_state( &psDelDec[ RDmax_ind ], &psDelDec[ RDmin_ind ], i ); \r
-            SKP_memcpy( &psSampleState[ RDmax_ind ][ 0 ], &psSampleState[ RDmin_ind ][ 1 ], sizeof( NSQ_sample_struct ) );\r
-        }\r
-\r
-        /* Write samples from winner to output and long-term filter states */\r
-        psDD = &psDelDec[ Winner_ind ];\r
-        if( subfr > 0 || i >= decisionDelay ) {\r
-            q[  i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );\r
-            xq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( \r
-                SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );\r
-            NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay ] = psDD->Shape_Q10[ last_smple_idx ];\r
-            sLTP_Q16[          NSQ->sLTP_buf_idx     - decisionDelay ] = psDD->Pred_Q16[  last_smple_idx ];\r
-        }\r
-        NSQ->sLTP_shp_buf_idx++;\r
-        NSQ->sLTP_buf_idx++;\r
-\r
-        /* Update states */\r
-        for( k = 0; k < nStatesDelayedDecision; k++ ) {\r
-            psDD                                     = &psDelDec[ k ];\r
-            psSS                                     = &psSampleState[ k ][ 0 ];\r
-            psDD->LF_AR_Q12                          = psSS->LF_AR_Q12;\r
-            psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH + i ] = psSS->xq_Q14;\r
-            psDD->Xq_Q10[    *smpl_buf_idx ]         = SKP_RSHIFT( psSS->xq_Q14, 4 );\r
-            psDD->Q_Q10[     *smpl_buf_idx ]         = psSS->Q_Q10;\r
-            psDD->Pred_Q16[  *smpl_buf_idx ]         = psSS->LPC_exc_Q16;\r
-            psDD->Shape_Q10[ *smpl_buf_idx ]         = psSS->sLTP_shp_Q10;\r
-            psDD->Seed                               = SKP_ADD_RSHIFT32( psDD->Seed, psSS->Q_Q10, 10 );\r
-            psDD->RandState[ *smpl_buf_idx ]         = psDD->Seed;\r
-            psDD->RD_Q10                             = psSS->RD_Q10;\r
-            psDD->Gain_Q16[  *smpl_buf_idx ]         = Gain_Q16;\r
-        }\r
-    }\r
-    /* Update LPC states */\r
-    for( k = 0; k < nStatesDelayedDecision; k++ ) {\r
-        psDD = &psDelDec[ k ];\r
-        SKP_memcpy( psDD->sLPC_Q14, &psDD->sLPC_Q14[ length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );\r
-    }\r
-}\r
-\r
-SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(\r
-    SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */\r
-    NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */\r
-    const SKP_int16     x[],                    /* I    Input in Q0                         */\r
-    SKP_int32           x_sc_Q10[],             /* O    Input scaled with 1/Gain in Q10     */\r
-    SKP_int             subfr_length,           /* I    Length of input                     */\r
-    const SKP_int16     sLTP[],                 /* I    Re-whitened LTP state in Q0         */\r
-    SKP_int32           sLTP_Q16[],             /* O    LTP state matching scaled input     */\r
-    SKP_int             subfr,                  /* I    Subframe number                     */\r
-    SKP_int             nStatesDelayedDecision, /* I    Number of del dec states            */\r
-    SKP_int             smpl_buf_idx,           /* I    Index to newest samples in buffers  */\r
-    const SKP_int       LTP_scale_Q14,          /* I    LTP state scaling                   */\r
-    const SKP_int32     Gains_Q16[ NB_SUBFR ],  /* I                                        */\r
-    const SKP_int       pitchL[ NB_SUBFR ]      /* I    Pitch lag                           */\r
-)\r
-{\r
-    SKP_int            i, k, lag;\r
-    SKP_int32          inv_gain_Q16, gain_adj_Q16, inv_gain_Q32;\r
-    NSQ_del_dec_struct *psDD;\r
-\r
-    inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gains_Q16[ subfr ], 1 ), 32 );\r
-    inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );\r
-    lag          = pitchL[ subfr ];\r
-\r
-    /* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */\r
-    if( NSQ->rewhite_flag ) {\r
-        inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 );\r
-        if( subfr == 0 ) {\r
-            /* Do LTP downscaling */\r
-            inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, LTP_scale_Q14 ), 2 );\r
-        }\r
-        for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {\r
-            SKP_assert( i < MAX_FRAME_LENGTH );\r
-            sLTP_Q16[ i ] = SKP_SMULWB( inv_gain_Q32, sLTP[ i ] );\r
-        }\r
-    }\r
-\r
-    /* Adjust for changing gain */\r
-    if( inv_gain_Q16 != NSQ->prev_inv_gain_Q16 ) {\r
-        gain_adj_Q16 = SKP_DIV32_varQ( inv_gain_Q16, NSQ->prev_inv_gain_Q16, 16 );\r
-\r
-        /* Scale long-term shaping state */\r
-        for( i = NSQ->sLTP_shp_buf_idx - subfr_length * NB_SUBFR; i < NSQ->sLTP_shp_buf_idx; i++ ) {\r
-            NSQ->sLTP_shp_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q10[ i ] );\r
-        }\r
-\r
-        /* Scale long-term prediction state */\r
-        if( NSQ->rewhite_flag == 0 ) {\r
-            for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {\r
-                sLTP_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, sLTP_Q16[ i ] );\r
-            }\r
-        }\r
-\r
-        for( k = 0; k < nStatesDelayedDecision; k++ ) {\r
-            psDD = &psDelDec[ k ];\r
-            \r
-            /* Scale scalar states */\r
-            psDD->LF_AR_Q12 = SKP_SMULWW( gain_adj_Q16, psDD->LF_AR_Q12 );\r
-            \r
-               /* Scale short-term prediction and shaping states */\r
-            for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) {\r
-                psDD->sLPC_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->sLPC_Q14[ i ] );\r
-            }\r
-            for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) {\r
-                psDD->sAR2_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->sAR2_Q14[ i ] );\r
-            }\r
-            for( i = 0; i < DECISION_DELAY; i++ ) {\r
-                psDD->Pred_Q16[  i ] = SKP_SMULWW( gain_adj_Q16, psDD->Pred_Q16[  i ] );\r
-                psDD->Shape_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->Shape_Q10[ i ] );\r
-            }\r
-        }\r
-    }\r
-\r
-    /* Scale input */\r
-    for( i = 0; i < subfr_length; i++ ) {\r
-        x_sc_Q10[ i ] = SKP_RSHIFT( SKP_SMULBB( x[ i ], ( SKP_int16 )inv_gain_Q16 ), 6 );\r
-    }\r
-\r
-    /* save inv_gain */\r
-    SKP_assert( inv_gain_Q16 != 0 );\r
-    NSQ->prev_inv_gain_Q16 = inv_gain_Q16;\r
-}\r
-\r
-SKP_INLINE void SKP_Silk_copy_del_dec_state(\r
-    NSQ_del_dec_struct  *DD_dst,                /* I    Dst del dec state                   */\r
-    NSQ_del_dec_struct  *DD_src,                /* I    Src del dec state                   */\r
-    SKP_int             LPC_state_idx           /* I    Index to LPC buffer                 */\r
-)\r
-{\r
-    SKP_memcpy( DD_dst->RandState, DD_src->RandState, sizeof( DD_src->RandState ) );\r
-    SKP_memcpy( DD_dst->Q_Q10,     DD_src->Q_Q10,     sizeof( DD_src->Q_Q10     ) );\r
-    SKP_memcpy( DD_dst->Pred_Q16,  DD_src->Pred_Q16,  sizeof( DD_src->Pred_Q16  ) );\r
-    SKP_memcpy( DD_dst->Shape_Q10, DD_src->Shape_Q10, sizeof( DD_src->Shape_Q10 ) );\r
-    SKP_memcpy( DD_dst->Xq_Q10,    DD_src->Xq_Q10,    sizeof( DD_src->Xq_Q10    ) );\r
-    SKP_memcpy( DD_dst->sAR2_Q14,  DD_src->sAR2_Q14,  sizeof( DD_src->sAR2_Q14  ) );\r
-    SKP_memcpy( &DD_dst->sLPC_Q14[ LPC_state_idx ], &DD_src->sLPC_Q14[ LPC_state_idx ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );\r
-    DD_dst->LF_AR_Q12 = DD_src->LF_AR_Q12;\r
-    DD_dst->Seed      = DD_src->Seed;\r
-    DD_dst->SeedInit  = DD_src->SeedInit;\r
-    DD_dst->RD_Q10    = DD_src->RD_Q10;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+typedef struct {
+    SKP_int32 RandState[ DECISION_DELAY ];
+    SKP_int32 Q_Q10[     DECISION_DELAY ];
+    SKP_int32 Xq_Q10[    DECISION_DELAY ];
+    SKP_int32 Pred_Q16[  DECISION_DELAY ];
+    SKP_int32 Shape_Q10[ DECISION_DELAY ];
+    SKP_int32 Gain_Q16[  DECISION_DELAY ];
+    SKP_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ];
+    SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / NB_SUBFR + NSQ_LPC_BUF_LENGTH ];
+    SKP_int32 LF_AR_Q12;
+    SKP_int32 Seed;
+    SKP_int32 SeedInit;
+    SKP_int32 RD_Q10;
+} NSQ_del_dec_struct;
+
+typedef struct {
+    SKP_int32 Q_Q10;
+    SKP_int32 RD_Q10;
+    SKP_int32 xq_Q14;
+    SKP_int32 LF_AR_Q12;
+    SKP_int32 sLTP_shp_Q10;
+    SKP_int32 LPC_exc_Q16;
+} NSQ_sample_struct;
+
+SKP_INLINE void SKP_Silk_copy_del_dec_state(
+    NSQ_del_dec_struct  *DD_dst,                /* I    Dst del dec state                   */
+    NSQ_del_dec_struct  *DD_src,                /* I    Src del dec state                   */
+    SKP_int             LPC_state_idx           /* I    Index to LPC buffer                 */
+);
+
+SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(
+    SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */
+    NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */
+    const SKP_int16     x[],                    /* I    Input in Q0                         */
+    SKP_int32           x_sc_Q10[],             /* O    Input scaled with 1/Gain in Q10     */
+    SKP_int             subfr_length,           /* I    Length of input                     */
+    const SKP_int16     sLTP[],                 /* I    Re-whitened LTP state in Q0         */
+    SKP_int32           sLTP_Q16[],             /* O    LTP state matching scaled input     */
+    SKP_int             subfr,                  /* I    Subframe number                     */
+    SKP_int             nStatesDelayedDecision, /* I    Number of del dec states            */
+    SKP_int             smpl_buf_idx,           /* I    Index to newest samples in buffers  */
+    const SKP_int       LTP_scale_Q14,          /* I    LTP state scaling                   */
+    const SKP_int32     Gains_Q16[ NB_SUBFR ],  /* I                                        */
+    const SKP_int       pitchL[ NB_SUBFR ]      /* I    Pitch lag                           */
+);
+
+/******************************************/
+/* Noise shape quantizer for one subframe */
+/******************************************/
+SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
+    SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */
+    NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */
+    SKP_int             sigtype,                /* I    Signal type                         */
+    const SKP_int32     x_Q10[],                /* I                                        */
+    SKP_int8            q[],                    /* O                                        */
+    SKP_int16           xq[],                   /* O                                        */
+    SKP_int32           sLTP_Q16[],             /* I/O  LTP filter state                    */
+    const SKP_int16     a_Q12[],                /* I    Short term prediction coefs         */
+    const SKP_int16     b_Q14[],                /* I    Long term prediction coefs          */
+    const SKP_int16     AR_shp_Q13[],           /* I    Noise shaping coefs                 */
+    SKP_int             lag,                    /* I    Pitch lag                           */
+    SKP_int32           HarmShapeFIRPacked_Q14, /* I                                        */
+    SKP_int             Tilt_Q14,               /* I    Spectral tilt                       */
+    SKP_int32           LF_shp_Q14,             /* I                                        */
+    SKP_int32           Gain_Q16,               /* I                                        */
+    SKP_int             Lambda_Q10,             /* I                                        */
+    SKP_int             offset_Q10,             /* I                                        */
+    SKP_int             length,                 /* I    Input length                        */
+    SKP_int             subfr,                  /* I    Subframe number                     */
+    SKP_int             shapingLPCOrder,        /* I    Shaping LPC filter order            */
+    SKP_int             predictLPCOrder,        /* I    Prediction filter order             */
+    SKP_int             warping_Q16,            /* I                                        */
+    SKP_int             nStatesDelayedDecision, /* I    Number of states in decision tree   */
+    SKP_int             *smpl_buf_idx,          /* I    Index to newest samples in buffers  */
+    SKP_int             decisionDelay           /* I                                        */
+);
+
+void SKP_Silk_NSQ_del_dec(
+    SKP_Silk_encoder_state          *psEncC,                                    /* I/O  Encoder State                       */
+    SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */
+    SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */
+    const SKP_int16                 x[],                                        /* I    Prefiltered input signal            */
+    SKP_int8                        q[],                                        /* O    Quantized pulse signal              */
+    const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */
+    const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Prediction coefs                    */
+    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    LT prediction coefs                 */
+    const SKP_int16                 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ],  /* I                                        */
+    const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */
+    const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */
+    const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */
+    const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */
+    const SKP_int                   Lambda_Q10,                                 /* I                                        */
+    const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */
+)
+{
+    SKP_int     i, k, lag, start_idx, LSF_interpolation_flag, Winner_ind, subfr;
+    SKP_int     last_smple_idx, smpl_buf_idx, decisionDelay, subfr_length;
+    const SKP_int16 *A_Q12, *B_Q14, *AR_shp_Q13;
+    SKP_int16   *pxq;
+    SKP_int32   sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];
+    SKP_int16   sLTP[     2 * MAX_FRAME_LENGTH ];
+    SKP_int32   HarmShapeFIRPacked_Q14;
+    SKP_int     offset_Q10;
+    SKP_int32   FiltState[ MAX_LPC_ORDER ], RDmin_Q10;
+    SKP_int32   x_sc_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ];
+    NSQ_del_dec_struct psDelDec[ MAX_DEL_DEC_STATES ];
+    NSQ_del_dec_struct *psDD;
+
+    subfr_length = psEncC->frame_length / NB_SUBFR;
+
+    /* Set unvoiced lag to the previous one, overwrite later for voiced */
+    lag = NSQ->lagPrev;
+
+    SKP_assert( NSQ->prev_inv_gain_Q16 != 0 );
+
+    /* Initialize delayed decision states */
+    SKP_memset( psDelDec, 0, psEncC->nStatesDelayedDecision * sizeof( NSQ_del_dec_struct ) );
+    for( k = 0; k < psEncC->nStatesDelayedDecision; k++ ) {
+        psDD                 = &psDelDec[ k ];
+        psDD->Seed           = ( k + psEncCtrlC->Seed ) & 3;
+        psDD->SeedInit       = psDD->Seed;
+        psDD->RD_Q10         = 0;
+        psDD->LF_AR_Q12      = NSQ->sLF_AR_shp_Q12;
+        psDD->Shape_Q10[ 0 ] = NSQ->sLTP_shp_Q10[ psEncC->frame_length - 1 ];
+        SKP_memcpy( psDD->sLPC_Q14, NSQ->sLPC_Q14, NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
+        SKP_memcpy( psDD->sAR2_Q14, NSQ->sAR2_Q14, sizeof( NSQ->sAR2_Q14 ) );
+    }
+
+    offset_Q10   = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrlC->sigtype ][ psEncCtrlC->QuantOffsetType ];
+    smpl_buf_idx = 0; /* index of oldest samples */
+
+    decisionDelay = SKP_min_int( DECISION_DELAY, subfr_length );
+
+    /* For voiced frames limit the decision delay to lower than the pitch lag */
+    if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
+        for( k = 0; k < NB_SUBFR; k++ ) {
+            decisionDelay = SKP_min_int( decisionDelay, psEncCtrlC->pitchL[ k ] - LTP_ORDER / 2 - 1 );
+        }
+    } else {
+        if( lag > 0 ) {
+            decisionDelay = SKP_min_int( decisionDelay, lag - LTP_ORDER / 2 - 1 );
+        }
+    }
+
+    if( LSFInterpFactor_Q2 == ( 1 << 2 ) ) {
+        LSF_interpolation_flag = 0;
+    } else {
+        LSF_interpolation_flag = 1;
+    }
+
+    /* Setup pointers to start of sub frame */
+    pxq                   = &NSQ->xq[ psEncC->frame_length ];
+    NSQ->sLTP_shp_buf_idx = psEncC->frame_length;
+    NSQ->sLTP_buf_idx     = psEncC->frame_length;
+    subfr = 0;
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        A_Q12      = &PredCoef_Q12[ ( ( k >> 1 ) | ( 1 - LSF_interpolation_flag ) ) * MAX_LPC_ORDER ];
+        B_Q14      = &LTPCoef_Q14[ k * LTP_ORDER           ];
+        AR_shp_Q13 = &AR2_Q13[     k * MAX_SHAPE_LPC_ORDER ];
+
+        /* Noise shape parameters */
+        SKP_assert( HarmShapeGain_Q14[ k ] >= 0 );
+        HarmShapeFIRPacked_Q14  =                          SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 );
+        HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 );
+
+        NSQ->rewhite_flag = 0;
+        if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
+            /* Voiced */
+            lag = psEncCtrlC->pitchL[ k ];
+
+            /* Re-whitening */
+            if( ( k & ( 3 - SKP_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) {
+                if( k == 2 ) {
+                    /* RESET DELAYED DECISIONS */
+                    /* Find winner */
+                    RDmin_Q10 = psDelDec[ 0 ].RD_Q10;
+                    Winner_ind = 0;
+                    for( i = 1; i < psEncC->nStatesDelayedDecision; i++ ) {
+                        if( psDelDec[ i ].RD_Q10 < RDmin_Q10 ) {
+                            RDmin_Q10 = psDelDec[ i ].RD_Q10;
+                            Winner_ind = i;
+                        }
+                    }
+                    for( i = 0; i < psEncC->nStatesDelayedDecision; i++ ) {
+                        if( i != Winner_ind ) {
+                            psDelDec[ i ].RD_Q10 += ( SKP_int32_MAX >> 4 );
+                            SKP_assert( psDelDec[ i ].RD_Q10 >= 0 );
+                        }
+                    }
+                    
+                    /* Copy final part of signals from winner state to output and long-term filter states */
+                    psDD = &psDelDec[ Winner_ind ];
+                    last_smple_idx = smpl_buf_idx + decisionDelay;
+                    for( i = 0; i < decisionDelay; i++ ) {
+                        last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;
+                        q[   i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
+                        pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( 
+                            SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], 
+                            psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
+                        NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];
+                    }
+
+                    subfr = 0;
+                }
+
+                /* Rewhiten with new A coefs */
+                start_idx = psEncC->frame_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2;
+                SKP_assert( start_idx >= 0 );
+                SKP_assert( start_idx <= psEncC->frame_length - psEncC->predictLPCOrder );
+
+                SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) );
+                SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * psEncC->subfr_length ], 
+                    A_Q12, FiltState, sLTP + start_idx, psEncC->frame_length - start_idx, psEncC->predictLPCOrder );
+
+                NSQ->sLTP_buf_idx = psEncC->frame_length;
+                NSQ->rewhite_flag = 1;
+            }
+        }
+
+        SKP_Silk_nsq_del_dec_scale_states( NSQ, psDelDec, x, x_sc_Q10, 
+            subfr_length, sLTP, sLTP_Q16, k, psEncC->nStatesDelayedDecision, smpl_buf_idx,
+            LTP_scale_Q14, Gains_Q16, psEncCtrlC->pitchL );
+
+        SKP_Silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psEncCtrlC->sigtype, x_sc_Q10, q, pxq, sLTP_Q16,
+            A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], 
+            Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder, psEncC->predictLPCOrder, 
+            psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay );
+        
+        x   += psEncC->subfr_length;
+        q   += psEncC->subfr_length;
+        pxq += psEncC->subfr_length;
+    }
+
+    /* Find winner */
+    RDmin_Q10 = psDelDec[ 0 ].RD_Q10;
+    Winner_ind = 0;
+    for( k = 1; k < psEncC->nStatesDelayedDecision; k++ ) {
+        if( psDelDec[ k ].RD_Q10 < RDmin_Q10 ) {
+            RDmin_Q10 = psDelDec[ k ].RD_Q10;
+            Winner_ind = k;
+        }
+    }
+    
+    /* Copy final part of signals from winner state to output and long-term filter states */
+    psDD = &psDelDec[ Winner_ind ];
+    psEncCtrlC->Seed = psDD->SeedInit;
+    last_smple_idx = smpl_buf_idx + decisionDelay;
+    for( i = 0; i < decisionDelay; i++ ) {
+        last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;
+        q[   i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
+        pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( 
+            SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
+        NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];
+        sLTP_Q16[          NSQ->sLTP_buf_idx     - decisionDelay + i ] = psDD->Pred_Q16[  last_smple_idx ];
+    }
+    SKP_memcpy( NSQ->sLPC_Q14, &psDD->sLPC_Q14[ psEncC->subfr_length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
+    SKP_memcpy( NSQ->sAR2_Q14, psDD->sAR2_Q14, sizeof( psDD->sAR2_Q14 ) );
+
+    /* Update states */
+    NSQ->sLF_AR_shp_Q12 = psDD->LF_AR_Q12;
+    NSQ->lagPrev        = psEncCtrlC->pitchL[ NB_SUBFR - 1 ];
+
+    /* Save quantized speech and noise shaping signals */
+    SKP_memcpy( NSQ->xq,           &NSQ->xq[           psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) );
+    SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) );
+
+#ifdef USE_UNQUANTIZED_LSFS
+    DEBUG_STORE_DATA( xq_unq_lsfs.pcm, NSQ->xq, psEncC->frame_length * sizeof( SKP_int16 ) );
+#endif
+
+}
+
+/******************************************/
+/* Noise shape quantizer for one subframe */
+/******************************************/
+SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
+    SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */
+    NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */
+    SKP_int             sigtype,                /* I    Signal type                         */
+    const SKP_int32     x_Q10[],                /* I                                        */
+    SKP_int8            q[],                    /* O                                        */
+    SKP_int16           xq[],                   /* O                                        */
+    SKP_int32           sLTP_Q16[],             /* I/O  LTP filter state                    */
+    const SKP_int16     a_Q12[],                /* I    Short term prediction coefs         */
+    const SKP_int16     b_Q14[],                /* I    Long term prediction coefs          */
+    const SKP_int16     AR_shp_Q13[],           /* I    Noise shaping coefs                 */
+    SKP_int             lag,                    /* I    Pitch lag                           */
+    SKP_int32           HarmShapeFIRPacked_Q14, /* I                                        */
+    SKP_int             Tilt_Q14,               /* I    Spectral tilt                       */
+    SKP_int32           LF_shp_Q14,             /* I                                        */
+    SKP_int32           Gain_Q16,               /* I                                        */
+    SKP_int             Lambda_Q10,             /* I                                        */
+    SKP_int             offset_Q10,             /* I                                        */
+    SKP_int             length,                 /* I    Input length                        */
+    SKP_int             subfr,                  /* I    Subframe number                     */
+    SKP_int             shapingLPCOrder,        /* I    Shaping LPC filter order            */
+    SKP_int             predictLPCOrder,        /* I    Prediction filter order             */
+    SKP_int             warping_Q16,            /* I                                        */
+    SKP_int             nStatesDelayedDecision, /* I    Number of states in decision tree   */
+    SKP_int             *smpl_buf_idx,          /* I    Index to newest samples in buffers  */
+    SKP_int             decisionDelay           /* I                                        */
+)
+{
+    SKP_int     i, j, k, Winner_ind, RDmin_ind, RDmax_ind, last_smple_idx;
+    SKP_int32   Winner_rand_state;
+    SKP_int32   LTP_pred_Q14, LPC_pred_Q10, n_AR_Q10, n_LTP_Q14;
+    SKP_int32   n_LF_Q10, r_Q10, rr_Q20, rd1_Q10, rd2_Q10, RDmin_Q10, RDmax_Q10;
+    SKP_int32   q1_Q10, q2_Q10, dither, exc_Q10, LPC_exc_Q10, xq_Q10;
+    SKP_int32   tmp1, tmp2, sLF_AR_shp_Q10;
+    SKP_int32   *pred_lag_ptr, *shp_lag_ptr, *psLPC_Q14;
+    NSQ_sample_struct  psSampleState[ MAX_DEL_DEC_STATES ][ 2 ];
+    NSQ_del_dec_struct *psDD;
+    NSQ_sample_struct  *psSS;
+
+    shp_lag_ptr  = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ];
+    pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ];
+
+    for( i = 0; i < length; i++ ) {
+        /* Perform common calculations used in all states */
+
+        /* Long-term prediction */
+        if( sigtype == SIG_TYPE_VOICED ) {
+            /* Unrolled loop */
+            LTP_pred_Q14 = SKP_SMULWB(               pred_lag_ptr[  0 ], b_Q14[ 0 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], b_Q14[ 1 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], b_Q14[ 2 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], b_Q14[ 3 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], b_Q14[ 4 ] );
+            pred_lag_ptr++;
+        } else {
+            LTP_pred_Q14 = 0;
+        }
+
+        /* Long-term shaping */
+        if( lag > 0 ) {
+            /* Symmetric, packed FIR coefficients */
+            n_LTP_Q14 = SKP_SMULWB( SKP_ADD32( shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ] ), HarmShapeFIRPacked_Q14 );
+            n_LTP_Q14 = SKP_SMLAWT( n_LTP_Q14, shp_lag_ptr[ -1 ],                     HarmShapeFIRPacked_Q14 );
+            n_LTP_Q14 = SKP_LSHIFT( n_LTP_Q14, 6 );
+            shp_lag_ptr++;
+        } else {
+            n_LTP_Q14 = 0;
+        }
+
+        for( k = 0; k < nStatesDelayedDecision; k++ ) {
+            /* Delayed decision state */
+            psDD = &psDelDec[ k ];
+
+            /* Sample state */
+            psSS = psSampleState[ k ];
+
+            /* Generate dither */
+            psDD->Seed = SKP_RAND( psDD->Seed );
+
+            /* dither = rand_seed < 0 ? 0xFFFFFFFF : 0; */
+            dither = SKP_RSHIFT( psDD->Seed, 31 );
+            
+            /* Pointer used in short term prediction and shaping */
+            psLPC_Q14 = &psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 + i ];
+            /* Short-term prediction */
+            SKP_assert( predictLPCOrder >= 10 );            /* check that unrolling works */
+            SKP_assert( ( predictLPCOrder  & 1 ) == 0 );    /* check that order is even */
+            SKP_assert( ( ( ( int )( ( char* )( a_Q12 ) - ( ( char* ) 0 ) ) ) & 3 ) == 0 );    /* check that array starts at 4-byte aligned address */
+            /* Partially unrolled */
+            LPC_pred_Q10 = SKP_SMULWB(               psLPC_Q14[  0 ], a_Q12[ 0 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -1 ], a_Q12[ 1 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], a_Q12[ 2 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -3 ], a_Q12[ 3 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], a_Q12[ 4 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -5 ], a_Q12[ 5 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], a_Q12[ 6 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -7 ], a_Q12[ 7 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], a_Q12[ 8 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -9 ], a_Q12[ 9 ] );
+            for( j = 10; j < predictLPCOrder; j ++ ) {
+                LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], a_Q12[ j ] );
+            }
+
+            /* Noise shape feedback */
+            SKP_assert( ( shapingLPCOrder & 1 ) == 0 );   /* check that order is even */
+            /* Output of lowpass section */
+            tmp2 = SKP_SMLAWB( psLPC_Q14[ 0 ], psDD->sAR2_Q14[ 0 ], warping_Q16 );
+            /* Output of allpass section */
+            tmp1 = SKP_SMLAWB( psDD->sAR2_Q14[ 0 ], psDD->sAR2_Q14[ 1 ] - tmp2, warping_Q16 );
+            psDD->sAR2_Q14[ 0 ] = tmp2;
+            n_AR_Q10 = SKP_SMULWB( tmp2, AR_shp_Q13[ 0 ] );
+            /* Loop over allpass sections */
+            for( j = 2; j < shapingLPCOrder; j += 2 ) {
+                /* Output of allpass section */
+                tmp2 = SKP_SMLAWB( psDD->sAR2_Q14[ j - 1 ], psDD->sAR2_Q14[ j + 0 ] - tmp1, warping_Q16 );
+                psDD->sAR2_Q14[ j - 1 ] = tmp1;
+                n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ j - 1 ] );
+                /* Output of allpass section */
+                tmp1 = SKP_SMLAWB( psDD->sAR2_Q14[ j + 0 ], psDD->sAR2_Q14[ j + 1 ] - tmp2, warping_Q16 );
+                psDD->sAR2_Q14[ j + 0 ] = tmp2;
+                n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp2, AR_shp_Q13[ j ] );
+            }
+            psDD->sAR2_Q14[ shapingLPCOrder - 1 ] = tmp1;
+            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ shapingLPCOrder - 1 ] );
+
+            n_AR_Q10 = SKP_RSHIFT( n_AR_Q10, 1 );           /* Q11 -> Q10 */
+            n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psDD->LF_AR_Q12, Tilt_Q14 );
+
+            n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( psDD->Shape_Q10[ *smpl_buf_idx ], LF_shp_Q14 ), 2 ); 
+            n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, psDD->LF_AR_Q12, LF_shp_Q14 );       
+
+            /* Input minus prediction plus noise feedback                       */
+            /* r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP  */
+            tmp1  = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 );                       /* Add Q14 stuff */
+            tmp1  = SKP_RSHIFT( tmp1, 4 );                                      /* convert to Q10 */
+            tmp1  = SKP_ADD32( tmp1, LPC_pred_Q10 );                            /* add Q10 stuff */ 
+            tmp1  = SKP_SUB32( tmp1, n_AR_Q10 );                                /* subtract Q10 stuff */ 
+            tmp1  = SKP_SUB32( tmp1, n_LF_Q10 );                                /* subtract Q10 stuff */ 
+            r_Q10 = SKP_SUB32( x_Q10[ i ], tmp1 );                              /* residual error Q10 */
+            
+            /* Flip sign depending on dither */
+            r_Q10 = ( r_Q10 ^ dither ) - dither;
+            r_Q10 = SKP_SUB32( r_Q10, offset_Q10 );
+            r_Q10 = SKP_LIMIT_32( r_Q10, -64 << 10, 64 << 10 );
+
+            /* Find two quantization level candidates and measure their rate-distortion */
+            if( r_Q10 < -1536 ) {
+                q1_Q10  = SKP_LSHIFT( SKP_RSHIFT_ROUND( r_Q10, 10 ), 10 );
+                r_Q10   = SKP_SUB32( r_Q10, q1_Q10 );
+                rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( SKP_MUL( -SKP_ADD32( q1_Q10, offset_Q10 ), Lambda_Q10 ), r_Q10, r_Q10 ), 10 );
+                rd2_Q10 = SKP_ADD32( rd1_Q10, 1024 );
+                rd2_Q10 = SKP_SUB32( rd2_Q10, SKP_ADD_LSHIFT32( Lambda_Q10, r_Q10, 1 ) );
+                q2_Q10  = SKP_ADD32( q1_Q10, 1024 );
+            } else if( r_Q10 > 512 ) {
+                q1_Q10  = SKP_LSHIFT( SKP_RSHIFT_ROUND( r_Q10, 10 ), 10 );
+                r_Q10   = SKP_SUB32( r_Q10, q1_Q10 );
+                rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( SKP_MUL( SKP_ADD32( q1_Q10, offset_Q10 ), Lambda_Q10 ), r_Q10, r_Q10 ), 10 );
+                rd2_Q10 = SKP_ADD32( rd1_Q10, 1024 );
+                rd2_Q10 = SKP_SUB32( rd2_Q10, SKP_SUB_LSHIFT32( Lambda_Q10, r_Q10, 1 ) );
+                q2_Q10  = SKP_SUB32( q1_Q10, 1024 );
+            } else {            /* r_Q10 >= -1536 && q1_Q10 <= 512 */
+                rr_Q20  = SKP_SMULBB( offset_Q10, Lambda_Q10 );
+                rd2_Q10 = SKP_RSHIFT( SKP_SMLABB( rr_Q20, r_Q10, r_Q10 ), 10 );
+                rd1_Q10 = SKP_ADD32( rd2_Q10, 1024 );
+                rd1_Q10 = SKP_ADD32( rd1_Q10, SKP_SUB_RSHIFT32( SKP_ADD_LSHIFT32( Lambda_Q10, r_Q10, 1 ), rr_Q20, 9 ) );
+                q1_Q10  = -1024;
+                q2_Q10  = 0;
+            }
+
+            if( rd1_Q10 < rd2_Q10 ) {
+                psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 ); 
+                psSS[ 1 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd2_Q10 );
+                psSS[ 0 ].Q_Q10 = q1_Q10;
+                psSS[ 1 ].Q_Q10 = q2_Q10;
+            } else {
+                psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd2_Q10 );
+                psSS[ 1 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 );
+                psSS[ 0 ].Q_Q10 = q2_Q10;
+                psSS[ 1 ].Q_Q10 = q1_Q10;
+            }
+
+            /* Update states for best quantization */
+
+            /* Quantized excitation */
+            exc_Q10 = SKP_ADD32( offset_Q10, psSS[ 0 ].Q_Q10 );
+            exc_Q10 = ( exc_Q10 ^ dither ) - dither;
+
+            /* Add predictions */
+            LPC_exc_Q10 = exc_Q10 + SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 );
+            xq_Q10      = SKP_ADD32( LPC_exc_Q10, LPC_pred_Q10 );
+
+            /* Update states */
+            sLF_AR_shp_Q10         = SKP_SUB32(  xq_Q10, n_AR_Q10 );
+            psSS[ 0 ].sLTP_shp_Q10 = SKP_SUB32(  sLF_AR_shp_Q10, n_LF_Q10 );
+            psSS[ 0 ].LF_AR_Q12    = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );
+            psSS[ 0 ].xq_Q14       = SKP_LSHIFT( xq_Q10,         4 );
+            psSS[ 0 ].LPC_exc_Q16  = SKP_LSHIFT( LPC_exc_Q10,    6 );
+
+            /* Update states for second best quantization */
+
+            /* Quantized excitation */
+            exc_Q10 = SKP_ADD32( offset_Q10, psSS[ 1 ].Q_Q10 );
+            exc_Q10 = ( exc_Q10 ^ dither ) - dither;
+
+            /* Add predictions */
+            LPC_exc_Q10 = exc_Q10 + SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 );
+            xq_Q10      = SKP_ADD32( LPC_exc_Q10, LPC_pred_Q10 );
+
+            /* Update states */
+            sLF_AR_shp_Q10         = SKP_SUB32(  xq_Q10, n_AR_Q10 );
+            psSS[ 1 ].sLTP_shp_Q10 = SKP_SUB32(  sLF_AR_shp_Q10, n_LF_Q10 );
+            psSS[ 1 ].LF_AR_Q12    = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );
+            psSS[ 1 ].xq_Q14       = SKP_LSHIFT( xq_Q10,         4 );
+            psSS[ 1 ].LPC_exc_Q16  = SKP_LSHIFT( LPC_exc_Q10,    6 );
+        }
+
+        *smpl_buf_idx  = ( *smpl_buf_idx - 1 ) & DECISION_DELAY_MASK;                   /* Index to newest samples              */
+        last_smple_idx = ( *smpl_buf_idx + decisionDelay ) & DECISION_DELAY_MASK;       /* Index to decisionDelay old samples   */
+
+        /* Find winner */
+        RDmin_Q10 = psSampleState[ 0 ][ 0 ].RD_Q10;
+        Winner_ind = 0;
+        for( k = 1; k < nStatesDelayedDecision; k++ ) {
+            if( psSampleState[ k ][ 0 ].RD_Q10 < RDmin_Q10 ) {
+                RDmin_Q10   = psSampleState[ k ][ 0 ].RD_Q10;
+                Winner_ind = k;
+            }
+        }
+
+        /* Increase RD values of expired states */
+        Winner_rand_state = psDelDec[ Winner_ind ].RandState[ last_smple_idx ];
+        for( k = 0; k < nStatesDelayedDecision; k++ ) {
+            if( psDelDec[ k ].RandState[ last_smple_idx ] != Winner_rand_state ) {
+                psSampleState[ k ][ 0 ].RD_Q10 = SKP_ADD32( psSampleState[ k ][ 0 ].RD_Q10, ( SKP_int32_MAX >> 4 ) );
+                psSampleState[ k ][ 1 ].RD_Q10 = SKP_ADD32( psSampleState[ k ][ 1 ].RD_Q10, ( SKP_int32_MAX >> 4 ) );
+                SKP_assert( psSampleState[ k ][ 0 ].RD_Q10 >= 0 );
+            }
+        }
+
+        /* Find worst in first set and best in second set */
+        RDmax_Q10  = psSampleState[ 0 ][ 0 ].RD_Q10;
+        RDmin_Q10  = psSampleState[ 0 ][ 1 ].RD_Q10;
+        RDmax_ind = 0;
+        RDmin_ind = 0;
+        for( k = 1; k < nStatesDelayedDecision; k++ ) {
+            /* find worst in first set */
+            if( psSampleState[ k ][ 0 ].RD_Q10 > RDmax_Q10 ) {
+                RDmax_Q10  = psSampleState[ k ][ 0 ].RD_Q10;
+                RDmax_ind = k;
+            }
+            /* find best in second set */
+            if( psSampleState[ k ][ 1 ].RD_Q10 < RDmin_Q10 ) {
+                RDmin_Q10  = psSampleState[ k ][ 1 ].RD_Q10;
+                RDmin_ind = k;
+            }
+        }
+
+        /* Replace a state if best from second set outperforms worst in first set */
+        if( RDmin_Q10 < RDmax_Q10 ) {
+            SKP_Silk_copy_del_dec_state( &psDelDec[ RDmax_ind ], &psDelDec[ RDmin_ind ], i ); 
+            SKP_memcpy( &psSampleState[ RDmax_ind ][ 0 ], &psSampleState[ RDmin_ind ][ 1 ], sizeof( NSQ_sample_struct ) );
+        }
+
+        /* Write samples from winner to output and long-term filter states */
+        psDD = &psDelDec[ Winner_ind ];
+        if( subfr > 0 || i >= decisionDelay ) {
+            q[  i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
+            xq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( 
+                SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
+            NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay ] = psDD->Shape_Q10[ last_smple_idx ];
+            sLTP_Q16[          NSQ->sLTP_buf_idx     - decisionDelay ] = psDD->Pred_Q16[  last_smple_idx ];
+        }
+        NSQ->sLTP_shp_buf_idx++;
+        NSQ->sLTP_buf_idx++;
+
+        /* Update states */
+        for( k = 0; k < nStatesDelayedDecision; k++ ) {
+            psDD                                     = &psDelDec[ k ];
+            psSS                                     = &psSampleState[ k ][ 0 ];
+            psDD->LF_AR_Q12                          = psSS->LF_AR_Q12;
+            psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH + i ] = psSS->xq_Q14;
+            psDD->Xq_Q10[    *smpl_buf_idx ]         = SKP_RSHIFT( psSS->xq_Q14, 4 );
+            psDD->Q_Q10[     *smpl_buf_idx ]         = psSS->Q_Q10;
+            psDD->Pred_Q16[  *smpl_buf_idx ]         = psSS->LPC_exc_Q16;
+            psDD->Shape_Q10[ *smpl_buf_idx ]         = psSS->sLTP_shp_Q10;
+            psDD->Seed                               = SKP_ADD_RSHIFT32( psDD->Seed, psSS->Q_Q10, 10 );
+            psDD->RandState[ *smpl_buf_idx ]         = psDD->Seed;
+            psDD->RD_Q10                             = psSS->RD_Q10;
+            psDD->Gain_Q16[  *smpl_buf_idx ]         = Gain_Q16;
+        }
+    }
+    /* Update LPC states */
+    for( k = 0; k < nStatesDelayedDecision; k++ ) {
+        psDD = &psDelDec[ k ];
+        SKP_memcpy( psDD->sLPC_Q14, &psDD->sLPC_Q14[ length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
+    }
+}
+
+SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(
+    SKP_Silk_nsq_state  *NSQ,                   /* I/O  NSQ state                           */
+    NSQ_del_dec_struct  psDelDec[],             /* I/O  Delayed decision states             */
+    const SKP_int16     x[],                    /* I    Input in Q0                         */
+    SKP_int32           x_sc_Q10[],             /* O    Input scaled with 1/Gain in Q10     */
+    SKP_int             subfr_length,           /* I    Length of input                     */
+    const SKP_int16     sLTP[],                 /* I    Re-whitened LTP state in Q0         */
+    SKP_int32           sLTP_Q16[],             /* O    LTP state matching scaled input     */
+    SKP_int             subfr,                  /* I    Subframe number                     */
+    SKP_int             nStatesDelayedDecision, /* I    Number of del dec states            */
+    SKP_int             smpl_buf_idx,           /* I    Index to newest samples in buffers  */
+    const SKP_int       LTP_scale_Q14,          /* I    LTP state scaling                   */
+    const SKP_int32     Gains_Q16[ NB_SUBFR ],  /* I                                        */
+    const SKP_int       pitchL[ NB_SUBFR ]      /* I    Pitch lag                           */
+)
+{
+    SKP_int            i, k, lag;
+    SKP_int32          inv_gain_Q16, gain_adj_Q16, inv_gain_Q32;
+    NSQ_del_dec_struct *psDD;
+
+    inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gains_Q16[ subfr ], 1 ), 32 );
+    inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );
+    lag          = pitchL[ subfr ];
+
+    /* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */
+    if( NSQ->rewhite_flag ) {
+        inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 );
+        if( subfr == 0 ) {
+            /* Do LTP downscaling */
+            inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, LTP_scale_Q14 ), 2 );
+        }
+        for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
+            SKP_assert( i < MAX_FRAME_LENGTH );
+            sLTP_Q16[ i ] = SKP_SMULWB( inv_gain_Q32, sLTP[ i ] );
+        }
+    }
+
+    /* Adjust for changing gain */
+    if( inv_gain_Q16 != NSQ->prev_inv_gain_Q16 ) {
+        gain_adj_Q16 = SKP_DIV32_varQ( inv_gain_Q16, NSQ->prev_inv_gain_Q16, 16 );
+
+        /* Scale long-term shaping state */
+        for( i = NSQ->sLTP_shp_buf_idx - subfr_length * NB_SUBFR; i < NSQ->sLTP_shp_buf_idx; i++ ) {
+            NSQ->sLTP_shp_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q10[ i ] );
+        }
+
+        /* Scale long-term prediction state */
+        if( NSQ->rewhite_flag == 0 ) {
+            for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
+                sLTP_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, sLTP_Q16[ i ] );
+            }
+        }
+
+        for( k = 0; k < nStatesDelayedDecision; k++ ) {
+            psDD = &psDelDec[ k ];
+            
+            /* Scale scalar states */
+            psDD->LF_AR_Q12 = SKP_SMULWW( gain_adj_Q16, psDD->LF_AR_Q12 );
+            
+               /* Scale short-term prediction and shaping states */
+            for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) {
+                psDD->sLPC_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->sLPC_Q14[ i ] );
+            }
+            for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) {
+                psDD->sAR2_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->sAR2_Q14[ i ] );
+            }
+            for( i = 0; i < DECISION_DELAY; i++ ) {
+                psDD->Pred_Q16[  i ] = SKP_SMULWW( gain_adj_Q16, psDD->Pred_Q16[  i ] );
+                psDD->Shape_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->Shape_Q10[ i ] );
+            }
+        }
+    }
+
+    /* Scale input */
+    for( i = 0; i < subfr_length; i++ ) {
+        x_sc_Q10[ i ] = SKP_RSHIFT( SKP_SMULBB( x[ i ], ( SKP_int16 )inv_gain_Q16 ), 6 );
+    }
+
+    /* save inv_gain */
+    SKP_assert( inv_gain_Q16 != 0 );
+    NSQ->prev_inv_gain_Q16 = inv_gain_Q16;
+}
+
+SKP_INLINE void SKP_Silk_copy_del_dec_state(
+    NSQ_del_dec_struct  *DD_dst,                /* I    Dst del dec state                   */
+    NSQ_del_dec_struct  *DD_src,                /* I    Src del dec state                   */
+    SKP_int             LPC_state_idx           /* I    Index to LPC buffer                 */
+)
+{
+    SKP_memcpy( DD_dst->RandState, DD_src->RandState, sizeof( DD_src->RandState ) );
+    SKP_memcpy( DD_dst->Q_Q10,     DD_src->Q_Q10,     sizeof( DD_src->Q_Q10     ) );
+    SKP_memcpy( DD_dst->Pred_Q16,  DD_src->Pred_Q16,  sizeof( DD_src->Pred_Q16  ) );
+    SKP_memcpy( DD_dst->Shape_Q10, DD_src->Shape_Q10, sizeof( DD_src->Shape_Q10 ) );
+    SKP_memcpy( DD_dst->Xq_Q10,    DD_src->Xq_Q10,    sizeof( DD_src->Xq_Q10    ) );
+    SKP_memcpy( DD_dst->sAR2_Q14,  DD_src->sAR2_Q14,  sizeof( DD_src->sAR2_Q14  ) );
+    SKP_memcpy( &DD_dst->sLPC_Q14[ LPC_state_idx ], &DD_src->sLPC_Q14[ LPC_state_idx ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
+    DD_dst->LF_AR_Q12 = DD_src->LF_AR_Q12;
+    DD_dst->Seed      = DD_src->Seed;
+    DD_dst->SeedInit  = DD_src->SeedInit;
+    DD_dst->RD_Q10    = DD_src->RD_Q10;
+}
index 690ac0223e2c41d92c7675cec01641fd2fe8d9d1..61d0b9646acccc1c32d5483f8d593c46b4acc80d 100644 (file)
-/***********************************************************************\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_PLC.h"\r
-\r
-#define NB_ATT 2\r
-static const SKP_int16 HARM_ATT_Q15[NB_ATT]              = { 32440, 31130 }; /* 0.99, 0.95 */\r
-static const SKP_int16 PLC_RAND_ATTENUATE_V_Q15[NB_ATT]  = { 31130, 26214 }; /* 0.95, 0.8 */\r
-static const SKP_int16 PLC_RAND_ATTENUATE_UV_Q15[NB_ATT] = { 32440, 29491 }; /* 0.99, 0.9 */\r
-\r
-void SKP_Silk_PLC_Reset(\r
-    SKP_Silk_decoder_state      *psDec              /* I/O Decoder state        */\r
-)\r
-{\r
-    psDec->sPLC.pitchL_Q8 = SKP_RSHIFT( psDec->frame_length, 1 );\r
-}\r
-\r
-void SKP_Silk_PLC(\r
-    SKP_Silk_decoder_state      *psDec,             /* I Decoder state          */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I Decoder control        */\r
-    SKP_int16                   signal[],           /* O Concealed signal       */\r
-    SKP_int                     length,             /* I length of residual     */\r
-    SKP_int                     lost                /* I Loss flag              */\r
-)\r
-{\r
-    /* PLC control function */\r
-    if( psDec->fs_kHz != psDec->sPLC.fs_kHz ) {\r
-        SKP_Silk_PLC_Reset( psDec );\r
-        psDec->sPLC.fs_kHz = psDec->fs_kHz;\r
-    }\r
-\r
-    if( lost ) {\r
-        /****************************/\r
-        /* Generate Signal          */\r
-        /****************************/\r
-        SKP_Silk_PLC_conceal( psDec, psDecCtrl, signal, length );\r
-\r
-        psDec->lossCnt++;\r
-    } else {\r
-        /****************************/\r
-        /* Update state             */\r
-        /****************************/\r
-        SKP_Silk_PLC_update( psDec, psDecCtrl, signal, length );\r
-    }\r
-}\r
-\r
-/**************************************************/\r
-/* Update state of PLC                            */\r
-/**************************************************/\r
-void SKP_Silk_PLC_update(\r
-    SKP_Silk_decoder_state      *psDec,             /* (I/O) Decoder state          */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* (I/O) Decoder control        */\r
-    SKP_int16                   signal[],\r
-    SKP_int                     length\r
-)\r
-{\r
-    SKP_int32 LTP_Gain_Q14, temp_LTP_Gain_Q14;\r
-    SKP_int   i, j;\r
-    SKP_Silk_PLC_struct *psPLC;\r
-\r
-    psPLC = &psDec->sPLC;\r
-\r
-    /* Update parameters used in case of packet loss */\r
-    psDec->prev_sigtype = psDecCtrl->sigtype;\r
-    LTP_Gain_Q14 = 0;\r
-    if( psDecCtrl->sigtype == SIG_TYPE_VOICED ) {\r
-        /* Find the parameters for the last subframe which contains a pitch pulse */\r
-        for( j = 0; j * psDec->subfr_length  < psDecCtrl->pitchL[ NB_SUBFR - 1 ]; j++ ) {\r
-            temp_LTP_Gain_Q14 = 0;\r
-            for( i = 0; i < LTP_ORDER; i++ ) {\r
-                temp_LTP_Gain_Q14 += psDecCtrl->LTPCoef_Q14[ ( NB_SUBFR - 1 - j ) * LTP_ORDER  + i ];\r
-            }\r
-            if( temp_LTP_Gain_Q14 > LTP_Gain_Q14 ) {\r
-                LTP_Gain_Q14 = temp_LTP_Gain_Q14;\r
-                SKP_memcpy( psPLC->LTPCoef_Q14,\r
-                    &psDecCtrl->LTPCoef_Q14[ SKP_SMULBB( NB_SUBFR - 1 - j, LTP_ORDER ) ],\r
-                    LTP_ORDER * sizeof( SKP_int16 ) );\r
-\r
-                psPLC->pitchL_Q8 = SKP_LSHIFT( psDecCtrl->pitchL[ NB_SUBFR - 1 - j ], 8 );\r
-            }\r
-        }\r
-\r
-#if USE_SINGLE_TAP\r
-        SKP_memset( psPLC->LTPCoef_Q14, 0, LTP_ORDER * sizeof( SKP_int16 ) );\r
-        psPLC->LTPCoef_Q14[ LTP_ORDER / 2 ] = LTP_Gain_Q14;\r
-#endif\r
-\r
-        /* Limit LT coefs */\r
-        if( LTP_Gain_Q14 < V_PITCH_GAIN_START_MIN_Q14 ) {\r
-            SKP_int   scale_Q10;\r
-            SKP_int32 tmp;\r
-\r
-            tmp = SKP_LSHIFT( V_PITCH_GAIN_START_MIN_Q14, 10 );\r
-            scale_Q10 = SKP_DIV32( tmp, SKP_max( LTP_Gain_Q14, 1 ) );\r
-            for( i = 0; i < LTP_ORDER; i++ ) {\r
-                psPLC->LTPCoef_Q14[ i ] = SKP_RSHIFT( SKP_SMULBB( psPLC->LTPCoef_Q14[ i ], scale_Q10 ), 10 );\r
-            }\r
-        } else if( LTP_Gain_Q14 > V_PITCH_GAIN_START_MAX_Q14 ) {\r
-            SKP_int   scale_Q14;\r
-            SKP_int32 tmp;\r
-\r
-            tmp = SKP_LSHIFT( V_PITCH_GAIN_START_MAX_Q14, 14 );\r
-            scale_Q14 = SKP_DIV32( tmp, SKP_max( LTP_Gain_Q14, 1 ) );\r
-            for( i = 0; i < LTP_ORDER; i++ ) {\r
-                psPLC->LTPCoef_Q14[ i ] = SKP_RSHIFT( SKP_SMULBB( psPLC->LTPCoef_Q14[ i ], scale_Q14 ), 14 );\r
-            }\r
-        }\r
-    } else {\r
-        psPLC->pitchL_Q8 = SKP_LSHIFT( SKP_SMULBB( psDec->fs_kHz, 18 ), 8 );\r
-        SKP_memset( psPLC->LTPCoef_Q14, 0, LTP_ORDER * sizeof( SKP_int16 ));\r
-    }\r
-\r
-    /* Save LPC coeficients */\r
-    SKP_memcpy( psPLC->prevLPC_Q12, psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof( SKP_int16 ) );\r
-    psPLC->prevLTP_scale_Q14 = psDecCtrl->LTP_scale_Q14;\r
-\r
-    /* Save Gains */\r
-    SKP_memcpy( psPLC->prevGain_Q16, psDecCtrl->Gains_Q16, NB_SUBFR * sizeof( SKP_int32 ) );\r
-}\r
-\r
-void SKP_Silk_PLC_conceal(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O Decoder state */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control */\r
-    SKP_int16                   signal[],           /* O concealed signal */\r
-    SKP_int                     length              /* I length of residual */\r
-)\r
-{\r
-    SKP_int   i, j, k;\r
-    SKP_int16 *B_Q14, exc_buf[ MAX_FRAME_LENGTH ], *exc_buf_ptr;\r
-    SKP_int16 rand_scale_Q14;\r
-    union {\r
-        SKP_int16 as_int16[ MAX_LPC_ORDER ];\r
-        SKP_int32 as_int32[ MAX_LPC_ORDER / 2 ];\r
-    } A_Q12_tmp;\r
-    SKP_int32 rand_seed, harm_Gain_Q15, rand_Gain_Q15;\r
-    SKP_int   lag, idx, sLTP_buf_idx, shift1, shift2;\r
-    SKP_int32 energy1, energy2, *rand_ptr, *pred_lag_ptr;\r
-    SKP_int32 sig_Q10[ MAX_FRAME_LENGTH ], *sig_Q10_ptr, LPC_exc_Q10, LPC_pred_Q10,  LTP_pred_Q14;\r
-    SKP_Silk_PLC_struct *psPLC;\r
-    psPLC = &psDec->sPLC;\r
-\r
-    /* Update LTP buffer */\r
-    SKP_memcpy( psDec->sLTP_Q16, &psDec->sLTP_Q16[ psDec->frame_length ], psDec->frame_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
-\r
-    /* Find random noise component */\r
-    /* Scale previous excitation signal */\r
-    exc_buf_ptr = exc_buf;\r
-    for( k = ( NB_SUBFR >> 1 ); k < NB_SUBFR; k++ ) {\r
-        for( i = 0; i < psDec->subfr_length; i++ ) {\r
-            exc_buf_ptr[ i ] = ( SKP_int16 )SKP_RSHIFT( \r
-                SKP_SMULWW( psDec->exc_Q10[ i + k * psDec->subfr_length ], psPLC->prevGain_Q16[ k ] ), 10 );\r
-        }\r
-        exc_buf_ptr += psDec->subfr_length;\r
-    }\r
-    /* Find the subframe with lowest energy of the last two and use that as random noise generator */ \r
-    SKP_Silk_sum_sqr_shift( &energy1, &shift1, exc_buf,                         psDec->subfr_length );\r
-    SKP_Silk_sum_sqr_shift( &energy2, &shift2, &exc_buf[ psDec->subfr_length ], psDec->subfr_length );\r
-        \r
-    if( SKP_RSHIFT( energy1, shift2 ) < SKP_RSHIFT( energy2, shift1 ) ) {\r
-        /* First sub-frame has lowest energy */\r
-        rand_ptr = &psDec->exc_Q10[ SKP_max_int( 0, 3 * psDec->subfr_length - RAND_BUF_SIZE ) ];\r
-    } else {\r
-        /* Second sub-frame has lowest energy */\r
-        rand_ptr = &psDec->exc_Q10[ SKP_max_int( 0, psDec->frame_length - RAND_BUF_SIZE ) ];\r
-    }\r
-\r
-    /* Setup Gain to random noise component */ \r
-    B_Q14          = psPLC->LTPCoef_Q14;\r
-    rand_scale_Q14 = psPLC->randScale_Q14;\r
-\r
-    /* Setup attenuation gains */\r
-    harm_Gain_Q15 = HARM_ATT_Q15[ SKP_min_int( NB_ATT - 1, psDec->lossCnt ) ];\r
-    if( psDec->prev_sigtype == SIG_TYPE_VOICED ) {\r
-        rand_Gain_Q15 = PLC_RAND_ATTENUATE_V_Q15[  SKP_min_int( NB_ATT - 1, psDec->lossCnt ) ];\r
-    } else {\r
-        rand_Gain_Q15 = PLC_RAND_ATTENUATE_UV_Q15[ SKP_min_int( NB_ATT - 1, psDec->lossCnt ) ];\r
-    }\r
-\r
-    /* First Lost frame */\r
-    if( psDec->lossCnt == 0 ) {\r
-        rand_scale_Q14 = (1 << 14 );\r
-    \r
-        /* Reduce random noise Gain for voiced frames */\r
-        if( psDec->prev_sigtype == SIG_TYPE_VOICED ) {\r
-            for( i = 0; i < LTP_ORDER; i++ ) {\r
-                rand_scale_Q14 -= B_Q14[ i ];\r
-            }\r
-            rand_scale_Q14 = SKP_max_16( 3277, rand_scale_Q14 ); /* 0.2 */\r
-            rand_scale_Q14 = ( SKP_int16 )SKP_RSHIFT( SKP_SMULBB( rand_scale_Q14, psPLC->prevLTP_scale_Q14 ), 14 );\r
-        }\r
-\r
-        /* Reduce random noise for unvoiced frames with high LPC gain */\r
-        if( psDec->prev_sigtype == SIG_TYPE_UNVOICED ) {\r
-            SKP_int32 invGain_Q30, down_scale_Q30;\r
-            \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_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
-        }\r
-    }\r
-\r
-    rand_seed    = psPLC->rand_seed;\r
-    lag          = SKP_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 );\r
-    sLTP_buf_idx = psDec->frame_length;\r
-\r
-    /***************************/\r
-    /* LTP synthesis filtering */\r
-    /***************************/\r
-    sig_Q10_ptr = sig_Q10;\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        /* Setup pointer */\r
-        pred_lag_ptr = &psDec->sLTP_Q16[ sLTP_buf_idx - lag + LTP_ORDER / 2 ];\r
-        for( i = 0; i < psDec->subfr_length; i++ ) {\r
-            rand_seed = SKP_RAND( rand_seed );\r
-            idx = SKP_RSHIFT( rand_seed, 25 ) & RAND_BUF_MASK;\r
-\r
-            /* Unrolled loop */\r
-            LTP_pred_Q14 = SKP_SMULWB(               pred_lag_ptr[  0 ], B_Q14[ 0 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], B_Q14[ 1 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], B_Q14[ 2 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], B_Q14[ 3 ] );\r
-            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], B_Q14[ 4 ] );\r
-            pred_lag_ptr++;\r
-            \r
-            /* Generate LPC residual */\r
-            LPC_exc_Q10 = SKP_LSHIFT( SKP_SMULWB( rand_ptr[ idx ], rand_scale_Q14 ), 2 ); /* Random noise part */\r
-            LPC_exc_Q10 = SKP_ADD32( LPC_exc_Q10, SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) );  /* Harmonic part */\r
-            \r
-            /* Update states */\r
-            psDec->sLTP_Q16[ sLTP_buf_idx ] = SKP_LSHIFT( LPC_exc_Q10, 6 );\r
-            sLTP_buf_idx++;\r
-                \r
-            /* Save LPC residual */\r
-            sig_Q10_ptr[ i ] = LPC_exc_Q10;\r
-        }\r
-        sig_Q10_ptr += psDec->subfr_length;\r
-        /* Gradually reduce LTP gain */\r
-        for( j = 0; j < LTP_ORDER; j++ ) {\r
-            B_Q14[ j ] = SKP_RSHIFT( SKP_SMULBB( harm_Gain_Q15, B_Q14[ j ] ), 15 );\r
-        }\r
-        /* Gradually reduce excitation gain */\r
-        rand_scale_Q14 = SKP_RSHIFT( SKP_SMULBB( rand_scale_Q14, rand_Gain_Q15 ), 15 );\r
-\r
-        /* Slowly increase pitch lag */\r
-        psPLC->pitchL_Q8 += SKP_SMULWB( psPLC->pitchL_Q8, PITCH_DRIFT_FAC_Q16 );\r
-        psPLC->pitchL_Q8 = SKP_min_32( psPLC->pitchL_Q8, SKP_LSHIFT( SKP_SMULBB( MAX_PITCH_LAG_MS, psDec->fs_kHz ), 8 ) );\r
-        lag = SKP_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 );\r
-    }\r
-\r
-    /***************************/\r
-    /* LPC synthesis filtering */\r
-    /***************************/\r
-    sig_Q10_ptr = sig_Q10;\r
-    /* Preload LPC coeficients to array on stack. Gives small performance gain */\r
-    SKP_memcpy( A_Q12_tmp.as_int16, psPLC->prevLPC_Q12, psDec->LPC_order * sizeof( SKP_int16 ) );\r
-    SKP_assert( psDec->LPC_order >= 10 ); /* check that unrolling works */\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        for( i = 0; i < psDec->subfr_length; i++ ){\r
-            /* partly unrolled */\r
-            LPC_pred_Q10 = SKP_SMULWB(               psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  1 ], A_Q12_tmp.as_int16[ 0 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  2 ], A_Q12_tmp.as_int16[ 1 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  3 ], A_Q12_tmp.as_int16[ 2 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  4 ], A_Q12_tmp.as_int16[ 3 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  5 ], A_Q12_tmp.as_int16[ 4 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  6 ], A_Q12_tmp.as_int16[ 5 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  7 ], A_Q12_tmp.as_int16[ 6 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  8 ], A_Q12_tmp.as_int16[ 7 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  9 ], A_Q12_tmp.as_int16[ 8 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp.as_int16[ 9 ] );\r
-\r
-            for( j = 10; j < psDec->LPC_order; j++ ) {\r
-                LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - j - 1 ], A_Q12_tmp.as_int16[ j ] );\r
-            }\r
-            /* Add prediction to LPC residual */\r
-            sig_Q10_ptr[ i ] = SKP_ADD32( sig_Q10_ptr[ i ], LPC_pred_Q10 );\r
-                \r
-            /* Update states */\r
-            psDec->sLPC_Q14[ MAX_LPC_ORDER + i ] = SKP_LSHIFT( sig_Q10_ptr[ i ], 4 );\r
-        }\r
-        sig_Q10_ptr += psDec->subfr_length;\r
-        /* Update LPC filter state */\r
-        SKP_memcpy( psDec->sLPC_Q14, &psDec->sLPC_Q14[ psDec->subfr_length ], MAX_LPC_ORDER * sizeof( SKP_int32 ) );\r
-    }\r
-\r
-    /* Scale with Gain */\r
-    for( i = 0; i < psDec->frame_length; i++ ) {\r
-        signal[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( sig_Q10[ i ], psPLC->prevGain_Q16[ NB_SUBFR - 1 ] ), 10 ) );\r
-    }\r
-\r
-    /**************************************/\r
-    /* Update states                      */\r
-    /**************************************/\r
-    psPLC->rand_seed     = rand_seed;\r
-    psPLC->randScale_Q14 = rand_scale_Q14;\r
-    for( i = 0; i < NB_SUBFR; i++ ) {\r
-        psDecCtrl->pitchL[ i ] = lag;\r
-    }\r
-}\r
-\r
-/* Glues concealed frames with new good recieved frames             */\r
-void SKP_Silk_PLC_glue_frames(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O decoder state    */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control  */\r
-    SKP_int16                   signal[],           /* I/O signal           */\r
-    SKP_int                     length              /* I length of residual */\r
-)\r
-{\r
-    SKP_int   i, energy_shift;\r
-    SKP_int32 energy;\r
-    SKP_Silk_PLC_struct *psPLC;\r
-    psPLC = &psDec->sPLC;\r
-\r
-    if( psDec->lossCnt ) {\r
-        /* Calculate energy in concealed residual */\r
-        SKP_Silk_sum_sqr_shift( &psPLC->conc_energy, &psPLC->conc_energy_shift, signal, length );\r
-        \r
-        psPLC->last_frame_lost = 1;\r
-    } else {\r
-        if( psDec->sPLC.last_frame_lost ) {\r
-            /* Calculate residual in decoded signal if last frame was lost */\r
-            SKP_Silk_sum_sqr_shift( &energy, &energy_shift, signal, length );\r
-\r
-            /* Normalize energies */\r
-            if( energy_shift > psPLC->conc_energy_shift ) {\r
-                psPLC->conc_energy = SKP_RSHIFT( psPLC->conc_energy, energy_shift - psPLC->conc_energy_shift );\r
-            } else if( energy_shift < psPLC->conc_energy_shift ) {\r
-                energy = SKP_RSHIFT( energy, psPLC->conc_energy_shift - energy_shift );\r
-            }\r
-\r
-            /* 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
-\r
-                LZ = SKP_Silk_CLZ32( psPLC->conc_energy );\r
-                LZ = LZ - 1;\r
-                psPLC->conc_energy = SKP_LSHIFT( psPLC->conc_energy, LZ );\r
-                energy = SKP_RSHIFT( energy, SKP_max_32( 24 - LZ, 0 ) );\r
-                \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
-\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
-                }\r
-            }\r
-        }\r
-        psPLC->last_frame_lost = 0;\r
-\r
-    }\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+#include "SKP_Silk_PLC.h"
+
+#define NB_ATT 2
+static const SKP_int16 HARM_ATT_Q15[NB_ATT]              = { 32440, 31130 }; /* 0.99, 0.95 */
+static const SKP_int16 PLC_RAND_ATTENUATE_V_Q15[NB_ATT]  = { 31130, 26214 }; /* 0.95, 0.8 */
+static const SKP_int16 PLC_RAND_ATTENUATE_UV_Q15[NB_ATT] = { 32440, 29491 }; /* 0.99, 0.9 */
+
+void SKP_Silk_PLC_Reset(
+    SKP_Silk_decoder_state      *psDec              /* I/O Decoder state        */
+)
+{
+    psDec->sPLC.pitchL_Q8 = SKP_RSHIFT( psDec->frame_length, 1 );
+}
+
+void SKP_Silk_PLC(
+    SKP_Silk_decoder_state      *psDec,             /* I Decoder state          */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I Decoder control        */
+    SKP_int16                   signal[],           /* O Concealed signal       */
+    SKP_int                     length,             /* I length of residual     */
+    SKP_int                     lost                /* I Loss flag              */
+)
+{
+    /* PLC control function */
+    if( psDec->fs_kHz != psDec->sPLC.fs_kHz ) {
+        SKP_Silk_PLC_Reset( psDec );
+        psDec->sPLC.fs_kHz = psDec->fs_kHz;
+    }
+
+    if( lost ) {
+        /****************************/
+        /* Generate Signal          */
+        /****************************/
+        SKP_Silk_PLC_conceal( psDec, psDecCtrl, signal, length );
+
+        psDec->lossCnt++;
+    } else {
+        /****************************/
+        /* Update state             */
+        /****************************/
+        SKP_Silk_PLC_update( psDec, psDecCtrl, signal, length );
+    }
+}
+
+/**************************************************/
+/* Update state of PLC                            */
+/**************************************************/
+void SKP_Silk_PLC_update(
+    SKP_Silk_decoder_state      *psDec,             /* (I/O) Decoder state          */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* (I/O) Decoder control        */
+    SKP_int16                   signal[],
+    SKP_int                     length
+)
+{
+    SKP_int32 LTP_Gain_Q14, temp_LTP_Gain_Q14;
+    SKP_int   i, j;
+    SKP_Silk_PLC_struct *psPLC;
+
+    psPLC = &psDec->sPLC;
+
+    /* Update parameters used in case of packet loss */
+    psDec->prev_sigtype = psDecCtrl->sigtype;
+    LTP_Gain_Q14 = 0;
+    if( psDecCtrl->sigtype == SIG_TYPE_VOICED ) {
+        /* Find the parameters for the last subframe which contains a pitch pulse */
+        for( j = 0; j * psDec->subfr_length  < psDecCtrl->pitchL[ NB_SUBFR - 1 ]; j++ ) {
+            temp_LTP_Gain_Q14 = 0;
+            for( i = 0; i < LTP_ORDER; i++ ) {
+                temp_LTP_Gain_Q14 += psDecCtrl->LTPCoef_Q14[ ( NB_SUBFR - 1 - j ) * LTP_ORDER  + i ];
+            }
+            if( temp_LTP_Gain_Q14 > LTP_Gain_Q14 ) {
+                LTP_Gain_Q14 = temp_LTP_Gain_Q14;
+                SKP_memcpy( psPLC->LTPCoef_Q14,
+                    &psDecCtrl->LTPCoef_Q14[ SKP_SMULBB( NB_SUBFR - 1 - j, LTP_ORDER ) ],
+                    LTP_ORDER * sizeof( SKP_int16 ) );
+
+                psPLC->pitchL_Q8 = SKP_LSHIFT( psDecCtrl->pitchL[ NB_SUBFR - 1 - j ], 8 );
+            }
+        }
+
+#if USE_SINGLE_TAP
+        SKP_memset( psPLC->LTPCoef_Q14, 0, LTP_ORDER * sizeof( SKP_int16 ) );
+        psPLC->LTPCoef_Q14[ LTP_ORDER / 2 ] = LTP_Gain_Q14;
+#endif
+
+        /* Limit LT coefs */
+        if( LTP_Gain_Q14 < V_PITCH_GAIN_START_MIN_Q14 ) {
+            SKP_int   scale_Q10;
+            SKP_int32 tmp;
+
+            tmp = SKP_LSHIFT( V_PITCH_GAIN_START_MIN_Q14, 10 );
+            scale_Q10 = SKP_DIV32( tmp, SKP_max( LTP_Gain_Q14, 1 ) );
+            for( i = 0; i < LTP_ORDER; i++ ) {
+                psPLC->LTPCoef_Q14[ i ] = SKP_RSHIFT( SKP_SMULBB( psPLC->LTPCoef_Q14[ i ], scale_Q10 ), 10 );
+            }
+        } else if( LTP_Gain_Q14 > V_PITCH_GAIN_START_MAX_Q14 ) {
+            SKP_int   scale_Q14;
+            SKP_int32 tmp;
+
+            tmp = SKP_LSHIFT( V_PITCH_GAIN_START_MAX_Q14, 14 );
+            scale_Q14 = SKP_DIV32( tmp, SKP_max( LTP_Gain_Q14, 1 ) );
+            for( i = 0; i < LTP_ORDER; i++ ) {
+                psPLC->LTPCoef_Q14[ i ] = SKP_RSHIFT( SKP_SMULBB( psPLC->LTPCoef_Q14[ i ], scale_Q14 ), 14 );
+            }
+        }
+    } else {
+        psPLC->pitchL_Q8 = SKP_LSHIFT( SKP_SMULBB( psDec->fs_kHz, 18 ), 8 );
+        SKP_memset( psPLC->LTPCoef_Q14, 0, LTP_ORDER * sizeof( SKP_int16 ));
+    }
+
+    /* Save LPC coeficients */
+    SKP_memcpy( psPLC->prevLPC_Q12, psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof( SKP_int16 ) );
+    psPLC->prevLTP_scale_Q14 = psDecCtrl->LTP_scale_Q14;
+
+    /* Save Gains */
+    SKP_memcpy( psPLC->prevGain_Q16, psDecCtrl->Gains_Q16, NB_SUBFR * sizeof( SKP_int32 ) );
+}
+
+void SKP_Silk_PLC_conceal(
+    SKP_Silk_decoder_state      *psDec,             /* I/O Decoder state */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control */
+    SKP_int16                   signal[],           /* O concealed signal */
+    SKP_int                     length              /* I length of residual */
+)
+{
+    SKP_int   i, j, k;
+    SKP_int16 *B_Q14, exc_buf[ MAX_FRAME_LENGTH ], *exc_buf_ptr;
+    SKP_int16 rand_scale_Q14;
+    union {
+        SKP_int16 as_int16[ MAX_LPC_ORDER ];
+        SKP_int32 as_int32[ MAX_LPC_ORDER / 2 ];
+    } A_Q12_tmp;
+    SKP_int32 rand_seed, harm_Gain_Q15, rand_Gain_Q15;
+    SKP_int   lag, idx, sLTP_buf_idx, shift1, shift2;
+    SKP_int32 energy1, energy2, *rand_ptr, *pred_lag_ptr;
+    SKP_int32 sig_Q10[ MAX_FRAME_LENGTH ], *sig_Q10_ptr, LPC_exc_Q10, LPC_pred_Q10,  LTP_pred_Q14;
+    SKP_Silk_PLC_struct *psPLC;
+    psPLC = &psDec->sPLC;
+
+    /* Update LTP buffer */
+    SKP_memcpy( psDec->sLTP_Q16, &psDec->sLTP_Q16[ psDec->frame_length ], psDec->frame_length * sizeof( SKP_int32 ) );
+
+    /* LPC concealment. Apply BWE to previous LPC */
+    SKP_Silk_bwexpander( psPLC->prevLPC_Q12, psDec->LPC_order, BWE_COEF_Q16 );
+
+    /* Find random noise component */
+    /* Scale previous excitation signal */
+    exc_buf_ptr = exc_buf;
+    for( k = ( NB_SUBFR >> 1 ); k < NB_SUBFR; k++ ) {
+        for( i = 0; i < psDec->subfr_length; i++ ) {
+            exc_buf_ptr[ i ] = ( SKP_int16 )SKP_RSHIFT( 
+                SKP_SMULWW( psDec->exc_Q10[ i + k * psDec->subfr_length ], psPLC->prevGain_Q16[ k ] ), 10 );
+        }
+        exc_buf_ptr += psDec->subfr_length;
+    }
+    /* Find the subframe with lowest energy of the last two and use that as random noise generator */ 
+    SKP_Silk_sum_sqr_shift( &energy1, &shift1, exc_buf,                         psDec->subfr_length );
+    SKP_Silk_sum_sqr_shift( &energy2, &shift2, &exc_buf[ psDec->subfr_length ], psDec->subfr_length );
+        
+    if( SKP_RSHIFT( energy1, shift2 ) < SKP_RSHIFT( energy2, shift1 ) ) {
+        /* First sub-frame has lowest energy */
+        rand_ptr = &psDec->exc_Q10[ SKP_max_int( 0, 3 * psDec->subfr_length - RAND_BUF_SIZE ) ];
+    } else {
+        /* Second sub-frame has lowest energy */
+        rand_ptr = &psDec->exc_Q10[ SKP_max_int( 0, psDec->frame_length - RAND_BUF_SIZE ) ];
+    }
+
+    /* Setup Gain to random noise component */ 
+    B_Q14          = psPLC->LTPCoef_Q14;
+    rand_scale_Q14 = psPLC->randScale_Q14;
+
+    /* Setup attenuation gains */
+    harm_Gain_Q15 = HARM_ATT_Q15[ SKP_min_int( NB_ATT - 1, psDec->lossCnt ) ];
+    if( psDec->prev_sigtype == SIG_TYPE_VOICED ) {
+        rand_Gain_Q15 = PLC_RAND_ATTENUATE_V_Q15[  SKP_min_int( NB_ATT - 1, psDec->lossCnt ) ];
+    } else {
+        rand_Gain_Q15 = PLC_RAND_ATTENUATE_UV_Q15[ SKP_min_int( NB_ATT - 1, psDec->lossCnt ) ];
+    }
+
+    /* First Lost frame */
+    if( psDec->lossCnt == 0 ) {
+        rand_scale_Q14 = (1 << 14 );
+    
+        /* Reduce random noise Gain for voiced frames */
+        if( psDec->prev_sigtype == SIG_TYPE_VOICED ) {
+            for( i = 0; i < LTP_ORDER; i++ ) {
+                rand_scale_Q14 -= B_Q14[ i ];
+            }
+            rand_scale_Q14 = SKP_max_16( 3277, rand_scale_Q14 ); /* 0.2 */
+            rand_scale_Q14 = ( SKP_int16 )SKP_RSHIFT( SKP_SMULBB( rand_scale_Q14, psPLC->prevLTP_scale_Q14 ), 14 );
+        }
+
+        /* Reduce random noise for unvoiced frames with high LPC gain */
+        if( psDec->prev_sigtype == SIG_TYPE_UNVOICED ) {
+            SKP_int32 invGain_Q30, down_scale_Q30;
+            
+            SKP_Silk_LPC_inverse_pred_gain( &invGain_Q30, psPLC->prevLPC_Q12, psDec->LPC_order );
+            
+            down_scale_Q30 = SKP_min_32( SKP_RSHIFT( ( 1 << 30 ), LOG2_INV_LPC_GAIN_HIGH_THRES ), invGain_Q30 );
+            down_scale_Q30 = SKP_max_32( SKP_RSHIFT( ( 1 << 30 ), LOG2_INV_LPC_GAIN_LOW_THRES ), down_scale_Q30 );
+            down_scale_Q30 = SKP_LSHIFT( down_scale_Q30, LOG2_INV_LPC_GAIN_HIGH_THRES );
+            
+            rand_Gain_Q15 = SKP_RSHIFT( SKP_SMULWB( down_scale_Q30, rand_Gain_Q15 ), 14 );
+        }
+    }
+
+    rand_seed    = psPLC->rand_seed;
+    lag          = SKP_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 );
+    sLTP_buf_idx = psDec->frame_length;
+
+    /***************************/
+    /* LTP synthesis filtering */
+    /***************************/
+    sig_Q10_ptr = sig_Q10;
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        /* Setup pointer */
+        pred_lag_ptr = &psDec->sLTP_Q16[ sLTP_buf_idx - lag + LTP_ORDER / 2 ];
+        for( i = 0; i < psDec->subfr_length; i++ ) {
+            rand_seed = SKP_RAND( rand_seed );
+            idx = SKP_RSHIFT( rand_seed, 25 ) & RAND_BUF_MASK;
+
+            /* Unrolled loop */
+            LTP_pred_Q14 = SKP_SMULWB(               pred_lag_ptr[  0 ], B_Q14[ 0 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], B_Q14[ 1 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], B_Q14[ 2 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], B_Q14[ 3 ] );
+            LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], B_Q14[ 4 ] );
+            pred_lag_ptr++;
+            
+            /* Generate LPC residual */
+            LPC_exc_Q10 = SKP_LSHIFT( SKP_SMULWB( rand_ptr[ idx ], rand_scale_Q14 ), 2 ); /* Random noise part */
+            LPC_exc_Q10 = SKP_ADD32( LPC_exc_Q10, SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) );  /* Harmonic part */
+            
+            /* Update states */
+            psDec->sLTP_Q16[ sLTP_buf_idx ] = SKP_LSHIFT( LPC_exc_Q10, 6 );
+            sLTP_buf_idx++;
+                
+            /* Save LPC residual */
+            sig_Q10_ptr[ i ] = LPC_exc_Q10;
+        }
+        sig_Q10_ptr += psDec->subfr_length;
+        /* Gradually reduce LTP gain */
+        for( j = 0; j < LTP_ORDER; j++ ) {
+            B_Q14[ j ] = SKP_RSHIFT( SKP_SMULBB( harm_Gain_Q15, B_Q14[ j ] ), 15 );
+        }
+        /* Gradually reduce excitation gain */
+        rand_scale_Q14 = SKP_RSHIFT( SKP_SMULBB( rand_scale_Q14, rand_Gain_Q15 ), 15 );
+
+        /* Slowly increase pitch lag */
+        psPLC->pitchL_Q8 += SKP_SMULWB( psPLC->pitchL_Q8, PITCH_DRIFT_FAC_Q16 );
+        psPLC->pitchL_Q8 = SKP_min_32( psPLC->pitchL_Q8, SKP_LSHIFT( SKP_SMULBB( MAX_PITCH_LAG_MS, psDec->fs_kHz ), 8 ) );
+        lag = SKP_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 );
+    }
+
+    /***************************/
+    /* LPC synthesis filtering */
+    /***************************/
+    sig_Q10_ptr = sig_Q10;
+    /* Preload LPC coeficients to array on stack. Gives small performance gain */
+    SKP_memcpy( A_Q12_tmp.as_int16, psPLC->prevLPC_Q12, psDec->LPC_order * sizeof( SKP_int16 ) );
+    SKP_assert( psDec->LPC_order >= 10 ); /* check that unrolling works */
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        for( i = 0; i < psDec->subfr_length; i++ ){
+            /* partly unrolled */
+            LPC_pred_Q10 = SKP_SMULWB(               psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  1 ], A_Q12_tmp.as_int16[ 0 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  2 ], A_Q12_tmp.as_int16[ 1 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  3 ], A_Q12_tmp.as_int16[ 2 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  4 ], A_Q12_tmp.as_int16[ 3 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  5 ], A_Q12_tmp.as_int16[ 4 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  6 ], A_Q12_tmp.as_int16[ 5 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  7 ], A_Q12_tmp.as_int16[ 6 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  8 ], A_Q12_tmp.as_int16[ 7 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i -  9 ], A_Q12_tmp.as_int16[ 8 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp.as_int16[ 9 ] );
+
+            for( j = 10; j < psDec->LPC_order; j++ ) {
+                LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - j - 1 ], A_Q12_tmp.as_int16[ j ] );
+            }
+            /* Add prediction to LPC residual */
+            sig_Q10_ptr[ i ] = SKP_ADD32( sig_Q10_ptr[ i ], LPC_pred_Q10 );
+                
+            /* Update states */
+            psDec->sLPC_Q14[ MAX_LPC_ORDER + i ] = SKP_LSHIFT( sig_Q10_ptr[ i ], 4 );
+        }
+        sig_Q10_ptr += psDec->subfr_length;
+        /* Update LPC filter state */
+        SKP_memcpy( psDec->sLPC_Q14, &psDec->sLPC_Q14[ psDec->subfr_length ], MAX_LPC_ORDER * sizeof( SKP_int32 ) );
+    }
+
+    /* Scale with Gain */
+    for( i = 0; i < psDec->frame_length; i++ ) {
+        signal[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( sig_Q10[ i ], psPLC->prevGain_Q16[ NB_SUBFR - 1 ] ), 10 ) );
+    }
+
+    /**************************************/
+    /* Update states                      */
+    /**************************************/
+    psPLC->rand_seed     = rand_seed;
+    psPLC->randScale_Q14 = rand_scale_Q14;
+    for( i = 0; i < NB_SUBFR; i++ ) {
+        psDecCtrl->pitchL[ i ] = lag;
+    }
+}
+
+/* Glues concealed frames with new good recieved frames             */
+void SKP_Silk_PLC_glue_frames(
+    SKP_Silk_decoder_state      *psDec,             /* I/O decoder state    */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control  */
+    SKP_int16                   signal[],           /* I/O signal           */
+    SKP_int                     length              /* I length of residual */
+)
+{
+    SKP_int   i, energy_shift;
+    SKP_int32 energy;
+    SKP_Silk_PLC_struct *psPLC;
+    psPLC = &psDec->sPLC;
+
+    if( psDec->lossCnt ) {
+        /* Calculate energy in concealed residual */
+        SKP_Silk_sum_sqr_shift( &psPLC->conc_energy, &psPLC->conc_energy_shift, signal, length );
+        
+        psPLC->last_frame_lost = 1;
+    } else {
+        if( psDec->sPLC.last_frame_lost ) {
+            /* Calculate residual in decoded signal if last frame was lost */
+            SKP_Silk_sum_sqr_shift( &energy, &energy_shift, signal, length );
+
+            /* Normalize energies */
+            if( energy_shift > psPLC->conc_energy_shift ) {
+                psPLC->conc_energy = SKP_RSHIFT( psPLC->conc_energy, energy_shift - psPLC->conc_energy_shift );
+            } else if( energy_shift < psPLC->conc_energy_shift ) {
+                energy = SKP_RSHIFT( energy, psPLC->conc_energy_shift - energy_shift );
+            }
+
+            /* Fade in the energy difference */
+            if( energy > psPLC->conc_energy ) {
+                SKP_int32 frac_Q24, LZ;
+                SKP_int32 gain_Q12, slope_Q12;
+
+                LZ = SKP_Silk_CLZ32( psPLC->conc_energy );
+                LZ = LZ - 1;
+                psPLC->conc_energy = SKP_LSHIFT( psPLC->conc_energy, LZ );
+                energy = SKP_RSHIFT( energy, SKP_max_32( 24 - LZ, 0 ) );
+                
+                frac_Q24 = SKP_DIV32( psPLC->conc_energy, SKP_max( energy, 1 ) );
+                
+                gain_Q12 = SKP_Silk_SQRT_APPROX( frac_Q24 );
+                slope_Q12 = SKP_DIV32_16( ( 1 << 12 ) - gain_Q12, length );
+
+                for( i = 0; i < length; i++ ) {
+                    signal[ i ] = SKP_RSHIFT( SKP_MUL( gain_Q12, signal[ i ] ), 12 );
+                    gain_Q12 += slope_Q12;
+                    gain_Q12 = SKP_min( gain_Q12, ( 1 << 12 ) );
+                }
+            }
+        }
+        psPLC->last_frame_lost = 0;
+
+    }
+}
+
index d23f994afb61034c1d9d66978beb4f8489165cb1..49a6fb283d38bf85f186af14bfa820786e903429 100644 (file)
@@ -1,79 +1,79 @@
-/***********************************************************************\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
-#ifndef SKP_SILK_PLC_FIX_H\r
-#define SKP_SILK_PLC_FIX_H\r
-\r
-#include "SKP_Silk_main.h"\r
-\r
-#define BWE_COEF_Q16                    64880           /* 0.99 in Q16                      */\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
-#define SA_THRES_Q8                     50\r
-#define USE_SINGLE_TAP                  1\r
-#define RAND_BUF_SIZE                   128\r
-#define RAND_BUF_MASK                   (RAND_BUF_SIZE - 1)\r
-#define LOG2_INV_LPC_GAIN_HIGH_THRES    3               /* 2^3 = 8 dB LPC gain              */\r
-#define LOG2_INV_LPC_GAIN_LOW_THRES     8               /* 2^8 = 24 dB LPC gain             */\r
-#define PITCH_DRIFT_FAC_Q16             655             /* 0.01 in Q16                      */\r
-\r
-void SKP_Silk_PLC_Reset(\r
-    SKP_Silk_decoder_state      *psDec              /* I/O Decoder state        */\r
-);\r
-\r
-void SKP_Silk_PLC(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O Decoder state        */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control      */\r
-    SKP_int16                   signal[],           /* I/O  signal              */\r
-    SKP_int                     length,             /* I length of residual     */\r
-    SKP_int                     lost                /* I Loss flag              */\r
-);\r
-\r
-void SKP_Silk_PLC_update(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O Decoder state        */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control      */\r
-    SKP_int16                   signal[],\r
-    SKP_int                     length\r
-);\r
-\r
-void SKP_Silk_PLC_conceal(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O Decoder state        */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control      */\r
-    SKP_int16                   signal[],           /* O LPC residual signal    */\r
-    SKP_int                     length              /* I length of signal       */\r
-);\r
-\r
-void SKP_Silk_PLC_glue_frames(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O decoder state        */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control      */\r
-    SKP_int16                   signal[],           /* I/O signal               */\r
-    SKP_int                     length              /* I length of signal       */\r
-);\r
-\r
-#endif\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_PLC_FIX_H
+#define SKP_SILK_PLC_FIX_H
+
+#include "SKP_Silk_main.h"
+
+#define BWE_COEF_Q16                    64880           /* 0.99 in Q16                      */
+#define V_PITCH_GAIN_START_MIN_Q14      11469           /* 0.7 in Q14                       */
+#define V_PITCH_GAIN_START_MAX_Q14      15565           /* 0.95 in Q14                      */
+#define MAX_PITCH_LAG_MS                18
+#define SA_THRES_Q8                     50
+#define USE_SINGLE_TAP                  1
+#define RAND_BUF_SIZE                   128
+#define RAND_BUF_MASK                   (RAND_BUF_SIZE - 1)
+#define LOG2_INV_LPC_GAIN_HIGH_THRES    3               /* 2^3 = 8 dB LPC gain              */
+#define LOG2_INV_LPC_GAIN_LOW_THRES     8               /* 2^8 = 24 dB LPC gain             */
+#define PITCH_DRIFT_FAC_Q16             655             /* 0.01 in Q16                      */
+
+void SKP_Silk_PLC_Reset(
+    SKP_Silk_decoder_state      *psDec              /* I/O Decoder state        */
+);
+
+void SKP_Silk_PLC(
+    SKP_Silk_decoder_state      *psDec,             /* I/O Decoder state        */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control      */
+    SKP_int16                   signal[],           /* I/O  signal              */
+    SKP_int                     length,             /* I length of residual     */
+    SKP_int                     lost                /* I Loss flag              */
+);
+
+void SKP_Silk_PLC_update(
+    SKP_Silk_decoder_state      *psDec,             /* I/O Decoder state        */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control      */
+    SKP_int16                   signal[],
+    SKP_int                     length
+);
+
+void SKP_Silk_PLC_conceal(
+    SKP_Silk_decoder_state      *psDec,             /* I/O Decoder state        */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control      */
+    SKP_int16                   signal[],           /* O LPC residual signal    */
+    SKP_int                     length              /* I length of signal       */
+);
+
+void SKP_Silk_PLC_glue_frames(
+    SKP_Silk_decoder_state      *psDec,             /* I/O decoder state        */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O Decoder control      */
+    SKP_int16                   signal[],           /* I/O signal               */
+    SKP_int                     length              /* I length of signal       */
+);
+
+#endif
+
index 48a506731ee2ee102e408e13724a9d46b60342fd..755e77dfa7f4f1a6e860dfa4ad50cd599ce14e7f 100644 (file)
-/***********************************************************************\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
-#ifndef _SKP_SILK_SIGPROC_FIX_H_\r
-#define _SKP_SILK_SIGPROC_FIX_H_\r
-\r
-#ifdef  __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-#define SKP_Silk_MAX_ORDER_LPC            16                    /* max order of the LPC analysis in schur() and k2a()    */\r
-#define SKP_Silk_MAX_CORRELATION_LENGTH   640                   /* max input length to the correlation                    */\r
-#include "SKP_Silk_typedef.h"\r
-#include <string.h>\r
-#include <stdlib.h>                                            /* for abs() */\r
-#include "SKP_Silk_resampler_structs.h"\r
-\r
-#      include "SKP_Silk_macros.h"\r
-\r
-\r
-\r
-/********************************************************************/\r
-/*                    SIGNAL PROCESSING FUNCTIONS                   */\r
-/********************************************************************/\r
-\r
-/*!\r
- * Initialize/reset the resampler state for a given pair of input/output sampling rates \r
-*/\r
-SKP_int SKP_Silk_resampler_init( \r
-       SKP_Silk_resampler_state_struct *S,                 /* I/O: Resampler state                     */\r
-       SKP_int32                                                       Fs_Hz_in,       /* I:   Input sampling rate (Hz)        */\r
-       SKP_int32                                                       Fs_Hz_out       /* I:   Output sampling rate (Hz)       */\r
-);\r
-\r
-\r
-/*!\r
- * Clear the states of all resampling filters, without resetting sampling rate ratio \r
- */\r
-SKP_int SKP_Silk_resampler_clear( \r
-       SKP_Silk_resampler_state_struct *S                  /* I/O: Resampler state                     */\r
-);\r
-\r
-/*!\r
- * Resampler: convert from one sampling rate to another\r
- */\r
-SKP_int SKP_Silk_resampler( \r
-       SKP_Silk_resampler_state_struct *S,                 /* I/O: Resampler state                     */\r
-       SKP_int16                                                       out[],      /* O:       Output signal                           */\r
-       const SKP_int16                                         in[],       /* I:       Input signal                            */\r
-       SKP_int32                                                       inLen       /* I:       Number of input samples         */\r
-);\r
-\r
-/*!\r
- Upsample 2x, low quality \r
- */\r
-void SKP_Silk_resampler_up2(\r
-    SKP_int32                           *S,         /* I/O: State vector [ 2 ]                  */\r
-    SKP_int16                           *out,       /* O:   Output signal [ 2 * len ]           */\r
-    const SKP_int16                     *in,        /* I:   Input signal [ len ]                */\r
-    SKP_int32                           len         /* I:   Number of input samples             */\r
-);\r
-\r
-/*!\r
-* Downsample 2x, mediocre quality \r
-*/\r
-void SKP_Silk_resampler_down2(\r
-    SKP_int32                           *S,         /* I/O: State vector [ 2 ]                  */\r
-    SKP_int16                           *out,       /* O:   Output signal [ len ]               */\r
-    const SKP_int16                     *in,        /* I:   Input signal [ floor(len/2) ]       */\r
-    SKP_int32                           inLen       /* I:   Number of input samples             */\r
-);\r
-\r
-\r
-/*!\r
- * Downsample by a factor 2/3, low quality\r
-*/\r
-void SKP_Silk_resampler_down2_3(\r
-    SKP_int32                           *S,         /* I/O: State vector [ 6 ]                  */\r
-    SKP_int16                           *out,       /* O:   Output signal [ floor(2*inLen/3) ]  */\r
-    const SKP_int16                     *in,        /* I:   Input signal [ inLen ]              */\r
-    SKP_int32                           inLen       /* I:   Number of input samples             */\r
-);\r
-\r
-/*!\r
- * Downsample by a factor 3, low quality\r
-*/\r
-void SKP_Silk_resampler_down3(\r
-    SKP_int32                           *S,         /* I/O: State vector [ 8 ]                  */\r
-    SKP_int16                           *out,       /* O:   Output signal [ floor(inLen/3) ]    */\r
-    const SKP_int16                     *in,        /* I:   Input signal [ inLen ]              */\r
-    SKP_int32                           inLen       /* I:   Number of input samples             */\r
-);\r
-\r
-/*! \r
- * second order ARMA filter\r
- * can handle (slowly) varying coefficients \r
- */\r
-void SKP_Silk_biquad(\r
-    const SKP_int16      *in,          /* I:   input signal                */\r
-    const SKP_int16      *B,           /* I:   MA coefficients, Q13 [3]    */\r
-    const SKP_int16      *A,           /* I:   AR coefficients, Q13 [2]    */\r
-          SKP_int32      *S,           /* I/O: state vector [2]            */\r
-          SKP_int16      *out,         /* O:   output signal               */\r
-    const SKP_int32      len           /* I:   signal length               */\r
-);\r
-/*!\r
- * second order ARMA filter; \r
- * slower than biquad() but uses more precise coefficients\r
- * can handle (slowly) varying coefficients \r
- */\r
-void SKP_Silk_biquad_alt(\r
-    const SKP_int16     *in,           /* I:    input signal                 */\r
-    const SKP_int32     *B_Q28,        /* I:    MA coefficients [3]          */\r
-    const SKP_int32     *A_Q28,        /* I:    AR coefficients [2]          */\r
-    SKP_int32           *S,            /* I/O: state vector [2]              */\r
-    SKP_int16           *out,          /* O:    output signal                */\r
-    const SKP_int32     len            /* I:    signal length (must be even) */\r
-);\r
-\r
-/*! \r
- * variable order MA filter. Prediction error filter implementation. Coeficients negated and starting with coef to x[n - 1]\r
- */\r
-void SKP_Silk_MA_Prediction(\r
-    const SKP_int16      *in,          /* I:   Input signal                                */\r
-    const SKP_int16      *B,           /* I:   MA prediction coefficients, Q12 [order]     */\r
-    SKP_int32            *S,           /* I/O: State vector [order]                        */\r
-    SKP_int16            *out,         /* O:   Output signal                               */\r
-    const SKP_int32      len,          /* I:   Signal length                               */\r
-    const SKP_int32      order         /* I:  Filter order                                 */\r
-);\r
-\r
-/*!\r
- * 16th order AR filter for LPC synthesis, coefficients are in Q12\r
- */\r
-void SKP_Silk_LPC_synthesis_order16(\r
-    const SKP_int16      *in,          /* I:   excitation signal                            */\r
-    const SKP_int16      *A_Q12,       /* I:   AR coefficients [16], between -8_Q0 and 8_Q0 */\r
-    const SKP_int32      Gain_Q26,     /* I:   gain                                         */\r
-          SKP_int32      *S,           /* I/O: state vector [16]                            */\r
-          SKP_int16      *out,         /* O:   output signal                                */\r
-    const SKP_int32      len           /* I:   signal length, must be multiple of 16        */\r
-);\r
-\r
-/* variable order MA prediction error filter. */\r
-/* Inverse filter of SKP_Silk_LPC_synthesis_filter */\r
-void SKP_Silk_LPC_analysis_filter(\r
-    const SKP_int16      *in,          /* I:   Input signal                                */\r
-    const SKP_int16      *B,           /* I:   MA prediction coefficients, Q12 [order]     */\r
-    SKP_int16            *S,           /* I/O: State vector [order]                        */\r
-    SKP_int16            *out,         /* O:   Output signal                               */\r
-    const SKP_int32      len,          /* I:   Signal length                               */\r
-    const SKP_int32      Order         /* I:   Filter order                                */\r
-);\r
-\r
-/* even order AR filter */\r
-void SKP_Silk_LPC_synthesis_filter(\r
-    const SKP_int16      *in,          /* I:   excitation signal                               */\r
-    const SKP_int16      *A_Q12,       /* I:   AR coefficients [Order], between -8_Q0 and 8_Q0 */\r
-    const SKP_int32      Gain_Q26,     /* I:   gain                                            */\r
-    SKP_int32            *S,           /* I/O: state vector [Order]                            */\r
-    SKP_int16            *out,         /* O:   output signal                                   */\r
-    const SKP_int32      len,          /* I:   signal length                                   */\r
-    const SKP_int        Order         /* I:   filter order, must be even                      */\r
-);\r
-\r
-/* Chirp (bandwidth expand) LP AR filter */\r
-void SKP_Silk_bwexpander( \r
-    SKP_int16            *ar,          /* I/O  AR filter to be expanded (without leading 1)    */\r
-    const SKP_int        d,            /* I    Length of ar                                    */\r
-    SKP_int32            chirp_Q16     /* I    Chirp factor (typically in the range 0 to 1)    */\r
-);\r
-\r
-/* Chirp (bandwidth expand) LP AR filter */\r
-void SKP_Silk_bwexpander_32( \r
-    SKP_int32            *ar,          /* I/O  AR filter to be expanded (without leading 1)    */\r
-    const SKP_int        d,            /* I    Length of ar                                    */\r
-    SKP_int32            chirp_Q16     /* I    Chirp factor in Q16                             */\r
-);\r
-\r
-/* Compute inverse of LPC prediction gain, and                           */\r
-/* test if LPC coefficients are stable (all poles within unit circle)    */\r
-SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O:  Returns 1 if unstable, otherwise 0          */\r
-    SKP_int32            *invGain_Q30,  /* O:  Inverse prediction gain, Q30 energy domain  */\r
-    const SKP_int16      *A_Q12,        /* I:  Prediction coefficients, Q12 [order]        */\r
-    const SKP_int        order          /* I:  Prediction order                            */\r
-);\r
-\r
-SKP_int SKP_Silk_LPC_inverse_pred_gain_Q24( /* O:   Returns 1 if unstable, otherwise 0      */\r
-    SKP_int32           *invGain_Q30,   /* O:   Inverse prediction gain, Q30 energy domain  */\r
-    const SKP_int32     *A_Q24,         /* I:   Prediction coefficients, Q24 [order]        */\r
-    const SKP_int       order           /* I:   Prediction order                            */\r
-);\r
-\r
-/* split signal in two decimated bands using first-order allpass filters */\r
-void SKP_Silk_ana_filt_bank_1(\r
-    const SKP_int16      *in,           /* I:   Input signal [N]        */\r
-    SKP_int32            *S,            /* I/O: State vector [2]        */\r
-    SKP_int16            *outL,         /* O:   Low band [N/2]          */\r
-    SKP_int16            *outH,         /* O:   High band [N/2]         */\r
-    SKP_int32            *scratch,      /* I:   Scratch memory [3*N/2]  */\r
-    const SKP_int32      N              /* I:   Number of input samples */\r
-);\r
-\r
-/********************************************************************/\r
-/*                        SCALAR FUNCTIONS                            */\r
-/********************************************************************/\r
-\r
-/* approximation of 128 * log2() (exact inverse of approx 2^() below) */\r
-/* convert input to a log scale    */\r
-SKP_int32 SKP_Silk_lin2log(const SKP_int32 inLin);        /* I: input in linear scale        */\r
-\r
-/* Approximation of a sigmoid function */\r
-SKP_int SKP_Silk_sigm_Q15(SKP_int in_Q5);\r
-\r
-/* approximation of 2^() (exact inverse of approx log2() above) */\r
-/* convert input to a linear scale    */ \r
-SKP_int32 SKP_Silk_log2lin(const SKP_int32 inLog_Q7);    /* I: input on log scale */ \r
-\r
-/* Function that returns the maximum absolut value of the input vector */\r
-SKP_int16 SKP_Silk_int16_array_maxabs(  /* O   Maximum absolute value, max: 2^15-1   */\r
-    const SKP_int16     *vec,           /* I   Input vector  [len]                   */ \r
-    const SKP_int32     len             /* I   Length of input vector                */\r
-);\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
-    SKP_int32           *energy,        /* O   Energy of x, after shifting to the right            */\r
-    SKP_int             *shift,         /* O   Number of bits right shift applied to energy        */\r
-    const SKP_int16     *x,             /* I   Input vector                                        */\r
-    SKP_int             len             /* I   Length of input vector                              */\r
-);\r
-\r
-/* Calculates the reflection coefficients from the correlation sequence    */\r
-/* Faster than schur64(), but much less accurate.                          */\r
-/* uses SMLAWB(), requiring armv5E and higher.                             */ \r
-SKP_int32 SKP_Silk_schur(               /* O:    Returns residual energy                   */\r
-    SKP_int16            *rc_Q15,       /* O:    reflection coefficients [order] Q15       */\r
-    const SKP_int32      *c,            /* I:    correlations [order+1]                    */\r
-    const SKP_int32      order          /* I:    prediction order                          */\r
-);;\r
-\r
-/* Calculates the reflection coefficients from the correlation sequence    */\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           rc_Q16[],       /* O:  Reflection coefficients [order] Q16         */\r
-    const SKP_int32     c[],            /* I:  Correlations [order+1]                      */\r
-    SKP_int32           order           /* I:  Prediction order                            */\r
-);\r
-\r
-/* Step up function, converts reflection coefficients to prediction coefficients */\r
-void SKP_Silk_k2a(\r
-    SKP_int32           *A_Q24,         /* O:  Prediction coefficients [order] Q24         */\r
-    const SKP_int16     *rc_Q15,        /* I:  Reflection coefficients [order] Q15         */\r
-    const SKP_int32     order           /* I:  Prediction order                            */\r
-);\r
-\r
-/* Step up function, converts reflection coefficients to prediction coefficients */\r
-void SKP_Silk_k2a_Q16(\r
-    SKP_int32           *A_Q24,         /* O:  Prediction coefficients [order] Q24         */\r
-    const SKP_int32     *rc_Q16,        /* I:  Reflection coefficients [order] Q16         */\r
-    const SKP_int32     order           /* I:  Prediction order                            */\r
-);\r
-\r
-/* Apply sine window to signal vector.                                      */\r
-/* Window types:                                                            */\r
-/*    1 -> sine window from 0 to pi/2                                       */\r
-/*    2 -> sine window from pi/2 to pi                                      */\r
-/* Every other sample is linearly interpolated, for speed.                  */\r
-/* Window length must be between 16 and 120 (incl) and a multiple of 4.     */\r
-void SKP_Silk_apply_sine_window_new(\r
-    SKP_int16                        px_win[],            /* O    Pointer to windowed signal                  */\r
-    const SKP_int16                  px[],                /* I    Pointer to input signal                     */\r
-    const SKP_int                    win_type,            /* I    Selects a window type                       */\r
-    const SKP_int                    length               /* I    Window length, multiple of 4                */\r
-);\r
-\r
-/* Compute autocorrelation */\r
-void SKP_Silk_autocorr( \r
-    SKP_int32           *results,       /* O  Result (length correlationCount)            */\r
-    SKP_int             *scale,         /* O  Scaling of the correlation vector           */\r
-    const SKP_int16     *inputData,     /* I  Input data to correlate                     */\r
-    const SKP_int       inputDataSize,  /* I  Length of input                             */\r
-    const SKP_int       correlationCount /* I  Number of correlation taps to compute      */\r
-);\r
-\r
-/* Pitch estimator */\r
-#define SKP_Silk_PITCH_EST_MIN_COMPLEX        0\r
-#define SKP_Silk_PITCH_EST_MID_COMPLEX        1\r
-#define SKP_Silk_PITCH_EST_MAX_COMPLEX        2\r
-\r
-void SKP_Silk_decode_pitch(\r
-    SKP_int            lagIndex,        /* I                                              */\r
-    SKP_int            contourIndex,    /* O                                              */\r
-    SKP_int            pitch_lags[],    /* O 4 pitch values                               */\r
-    SKP_int            Fs_kHz           /* I sampling frequency (kHz)                     */\r
-);\r
-\r
-SKP_int SKP_Silk_pitch_analysis_core(    /* O    Voicing estimate: 0 voiced, 1 unvoiced                      */\r
-    const SKP_int16  *signal,            /* I    Signal of length PITCH_EST_FRAME_LENGTH_MS*Fs_kHz           */\r
-    SKP_int          *pitch_out,         /* O    4 pitch lag values                                          */\r
-    SKP_int          *lagIndex,          /* O    Lag Index                                                   */\r
-    SKP_int          *contourIndex,      /* O    Pitch contour Index                                         */\r
-    SKP_int          *LTPCorr_Q15,       /* I/O  Normalized correlation; input: value from previous frame    */\r
-    SKP_int          prevLag,            /* I    Last lag of previous frame; set to zero is unvoiced         */\r
-    const SKP_int32  search_thres1_Q16,  /* I    First stage threshold for lag candidates 0 - 1              */\r
-    const SKP_int    search_thres2_Q15,  /* I    Final threshold for lag candidates 0 - 1                    */\r
-    const SKP_int    Fs_kHz,             /* I    Sample frequency (kHz)                                      */\r
-    const SKP_int    complexity,         /* I    Complexity setting, 0-2, where 2 is highest                 */\r
-       const SKP_int    forLJC                      /* I        1 if this function is called from LJC code, 0 otherwise.    */\r
-);\r
-\r
-/* parameter defining the size and accuracy of the piecewise linear    */\r
-/* cosine approximatin table.                                        */\r
-\r
-#define LSF_COS_TAB_SZ_FIX      128\r
-/* rom table with cosine values */\r
-extern const SKP_int SKP_Silk_LSFCosTab_FIX_Q12[ LSF_COS_TAB_SZ_FIX + 1 ];\r
-\r
-/* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients        */\r
-/* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence.    */\r
-void SKP_Silk_A2NLSF(\r
-    SKP_int            *NLSF,            /* O    Normalized Line Spectral Frequencies, Q15 (0 - (2^15-1)), [d] */\r
-    SKP_int32          *a_Q16,           /* I/O  Monic whitening filter coefficients in Q16 [d]                */\r
-    const SKP_int      d                 /* I    Filter order (must be even)                                   */\r
-);\r
-\r
-/* compute whitening filter coefficients from normalized line spectral frequencies */\r
-void SKP_Silk_NLSF2A(\r
-    SKP_int16          *a,               /* o    monic whitening filter coefficients in Q12,  [d]    */\r
-    const SKP_int      *NLSF,            /* i    normalized line spectral frequencies in Q15, [d]    */\r
-    const SKP_int      d                 /* i    filter order (should be even)                       */\r
-);\r
-\r
-void SKP_Silk_insertion_sort_increasing(\r
-    SKP_int32            *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
-void SKP_Silk_insertion_sort_decreasing_int16(\r
-    SKP_int16            *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
-void SKP_Silk_insertion_sort_increasing_all_values(\r
-     SKP_int             *a,            /* I/O:  Unsorted / Sorted vector                */\r
-     const SKP_int       L              /* I:    Vector length                           */\r
-);\r
-\r
-/* NLSF stabilizer, for a single input data vector */\r
-void SKP_Silk_NLSF_stabilize(\r
-          SKP_int        *NLSF_Q15,      /* I/O:  Unstable/stabilized normalized LSF vector in Q15 [L]                    */\r
-    const SKP_int        *NDeltaMin_Q15, /* I:    Normalized delta min vector in Q15, NDeltaMin_Q15[L] must be >= 1 [L+1] */\r
-    const SKP_int        L               /* I:    Number of NLSF parameters in the input vector                           */\r
-);\r
-\r
-/* Laroia low complexity NLSF weights */\r
-void SKP_Silk_NLSF_VQ_weights_laroia(\r
-    SKP_int              *pNLSFW_Q6,     /* O:    Pointer to input vector weights            [D x 1]       */\r
-    const SKP_int        *pNLSF_Q15,     /* I:    Pointer to input vector                    [D x 1]       */\r
-    const SKP_int        D               /* I:    Input vector dimension (even)                            */\r
-);\r
-\r
-/* Compute reflection coefficients from input signal */\r
-void SKP_Silk_burg_modified(        \r
-    SKP_int32            *res_nrg,           /* O   residual energy                                                 */\r
-    SKP_int              *res_nrgQ,          /* O   residual energy Q value                                         */\r
-    SKP_int32            A_Q16[],            /* O   prediction coefficients (length order)                          */\r
-    const SKP_int16      x[],                /* I   input signal, length: nb_subfr * ( D + subfr_length )           */\r
-    const SKP_int        subfr_length,       /* I   input signal subframe length (including D preceeding samples)   */\r
-    const SKP_int        nb_subfr,           /* I   number of subframes stacked in x                                */\r
-    const SKP_int32      WhiteNoiseFrac_Q32, /* I   fraction added to zero-lag autocorrelation                      */\r
-    const SKP_int        D                   /* I   order                                                           */\r
-);\r
-\r
-/* Copy and multiply a vector by a constant */\r
-void SKP_Silk_scale_copy_vector16( \r
-    SKP_int16            *data_out, \r
-    const SKP_int16      *data_in, \r
-    SKP_int32            gain_Q16,           /* I:   gain in Q16   */\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
-    SKP_int32            gain_Q26,           /* I:   Q26           */\r
-    SKP_int              dataSize            /* I:   length        */\r
-);\r
-\r
-/********************************************************************/\r
-/*                        INLINE ARM MATH                             */\r
-/********************************************************************/\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
-);\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
-);\r
-/********************************************************************/\r
-/*                                MACROS                            */\r
-/********************************************************************/\r
-\r
-/* Rotate a32 right by 'rot' bits. Negative rot values result in rotating\r
-   left. Output is 32bit int.\r
-   Note: contemporary compilers recognize the C expression below and\r
-   compile it into a 'ror' instruction if available. No need for inline ASM! */\r
-SKP_INLINE SKP_int32 SKP_ROR32( SKP_int32 a32, SKP_int rot )\r
-{\r
-    SKP_uint32 x = (SKP_uint32) a32;\r
-    SKP_uint32 r = (SKP_uint32) rot;\r
-    SKP_uint32 m = (SKP_uint32) -rot;\r
-    if(rot <= 0)\r
-        return (SKP_int32) ((x << m) | (x >> (32 - m)));\r
-    else\r
-        return (SKP_int32) ((x << (32 - r)) | (x >> r));\r
-}\r
-\r
-/* Allocate SKP_int16 alligned to 4-byte memory address */\r
-#define SKP_DWORD_ALIGN\r
-\r
-/* Useful Macros that can be adjusted to other platforms */\r
-#define SKP_memcpy(a, b, c)                memcpy((a), (b), (c))    /* Dest, Src, ByteCount */\r
-#define SKP_memset(a, b, c)                memset((a), (b), (c))    /* Dest, value, ByteCount */\r
-#define SKP_memmove(a, b, c)               memmove((a), (b), (c))    /* Dest, Src, ByteCount */\r
-/* fixed point macros */\r
-\r
-// (a32 * b32) output have to be 32bit int\r
-#define SKP_MUL(a32, b32)                  ((a32) * (b32))\r
-\r
-// (a32 * b32) output have to be 32bit uint\r
-#define SKP_MUL_uint(a32, b32)             SKP_MUL(a32, b32)\r
-\r
-// a32 + (b32 * c32) output have to be 32bit int\r
-#define SKP_MLA(a32, b32, c32)             SKP_ADD32((a32),((b32) * (c32)))\r
-\r
-// a32 + ((a32 >> 16)  * (b32 >> 16)) output have to be 32bit int\r
-#define SKP_SMLATT(a32, b32, c32)          SKP_ADD32((a32),((b32) >> 16) * ((c32) >> 16))\r
-\r
-#define SKP_SMLALBB(a64, b16, c16)         SKP_ADD64((a64),(SKP_int64)((SKP_int32)(b16) * (SKP_int32)(c16)))\r
-\r
-// (a32 * b32)\r
-#define SKP_SMULL(a32, b32)                ((SKP_int64)(a32) * /*(SKP_int64)*/(b32))\r
-\r
-// multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode)\r
-#define SKP_MLA_ovflw(a32, b32, c32)       SKP_MLA(a32, b32, c32)\r
-#ifndef SKP_SMLABB_ovflw\r
-#    define SKP_SMLABB_ovflw(a32, b32, c32)    SKP_SMLABB(a32, b32, c32)\r
-#endif\r
-#define SKP_SMLATT_ovflw(a32, b32, c32)    SKP_SMLATT(a32, b32, c32)\r
-#define SKP_SMLAWB_ovflw(a32, b32, c32)    SKP_SMLAWB(a32, b32, c32)\r
-#define SKP_SMLAWT_ovflw(a32, b32, c32)    SKP_SMLAWT(a32, b32, c32)\r
-\r
-#define SKP_DIV32_16(a32, b16)             ((SKP_int32)((a32) / (b16)))\r
-#define SKP_DIV32(a32, b32)                ((SKP_int32)((a32) / (b32)))\r
-\r
-#define SKP_ADD32(a, b)                    ((a) + (b))\r
-#define SKP_ADD64(a, b)                    ((a) + (b))\r
-\r
-#define SKP_SUB32(a, b)                    ((a) - (b))\r
-\r
-#define SKP_SAT16(a)                       ((a) > SKP_int16_MAX ? SKP_int16_MAX : \\r
-                                           ((a) < SKP_int16_MIN ? SKP_int16_MIN : (a)))\r
-#define SKP_SAT32(a)                       ((a) > SKP_int32_MAX ? SKP_int32_MAX : \\r
-                                           ((a) < SKP_int32_MIN ? SKP_int32_MIN : (a)))\r
-\r
-#define SKP_CHECK_FIT16(a)                 (a)\r
-#define SKP_CHECK_FIT32(a)                 (a)\r
-\r
-#define SKP_ADD_SAT16(a, b)                (SKP_int16)SKP_SAT16( SKP_ADD32( (SKP_int32)(a), (b) ) )\r
-\r
-/* Add with saturation for positive input values */ \r
-#define SKP_ADD_POS_SAT32(a, b)            ((((a)+(b)) & 0x80000000)           ? SKP_int32_MAX : ((a)+(b)))\r
-\r
-#define SKP_LSHIFT32(a, shift)             ((a)<<(shift))                // shift >= 0, shift < 32\r
-#define SKP_LSHIFT64(a, shift)             ((a)<<(shift))                // shift >= 0, shift < 64\r
-#define SKP_LSHIFT(a, shift)               SKP_LSHIFT32(a, shift)        // shift >= 0, shift < 32\r
-\r
-#define SKP_RSHIFT32(a, shift)             ((a)>>(shift))                // shift >= 0, shift < 32\r
-#define SKP_RSHIFT64(a, shift)             ((a)>>(shift))                // shift >= 0, shift < 64\r
-#define SKP_RSHIFT(a, shift)               SKP_RSHIFT32(a, shift)        // shift >= 0, shift < 32\r
-\r
-/* saturates before shifting */\r
-#define SKP_LSHIFT_SAT32(a, shift)         (SKP_LSHIFT32( SKP_LIMIT( (a), SKP_RSHIFT32( SKP_int32_MIN, (shift) ),    \\r
-                                                                          SKP_RSHIFT32( SKP_int32_MAX, (shift) ) ), (shift) ))\r
-\r
-#define SKP_LSHIFT_ovflw(a, shift)        ((a)<<(shift))        // shift >= 0, allowed to overflow\r
-#define SKP_LSHIFT_uint(a, shift)         ((a)<<(shift))        // shift >= 0\r
-#define SKP_RSHIFT_uint(a, shift)         ((a)>>(shift))        // shift >= 0\r
-\r
-#define SKP_ADD_LSHIFT(a, b, shift)       ((a) + SKP_LSHIFT((b), (shift)))            // shift >= 0\r
-#define SKP_ADD_LSHIFT32(a, b, shift)     SKP_ADD32((a), SKP_LSHIFT32((b), (shift)))    // shift >= 0\r
-#define SKP_ADD_RSHIFT(a, b, shift)       ((a) + SKP_RSHIFT((b), (shift)))            // shift >= 0\r
-#define SKP_ADD_RSHIFT32(a, b, shift)     SKP_ADD32((a), SKP_RSHIFT32((b), (shift)))    // shift >= 0\r
-#define SKP_ADD_RSHIFT_uint(a, b, shift)  ((a) + SKP_RSHIFT_uint((b), (shift)))        // shift >= 0\r
-#define SKP_SUB_LSHIFT32(a, b, shift)     SKP_SUB32((a), SKP_LSHIFT32((b), (shift)))    // shift >= 0\r
-#define SKP_SUB_RSHIFT32(a, b, shift)     SKP_SUB32((a), SKP_RSHIFT32((b), (shift)))    // shift >= 0\r
-\r
-/* Requires that shift > 0 */\r
-#define SKP_RSHIFT_ROUND(a, shift)        ((shift) == 1 ? ((a) >> 1) + ((a) & 1) : (((a) >> ((shift) - 1)) + 1) >> 1)\r
-#define SKP_RSHIFT_ROUND64(a, shift)      ((shift) == 1 ? ((a) >> 1) + ((a) & 1) : (((a) >> ((shift) - 1)) + 1) >> 1)\r
-\r
-/* Number of rightshift required to fit the multiplication */\r
-#define SKP_NSHIFT_MUL_32_32(a, b)        ( -(31- (32-SKP_Silk_CLZ32(SKP_abs(a)) + (32-SKP_Silk_CLZ32(SKP_abs(b))))) )\r
-\r
-#define SKP_min(a, b)                     (((a) < (b)) ? (a) : (b)) \r
-#define SKP_max(a, b)                     (((a) > (b)) ? (a) : (b))\r
-\r
-/* Macro to convert floating-point constants to fixed-point */\r
-#define SKP_FIX_CONST( C, Q )           ((SKP_int32)((C) * ((SKP_int64)1 << (Q)) + 0.5))\r
-\r
-/* SKP_min() versions with typecast in the function call */\r
-SKP_INLINE SKP_int SKP_min_int(SKP_int a, SKP_int b)\r
-{\r
-    return (((a) < (b)) ? (a) : (b));\r
-}\r
-\r
-SKP_INLINE SKP_int32 SKP_min_32(SKP_int32 a, SKP_int32 b)\r
-{\r
-    return (((a) < (b)) ? (a) : (b));\r
-}\r
-\r
-/* SKP_min() versions with typecast in the function call */\r
-SKP_INLINE SKP_int SKP_max_int(SKP_int a, SKP_int b)\r
-{\r
-    return (((a) > (b)) ? (a) : (b));\r
-}\r
-SKP_INLINE SKP_int16 SKP_max_16(SKP_int16 a, SKP_int16 b)\r
-{\r
-    return (((a) > (b)) ? (a) : (b));\r
-}\r
-SKP_INLINE SKP_int32 SKP_max_32(SKP_int32 a, SKP_int32 b)\r
-{\r
-    return (((a) > (b)) ? (a) : (b));\r
-}\r
-\r
-#define SKP_LIMIT( a, limit1, limit2)    ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \\r
-                                                             : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))))\r
-\r
-#define SKP_LIMIT_int SKP_LIMIT\r
-#define SKP_LIMIT_32 SKP_LIMIT\r
-\r
-//#define SKP_non_neg(a)                 ((a) & ((-(a)) >> (8 * sizeof(a) - 1)))   /* doesn't seem faster than SKP_max(0, a);\r
-\r
-#define SKP_abs(a)                       (((a) >  0)  ? (a) : -(a))            // Be careful, SKP_abs returns wrong when input equals to SKP_intXX_MIN\r
-#define SKP_abs_int32(a)                 (((a) ^ ((a) >> 31)) - ((a) >> 31))\r
-\r
-/* PSEUDO-RANDOM GENERATOR                                                          */\r
-/* Make sure to store the result as the seed for the next call (also in between     */\r
-/* frames), otherwise result won't be random at all. When only using some of the    */\r
-/* bits, take the most significant bits by right-shifting. Do not just mask off     */\r
-/* the lowest bits.                                                                 */\r
-#define SKP_RAND(seed)                   (SKP_MLA_ovflw(907633515, (seed), 196314165))\r
-\r
-// Add some multiplication functions that can be easily mapped to ARM.\r
-\r
-//    SKP_SMMUL: Signed top word multiply. \r
-//        ARMv6        2 instruction cycles. \r
-//        ARMv3M+        3 instruction cycles. use SMULL and ignore LSB registers.(except xM) \r
-//#define SKP_SMMUL(a32, b32)            (SKP_int32)SKP_RSHIFT(SKP_SMLAL(SKP_SMULWB((a32), (b32)), (a32), SKP_RSHIFT_ROUND((b32), 16)), 16)\r
-// the following seems faster on x86\r
-#define SKP_SMMUL(a32, b32)              (SKP_int32)SKP_RSHIFT64(SKP_SMULL((a32), (b32)), 32)\r
-\r
-#include "SKP_Silk_Inlines.h"\r
-\r
-#ifdef  __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef _SKP_SILK_SIGPROC_FIX_H_
+#define _SKP_SILK_SIGPROC_FIX_H_
+
+#ifdef  __cplusplus
+extern "C"
+{
+#endif
+
+#define SKP_Silk_MAX_ORDER_LPC            16                    /* max order of the LPC analysis in schur() and k2a()    */
+#define SKP_Silk_MAX_CORRELATION_LENGTH   640                   /* max input length to the correlation                    */
+#include "SKP_Silk_typedef.h"
+#include <string.h>
+#include <stdlib.h>                                            /* for abs() */
+#include "SKP_Silk_resampler_structs.h"
+
+#      include "SKP_Silk_macros.h"
+
+
+
+/********************************************************************/
+/*                    SIGNAL PROCESSING FUNCTIONS                   */
+/********************************************************************/
+
+/*!
+ * Initialize/reset the resampler state for a given pair of input/output sampling rates 
+*/
+SKP_int SKP_Silk_resampler_init( 
+       SKP_Silk_resampler_state_struct *S,                 /* I/O: Resampler state                     */
+       SKP_int32                                                       Fs_Hz_in,       /* I:   Input sampling rate (Hz)        */
+       SKP_int32                                                       Fs_Hz_out       /* I:   Output sampling rate (Hz)       */
+);
+
+
+/*!
+ * Clear the states of all resampling filters, without resetting sampling rate ratio 
+ */
+SKP_int SKP_Silk_resampler_clear( 
+       SKP_Silk_resampler_state_struct *S                  /* I/O: Resampler state                     */
+);
+
+/*!
+ * Resampler: convert from one sampling rate to another
+ */
+SKP_int SKP_Silk_resampler( 
+       SKP_Silk_resampler_state_struct *S,                 /* I/O: Resampler state                     */
+       SKP_int16                                                       out[],      /* O:       Output signal                           */
+       const SKP_int16                                         in[],       /* I:       Input signal                            */
+       SKP_int32                                                       inLen       /* I:       Number of input samples         */
+);
+
+/*!
+ Upsample 2x, low quality 
+ */
+void SKP_Silk_resampler_up2(
+    SKP_int32                           *S,         /* I/O: State vector [ 2 ]                  */
+    SKP_int16                           *out,       /* O:   Output signal [ 2 * len ]           */
+    const SKP_int16                     *in,        /* I:   Input signal [ len ]                */
+    SKP_int32                           len         /* I:   Number of input samples             */
+);
+
+/*!
+* Downsample 2x, mediocre quality 
+*/
+void SKP_Silk_resampler_down2(
+    SKP_int32                           *S,         /* I/O: State vector [ 2 ]                  */
+    SKP_int16                           *out,       /* O:   Output signal [ len ]               */
+    const SKP_int16                     *in,        /* I:   Input signal [ floor(len/2) ]       */
+    SKP_int32                           inLen       /* I:   Number of input samples             */
+);
+
+
+/*!
+ * Downsample by a factor 2/3, low quality
+*/
+void SKP_Silk_resampler_down2_3(
+    SKP_int32                           *S,         /* I/O: State vector [ 6 ]                  */
+    SKP_int16                           *out,       /* O:   Output signal [ floor(2*inLen/3) ]  */
+    const SKP_int16                     *in,        /* I:   Input signal [ inLen ]              */
+    SKP_int32                           inLen       /* I:   Number of input samples             */
+);
+
+/*!
+ * Downsample by a factor 3, low quality
+*/
+void SKP_Silk_resampler_down3(
+    SKP_int32                           *S,         /* I/O: State vector [ 8 ]                  */
+    SKP_int16                           *out,       /* O:   Output signal [ floor(inLen/3) ]    */
+    const SKP_int16                     *in,        /* I:   Input signal [ inLen ]              */
+    SKP_int32                           inLen       /* I:   Number of input samples             */
+);
+
+/*! 
+ * second order ARMA filter
+ * can handle (slowly) varying coefficients 
+ */
+void SKP_Silk_biquad(
+    const SKP_int16      *in,          /* I:   input signal                */
+    const SKP_int16      *B,           /* I:   MA coefficients, Q13 [3]    */
+    const SKP_int16      *A,           /* I:   AR coefficients, Q13 [2]    */
+          SKP_int32      *S,           /* I/O: state vector [2]            */
+          SKP_int16      *out,         /* O:   output signal               */
+    const SKP_int32      len           /* I:   signal length               */
+);
+/*!
+ * second order ARMA filter; 
+ * slower than biquad() but uses more precise coefficients
+ * can handle (slowly) varying coefficients 
+ */
+void SKP_Silk_biquad_alt(
+    const SKP_int16     *in,           /* I:    input signal                 */
+    const SKP_int32     *B_Q28,        /* I:    MA coefficients [3]          */
+    const SKP_int32     *A_Q28,        /* I:    AR coefficients [2]          */
+    SKP_int32           *S,            /* I/O: state vector [2]              */
+    SKP_int16           *out,          /* O:    output signal                */
+    const SKP_int32     len            /* I:    signal length (must be even) */
+);
+
+/*! 
+ * variable order MA filter. Prediction error filter implementation. Coeficients negated and starting with coef to x[n - 1]
+ */
+void SKP_Silk_MA_Prediction(
+    const SKP_int16      *in,          /* I:   Input signal                                */
+    const SKP_int16      *B,           /* I:   MA prediction coefficients, Q12 [order]     */
+    SKP_int32            *S,           /* I/O: State vector [order]                        */
+    SKP_int16            *out,         /* O:   Output signal                               */
+    const SKP_int32      len,          /* I:   Signal length                               */
+    const SKP_int32      order         /* I:  Filter order                                 */
+);
+
+/*!
+ * 16th order AR filter for LPC synthesis, coefficients are in Q12
+ */
+void SKP_Silk_LPC_synthesis_order16(
+    const SKP_int16      *in,          /* I:   excitation signal                            */
+    const SKP_int16      *A_Q12,       /* I:   AR coefficients [16], between -8_Q0 and 8_Q0 */
+    const SKP_int32      Gain_Q26,     /* I:   gain                                         */
+          SKP_int32      *S,           /* I/O: state vector [16]                            */
+          SKP_int16      *out,         /* O:   output signal                                */
+    const SKP_int32      len           /* I:   signal length, must be multiple of 16        */
+);
+
+/* variable order MA prediction error filter. */
+/* Inverse filter of SKP_Silk_LPC_synthesis_filter */
+void SKP_Silk_LPC_analysis_filter(
+    const SKP_int16      *in,          /* I:   Input signal                                */
+    const SKP_int16      *B,           /* I:   MA prediction coefficients, Q12 [order]     */
+    SKP_int16            *S,           /* I/O: State vector [order]                        */
+    SKP_int16            *out,         /* O:   Output signal                               */
+    const SKP_int32      len,          /* I:   Signal length                               */
+    const SKP_int32      Order         /* I:   Filter order                                */
+);
+
+/* even order AR filter */
+void SKP_Silk_LPC_synthesis_filter(
+    const SKP_int16      *in,          /* I:   excitation signal                               */
+    const SKP_int16      *A_Q12,       /* I:   AR coefficients [Order], between -8_Q0 and 8_Q0 */
+    const SKP_int32      Gain_Q26,     /* I:   gain                                            */
+    SKP_int32            *S,           /* I/O: state vector [Order]                            */
+    SKP_int16            *out,         /* O:   output signal                                   */
+    const SKP_int32      len,          /* I:   signal length                                   */
+    const SKP_int        Order         /* I:   filter order, must be even                      */
+);
+
+/* Chirp (bandwidth expand) LP AR filter */
+void SKP_Silk_bwexpander( 
+    SKP_int16            *ar,          /* I/O  AR filter to be expanded (without leading 1)    */
+    const SKP_int        d,            /* I    Length of ar                                    */
+    SKP_int32            chirp_Q16     /* I    Chirp factor (typically in the range 0 to 1)    */
+);
+
+/* Chirp (bandwidth expand) LP AR filter */
+void SKP_Silk_bwexpander_32( 
+    SKP_int32            *ar,          /* I/O  AR filter to be expanded (without leading 1)    */
+    const SKP_int        d,            /* I    Length of ar                                    */
+    SKP_int32            chirp_Q16     /* I    Chirp factor in Q16                             */
+);
+
+/* Compute inverse of LPC prediction gain, and                           */
+/* test if LPC coefficients are stable (all poles within unit circle)    */
+SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O:  Returns 1 if unstable, otherwise 0          */
+    SKP_int32            *invGain_Q30,  /* O:  Inverse prediction gain, Q30 energy domain  */
+    const SKP_int16      *A_Q12,        /* I:  Prediction coefficients, Q12 [order]        */
+    const SKP_int        order          /* I:  Prediction order                            */
+);
+
+SKP_int SKP_Silk_LPC_inverse_pred_gain_Q24( /* O:   Returns 1 if unstable, otherwise 0      */
+    SKP_int32           *invGain_Q30,   /* O:   Inverse prediction gain, Q30 energy domain  */
+    const SKP_int32     *A_Q24,         /* I:   Prediction coefficients, Q24 [order]        */
+    const SKP_int       order           /* I:   Prediction order                            */
+);
+
+/* split signal in two decimated bands using first-order allpass filters */
+void SKP_Silk_ana_filt_bank_1(
+    const SKP_int16      *in,           /* I:   Input signal [N]        */
+    SKP_int32            *S,            /* I/O: State vector [2]        */
+    SKP_int16            *outL,         /* O:   Low band [N/2]          */
+    SKP_int16            *outH,         /* O:   High band [N/2]         */
+    SKP_int32            *scratch,      /* I:   Scratch memory [3*N/2]  */
+    const SKP_int32      N              /* I:   Number of input samples */
+);
+
+/********************************************************************/
+/*                        SCALAR FUNCTIONS                            */
+/********************************************************************/
+
+/* approximation of 128 * log2() (exact inverse of approx 2^() below) */
+/* convert input to a log scale    */
+SKP_int32 SKP_Silk_lin2log(const SKP_int32 inLin);        /* I: input in linear scale        */
+
+/* Approximation of a sigmoid function */
+SKP_int SKP_Silk_sigm_Q15(SKP_int in_Q5);
+
+/* approximation of 2^() (exact inverse of approx log2() above) */
+/* convert input to a linear scale    */ 
+SKP_int32 SKP_Silk_log2lin(const SKP_int32 inLog_Q7);    /* I: input on log scale */ 
+
+/* Function that returns the maximum absolut value of the input vector */
+SKP_int16 SKP_Silk_int16_array_maxabs(  /* O   Maximum absolute value, max: 2^15-1   */
+    const SKP_int16     *vec,           /* I   Input vector  [len]                   */ 
+    const SKP_int32     len             /* I   Length of input vector                */
+);
+
+/* Compute number of bits to right shift the sum of squares of a vector    */
+/* of int16s to make it fit in an int32                                    */
+void SKP_Silk_sum_sqr_shift(
+    SKP_int32           *energy,        /* O   Energy of x, after shifting to the right            */
+    SKP_int             *shift,         /* O   Number of bits right shift applied to energy        */
+    const SKP_int16     *x,             /* I   Input vector                                        */
+    SKP_int             len             /* I   Length of input vector                              */
+);
+
+/* Calculates the reflection coefficients from the correlation sequence    */
+/* Faster than schur64(), but much less accurate.                          */
+/* uses SMLAWB(), requiring armv5E and higher.                             */ 
+SKP_int32 SKP_Silk_schur(               /* O:    Returns residual energy                   */
+    SKP_int16            *rc_Q15,       /* O:    reflection coefficients [order] Q15       */
+    const SKP_int32      *c,            /* I:    correlations [order+1]                    */
+    const SKP_int32      order          /* I:    prediction order                          */
+);;
+
+/* Calculates the reflection coefficients from the correlation sequence    */
+/* Slower than schur(), but more accurate.                                 */
+/* Uses SMULL(), available on armv4                                        */
+SKP_int32 SKP_Silk_schur64(             /* O:  returns residual energy                     */
+    SKP_int32           rc_Q16[],       /* O:  Reflection coefficients [order] Q16         */
+    const SKP_int32     c[],            /* I:  Correlations [order+1]                      */
+    SKP_int32           order           /* I:  Prediction order                            */
+);
+
+/* Step up function, converts reflection coefficients to prediction coefficients */
+void SKP_Silk_k2a(
+    SKP_int32           *A_Q24,         /* O:  Prediction coefficients [order] Q24         */
+    const SKP_int16     *rc_Q15,        /* I:  Reflection coefficients [order] Q15         */
+    const SKP_int32     order           /* I:  Prediction order                            */
+);
+
+/* Step up function, converts reflection coefficients to prediction coefficients */
+void SKP_Silk_k2a_Q16(
+    SKP_int32           *A_Q24,         /* O:  Prediction coefficients [order] Q24         */
+    const SKP_int32     *rc_Q16,        /* I:  Reflection coefficients [order] Q16         */
+    const SKP_int32     order           /* I:  Prediction order                            */
+);
+
+/* Apply sine window to signal vector.                                      */
+/* Window types:                                                            */
+/*    1 -> sine window from 0 to pi/2                                       */
+/*    2 -> sine window from pi/2 to pi                                      */
+/* Every other sample is linearly interpolated, for speed.                  */
+/* Window length must be between 16 and 120 (incl) and a multiple of 4.     */
+void SKP_Silk_apply_sine_window_new(
+    SKP_int16                        px_win[],            /* O    Pointer to windowed signal                  */
+    const SKP_int16                  px[],                /* I    Pointer to input signal                     */
+    const SKP_int                    win_type,            /* I    Selects a window type                       */
+    const SKP_int                    length               /* I    Window length, multiple of 4                */
+);
+
+/* Compute autocorrelation */
+void SKP_Silk_autocorr( 
+    SKP_int32           *results,       /* O  Result (length correlationCount)            */
+    SKP_int             *scale,         /* O  Scaling of the correlation vector           */
+    const SKP_int16     *inputData,     /* I  Input data to correlate                     */
+    const SKP_int       inputDataSize,  /* I  Length of input                             */
+    const SKP_int       correlationCount /* I  Number of correlation taps to compute      */
+);
+
+/* Pitch estimator */
+#define SKP_Silk_PITCH_EST_MIN_COMPLEX        0
+#define SKP_Silk_PITCH_EST_MID_COMPLEX        1
+#define SKP_Silk_PITCH_EST_MAX_COMPLEX        2
+
+void SKP_Silk_decode_pitch(
+    SKP_int            lagIndex,        /* I                                              */
+    SKP_int            contourIndex,    /* O                                              */
+    SKP_int            pitch_lags[],    /* O 4 pitch values                               */
+    SKP_int            Fs_kHz           /* I sampling frequency (kHz)                     */
+);
+
+SKP_int SKP_Silk_pitch_analysis_core(    /* O    Voicing estimate: 0 voiced, 1 unvoiced                      */
+    const SKP_int16  *signal,            /* I    Signal of length PITCH_EST_FRAME_LENGTH_MS*Fs_kHz           */
+    SKP_int          *pitch_out,         /* O    4 pitch lag values                                          */
+    SKP_int          *lagIndex,          /* O    Lag Index                                                   */
+    SKP_int          *contourIndex,      /* O    Pitch contour Index                                         */
+    SKP_int          *LTPCorr_Q15,       /* I/O  Normalized correlation; input: value from previous frame    */
+    SKP_int          prevLag,            /* I    Last lag of previous frame; set to zero is unvoiced         */
+    const SKP_int32  search_thres1_Q16,  /* I    First stage threshold for lag candidates 0 - 1              */
+    const SKP_int    search_thres2_Q15,  /* I    Final threshold for lag candidates 0 - 1                    */
+    const SKP_int    Fs_kHz,             /* I    Sample frequency (kHz)                                      */
+    const SKP_int    complexity,         /* I    Complexity setting, 0-2, where 2 is highest                 */
+       const SKP_int    forLJC                      /* I        1 if this function is called from LJC code, 0 otherwise.    */
+);
+
+/* parameter defining the size and accuracy of the piecewise linear    */
+/* cosine approximatin table.                                        */
+
+#define LSF_COS_TAB_SZ_FIX      128
+/* rom table with cosine values */
+extern const SKP_int SKP_Silk_LSFCosTab_FIX_Q12[ LSF_COS_TAB_SZ_FIX + 1 ];
+
+/* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients        */
+/* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence.    */
+void SKP_Silk_A2NLSF(
+    SKP_int            *NLSF,            /* O    Normalized Line Spectral Frequencies, Q15 (0 - (2^15-1)), [d] */
+    SKP_int32          *a_Q16,           /* I/O  Monic whitening filter coefficients in Q16 [d]                */
+    const SKP_int      d                 /* I    Filter order (must be even)                                   */
+);
+
+/* compute whitening filter coefficients from normalized line spectral frequencies */
+void SKP_Silk_NLSF2A(
+    SKP_int16          *a,               /* o    monic whitening filter coefficients in Q12,  [d]    */
+    const SKP_int      *NLSF,            /* i    normalized line spectral frequencies in Q15, [d]    */
+    const SKP_int      d                 /* i    filter order (should be even)                       */
+);
+
+void SKP_Silk_insertion_sort_increasing(
+    SKP_int32            *a,            /* I/O   Unsorted / Sorted vector                */
+    SKP_int              *index,        /* O:    Index vector for the sorted elements    */
+    const SKP_int        L,             /* I:    Vector length                           */
+    const SKP_int        K              /* I:    Number of correctly sorted positions    */
+);
+
+void SKP_Silk_insertion_sort_decreasing_int16(
+    SKP_int16            *a,            /* I/O:  Unsorted / Sorted vector                */
+    SKP_int              *index,        /* O:    Index vector for the sorted elements    */
+    const SKP_int        L,             /* I:    Vector length                           */
+    const SKP_int        K              /* I:    Number of correctly sorted positions    */
+);
+
+void SKP_Silk_insertion_sort_increasing_all_values(
+     SKP_int             *a,            /* I/O:  Unsorted / Sorted vector                */
+     const SKP_int       L              /* I:    Vector length                           */
+);
+
+/* NLSF stabilizer, for a single input data vector */
+void SKP_Silk_NLSF_stabilize(
+          SKP_int        *NLSF_Q15,      /* I/O:  Unstable/stabilized normalized LSF vector in Q15 [L]                    */
+    const SKP_int        *NDeltaMin_Q15, /* I:    Normalized delta min vector in Q15, NDeltaMin_Q15[L] must be >= 1 [L+1] */
+    const SKP_int        L               /* I:    Number of NLSF parameters in the input vector                           */
+);
+
+/* Laroia low complexity NLSF weights */
+void SKP_Silk_NLSF_VQ_weights_laroia(
+    SKP_int              *pNLSFW_Q6,     /* O:    Pointer to input vector weights            [D x 1]       */
+    const SKP_int        *pNLSF_Q15,     /* I:    Pointer to input vector                    [D x 1]       */
+    const SKP_int        D               /* I:    Input vector dimension (even)                            */
+);
+
+/* Compute reflection coefficients from input signal */
+void SKP_Silk_burg_modified(        
+    SKP_int32            *res_nrg,           /* O   residual energy                                                 */
+    SKP_int              *res_nrgQ,          /* O   residual energy Q value                                         */
+    SKP_int32            A_Q16[],            /* O   prediction coefficients (length order)                          */
+    const SKP_int16      x[],                /* I   input signal, length: nb_subfr * ( D + subfr_length )           */
+    const SKP_int        subfr_length,       /* I   input signal subframe length (including D preceeding samples)   */
+    const SKP_int        nb_subfr,           /* I   number of subframes stacked in x                                */
+    const SKP_int32      WhiteNoiseFrac_Q32, /* I   fraction added to zero-lag autocorrelation                      */
+    const SKP_int        D                   /* I   order                                                           */
+);
+
+/* Copy and multiply a vector by a constant */
+void SKP_Silk_scale_copy_vector16( 
+    SKP_int16            *data_out, 
+    const SKP_int16      *data_in, 
+    SKP_int32            gain_Q16,           /* I:   gain in Q16   */
+    const SKP_int        dataSize            /* I:   length        */
+);
+
+/* Some for the LTP related function requires Q26 to work.*/
+void SKP_Silk_scale_vector32_Q26_lshift_18( 
+    SKP_int32            *data1,             /* I/O: Q0/Q18        */
+    SKP_int32            gain_Q26,           /* I:   Q26           */
+    SKP_int              dataSize            /* I:   length        */
+);
+
+/********************************************************************/
+/*                        INLINE ARM MATH                             */
+/********************************************************************/
+
+/*    return sum(inVec1[i]*inVec2[i])    */
+/*    inVec1 and inVec2 should be increasing ordered, and starting address should be 4 byte aligned. (a factor of 4)*/
+SKP_int32 SKP_Silk_inner_prod_aligned(
+    const SKP_int16* const inVec1,           /* I   input vector 1    */ 
+    const SKP_int16* const inVec2,           /* I   input vector 2    */
+    const SKP_int          len               /* I   vector lengths    */
+);
+
+SKP_int64 SKP_Silk_inner_prod16_aligned_64(
+    const SKP_int16        *inVec1,          /* I   input vector 1    */
+    const SKP_int16        *inVec2,          /* I   input vector 2    */
+    const SKP_int          len               /* I   vector lengths    */
+);
+/********************************************************************/
+/*                                MACROS                            */
+/********************************************************************/
+
+/* Rotate a32 right by 'rot' bits. Negative rot values result in rotating
+   left. Output is 32bit int.
+   Note: contemporary compilers recognize the C expression below and
+   compile it into a 'ror' instruction if available. No need for inline ASM! */
+SKP_INLINE SKP_int32 SKP_ROR32( SKP_int32 a32, SKP_int rot )
+{
+    SKP_uint32 x = (SKP_uint32) a32;
+    SKP_uint32 r = (SKP_uint32) rot;
+    SKP_uint32 m = (SKP_uint32) -rot;
+    if(rot <= 0)
+        return (SKP_int32) ((x << m) | (x >> (32 - m)));
+    else
+        return (SKP_int32) ((x << (32 - r)) | (x >> r));
+}
+
+/* Allocate SKP_int16 alligned to 4-byte memory address */
+#define SKP_DWORD_ALIGN
+
+/* Useful Macros that can be adjusted to other platforms */
+#define SKP_memcpy(a, b, c)                memcpy((a), (b), (c))    /* Dest, Src, ByteCount */
+#define SKP_memset(a, b, c)                memset((a), (b), (c))    /* Dest, value, ByteCount */
+#define SKP_memmove(a, b, c)               memmove((a), (b), (c))    /* Dest, Src, ByteCount */
+/* fixed point macros */
+
+// (a32 * b32) output have to be 32bit int
+#define SKP_MUL(a32, b32)                  ((a32) * (b32))
+
+// (a32 * b32) output have to be 32bit uint
+#define SKP_MUL_uint(a32, b32)             SKP_MUL(a32, b32)
+
+// a32 + (b32 * c32) output have to be 32bit int
+#define SKP_MLA(a32, b32, c32)             SKP_ADD32((a32),((b32) * (c32)))
+
+// a32 + ((a32 >> 16)  * (b32 >> 16)) output have to be 32bit int
+#define SKP_SMLATT(a32, b32, c32)          SKP_ADD32((a32),((b32) >> 16) * ((c32) >> 16))
+
+#define SKP_SMLALBB(a64, b16, c16)         SKP_ADD64((a64),(SKP_int64)((SKP_int32)(b16) * (SKP_int32)(c16)))
+
+// (a32 * b32)
+#define SKP_SMULL(a32, b32)                ((SKP_int64)(a32) * /*(SKP_int64)*/(b32))
+
+// multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode)
+#define SKP_MLA_ovflw(a32, b32, c32)       SKP_MLA(a32, b32, c32)
+#ifndef SKP_SMLABB_ovflw
+#    define SKP_SMLABB_ovflw(a32, b32, c32)    SKP_SMLABB(a32, b32, c32)
+#endif
+#define SKP_SMLATT_ovflw(a32, b32, c32)    SKP_SMLATT(a32, b32, c32)
+#define SKP_SMLAWB_ovflw(a32, b32, c32)    SKP_SMLAWB(a32, b32, c32)
+#define SKP_SMLAWT_ovflw(a32, b32, c32)    SKP_SMLAWT(a32, b32, c32)
+
+#define SKP_DIV32_16(a32, b16)             ((SKP_int32)((a32) / (b16)))
+#define SKP_DIV32(a32, b32)                ((SKP_int32)((a32) / (b32)))
+
+#define SKP_ADD32(a, b)                    ((a) + (b))
+#define SKP_ADD64(a, b)                    ((a) + (b))
+
+#define SKP_SUB32(a, b)                    ((a) - (b))
+
+#define SKP_SAT16(a)                       ((a) > SKP_int16_MAX ? SKP_int16_MAX : \
+                                           ((a) < SKP_int16_MIN ? SKP_int16_MIN : (a)))
+#define SKP_SAT32(a)                       ((a) > SKP_int32_MAX ? SKP_int32_MAX : \
+                                           ((a) < SKP_int32_MIN ? SKP_int32_MIN : (a)))
+
+#define SKP_CHECK_FIT16(a)                 (a)
+#define SKP_CHECK_FIT32(a)                 (a)
+
+#define SKP_ADD_SAT16(a, b)                (SKP_int16)SKP_SAT16( SKP_ADD32( (SKP_int32)(a), (b) ) )
+
+/* Add with saturation for positive input values */ 
+#define SKP_ADD_POS_SAT32(a, b)            ((((a)+(b)) & 0x80000000)           ? SKP_int32_MAX : ((a)+(b)))
+
+#define SKP_LSHIFT32(a, shift)             ((a)<<(shift))                // shift >= 0, shift < 32
+#define SKP_LSHIFT64(a, shift)             ((a)<<(shift))                // shift >= 0, shift < 64
+#define SKP_LSHIFT(a, shift)               SKP_LSHIFT32(a, shift)        // shift >= 0, shift < 32
+
+#define SKP_RSHIFT32(a, shift)             ((a)>>(shift))                // shift >= 0, shift < 32
+#define SKP_RSHIFT64(a, shift)             ((a)>>(shift))                // shift >= 0, shift < 64
+#define SKP_RSHIFT(a, shift)               SKP_RSHIFT32(a, shift)        // shift >= 0, shift < 32
+
+/* saturates before shifting */
+#define SKP_LSHIFT_SAT32(a, shift)         (SKP_LSHIFT32( SKP_LIMIT( (a), SKP_RSHIFT32( SKP_int32_MIN, (shift) ),    \
+                                                                          SKP_RSHIFT32( SKP_int32_MAX, (shift) ) ), (shift) ))
+
+#define SKP_LSHIFT_ovflw(a, shift)        ((a)<<(shift))        // shift >= 0, allowed to overflow
+#define SKP_LSHIFT_uint(a, shift)         ((a)<<(shift))        // shift >= 0
+#define SKP_RSHIFT_uint(a, shift)         ((a)>>(shift))        // shift >= 0
+
+#define SKP_ADD_LSHIFT(a, b, shift)       ((a) + SKP_LSHIFT((b), (shift)))            // shift >= 0
+#define SKP_ADD_LSHIFT32(a, b, shift)     SKP_ADD32((a), SKP_LSHIFT32((b), (shift)))    // shift >= 0
+#define SKP_ADD_RSHIFT(a, b, shift)       ((a) + SKP_RSHIFT((b), (shift)))            // shift >= 0
+#define SKP_ADD_RSHIFT32(a, b, shift)     SKP_ADD32((a), SKP_RSHIFT32((b), (shift)))    // shift >= 0
+#define SKP_ADD_RSHIFT_uint(a, b, shift)  ((a) + SKP_RSHIFT_uint((b), (shift)))        // shift >= 0
+#define SKP_SUB_LSHIFT32(a, b, shift)     SKP_SUB32((a), SKP_LSHIFT32((b), (shift)))    // shift >= 0
+#define SKP_SUB_RSHIFT32(a, b, shift)     SKP_SUB32((a), SKP_RSHIFT32((b), (shift)))    // shift >= 0
+
+/* Requires that shift > 0 */
+#define SKP_RSHIFT_ROUND(a, shift)        ((shift) == 1 ? ((a) >> 1) + ((a) & 1) : (((a) >> ((shift) - 1)) + 1) >> 1)
+#define SKP_RSHIFT_ROUND64(a, shift)      ((shift) == 1 ? ((a) >> 1) + ((a) & 1) : (((a) >> ((shift) - 1)) + 1) >> 1)
+
+/* Number of rightshift required to fit the multiplication */
+#define SKP_NSHIFT_MUL_32_32(a, b)        ( -(31- (32-SKP_Silk_CLZ32(SKP_abs(a)) + (32-SKP_Silk_CLZ32(SKP_abs(b))))) )
+
+#define SKP_min(a, b)                     (((a) < (b)) ? (a) : (b)) 
+#define SKP_max(a, b)                     (((a) > (b)) ? (a) : (b))
+
+/* Macro to convert floating-point constants to fixed-point */
+#define SKP_FIX_CONST( C, Q )           ((SKP_int32)((C) * ((SKP_int64)1 << (Q)) + 0.5))
+
+/* SKP_min() versions with typecast in the function call */
+SKP_INLINE SKP_int SKP_min_int(SKP_int a, SKP_int b)
+{
+    return (((a) < (b)) ? (a) : (b));
+}
+
+SKP_INLINE SKP_int32 SKP_min_32(SKP_int32 a, SKP_int32 b)
+{
+    return (((a) < (b)) ? (a) : (b));
+}
+
+/* SKP_min() versions with typecast in the function call */
+SKP_INLINE SKP_int SKP_max_int(SKP_int a, SKP_int b)
+{
+    return (((a) > (b)) ? (a) : (b));
+}
+SKP_INLINE SKP_int16 SKP_max_16(SKP_int16 a, SKP_int16 b)
+{
+    return (((a) > (b)) ? (a) : (b));
+}
+SKP_INLINE SKP_int32 SKP_max_32(SKP_int32 a, SKP_int32 b)
+{
+    return (((a) > (b)) ? (a) : (b));
+}
+
+#define SKP_LIMIT( a, limit1, limit2)    ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
+                                                             : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))))
+
+#define SKP_LIMIT_int SKP_LIMIT
+#define SKP_LIMIT_32 SKP_LIMIT
+
+//#define SKP_non_neg(a)                 ((a) & ((-(a)) >> (8 * sizeof(a) - 1)))   /* doesn't seem faster than SKP_max(0, a);
+
+#define SKP_abs(a)                       (((a) >  0)  ? (a) : -(a))            // Be careful, SKP_abs returns wrong when input equals to SKP_intXX_MIN
+#define SKP_abs_int32(a)                 (((a) ^ ((a) >> 31)) - ((a) >> 31))
+
+/* PSEUDO-RANDOM GENERATOR                                                          */
+/* Make sure to store the result as the seed for the next call (also in between     */
+/* frames), otherwise result won't be random at all. When only using some of the    */
+/* bits, take the most significant bits by right-shifting. Do not just mask off     */
+/* the lowest bits.                                                                 */
+#define SKP_RAND(seed)                   (SKP_MLA_ovflw(907633515, (seed), 196314165))
+
+// Add some multiplication functions that can be easily mapped to ARM.
+
+//    SKP_SMMUL: Signed top word multiply. 
+//        ARMv6        2 instruction cycles. 
+//        ARMv3M+        3 instruction cycles. use SMULL and ignore LSB registers.(except xM) 
+//#define SKP_SMMUL(a32, b32)            (SKP_int32)SKP_RSHIFT(SKP_SMLAL(SKP_SMULWB((a32), (b32)), (a32), SKP_RSHIFT_ROUND((b32), 16)), 16)
+// the following seems faster on x86
+#define SKP_SMMUL(a32, b32)              (SKP_int32)SKP_RSHIFT64(SKP_SMULL((a32), (b32)), 32)
+
+#include "SKP_Silk_Inlines.h"
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
index c151663e6dd014073eb23c04d25571c05a3b48e3..b583c4336b487194424adda3312ee010a29145b9 100644 (file)
-/***********************************************************************\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
- * File Name:   SKP_Silk_VAD.c\r
- * Description: Silk VAD.\r
- */\r
-\r
-#include <stdlib.h>\r
-#include "SKP_Silk_main.h"\r
-\r
-/**********************************/\r
-/* Initialization of the Silk VAD */\r
-/**********************************/\r
-SKP_int SKP_Silk_VAD_Init(                              /* O    Return value, 0 if success                  */ \r
-    SKP_Silk_VAD_state              *psSilk_VAD         /* I/O  Pointer to Silk VAD state                   */ \r
-)\r
-{\r
-    SKP_int b, ret = 0;\r
-\r
-    /* reset state memory */\r
-    SKP_memset( psSilk_VAD, 0, sizeof( SKP_Silk_VAD_state ) );\r
-\r
-    /* init noise levels */\r
-    /* Initialize array with approx pink noise levels (psd proportional to inverse of frequency) */\r
-    for( b = 0; b < VAD_N_BANDS; b++ ) {\r
-        psSilk_VAD->NoiseLevelBias[ b ] = SKP_max_32( SKP_DIV32_16( VAD_NOISE_LEVELS_BIAS, b + 1 ), 1 );\r
-    }\r
-\r
-    /* Initialize state */\r
-    for( b = 0; b < VAD_N_BANDS; b++ ) {\r
-        psSilk_VAD->NL[ b ]     = SKP_MUL( 100, psSilk_VAD->NoiseLevelBias[ b ] );\r
-        psSilk_VAD->inv_NL[ b ] = SKP_DIV32( SKP_int32_MAX, psSilk_VAD->NL[ b ] );\r
-    }\r
-    psSilk_VAD->counter = 15;\r
-\r
-    /* init smoothed energy-to-noise ratio*/\r
-    for( b = 0; b < VAD_N_BANDS; b++ ) {\r
-        psSilk_VAD->NrgRatioSmth_Q8[ b ] = 100 * 256;       /* 100 * 256 --> 20 dB SNR */\r
-    }\r
-\r
-    return( ret );\r
-}\r
-\r
-/* Weighting factors for tilt measure */\r
-const static SKP_int32 tiltWeights[ VAD_N_BANDS ] = { 30000, 6000, -12000, -12000 };\r
-\r
-/***************************************/\r
-/* Get the speech activity level in Q8 */\r
-/***************************************/\r
-SKP_int SKP_Silk_VAD_GetSA_Q8(                                      /* O    Return value, 0 if success      */\r
-    SKP_Silk_VAD_state              *psSilk_VAD,                    /* I/O  Silk VAD state                  */\r
-    SKP_int                         *pSA_Q8,                        /* O    Speech activity level in Q8     */\r
-    SKP_int                         *pSNR_dB_Q7,                    /* O    SNR for current frame in Q7     */\r
-    SKP_int                         pQuality_Q15[ VAD_N_BANDS ],    /* O    Smoothed SNR for each band      */\r
-    SKP_int                         *pTilt_Q15,                     /* O    current frame's frequency tilt  */\r
-    const SKP_int16                 pIn[],                          /* I    PCM input       [framelength]   */\r
-    const SKP_int                   framelength                     /* I    Input frame length              */\r
-)\r
-{\r
-    SKP_int   SA_Q15, input_tilt;\r
-    SKP_int32 scratch[ 3 * MAX_FRAME_LENGTH / 2 ];\r
-    SKP_int   decimated_framelength, dec_subframe_length, dec_subframe_offset, SNR_Q7, i, b, s;\r
-    SKP_int32 sumSquared, smooth_coef_Q16;\r
-    SKP_int16 HPstateTmp;\r
-\r
-    SKP_int16 X[ VAD_N_BANDS ][ MAX_FRAME_LENGTH / 2 ];\r
-    SKP_int32 Xnrg[ VAD_N_BANDS ];\r
-    SKP_int32 NrgToNoiseRatio_Q8[ VAD_N_BANDS ];\r
-    SKP_int32 speech_nrg, x_tmp;\r
-    SKP_int   ret = 0;\r
-\r
-    /* Safety checks */\r
-    SKP_assert( VAD_N_BANDS == 4 );\r
-    SKP_assert( MAX_FRAME_LENGTH >= framelength );\r
-    SKP_assert( framelength <= 512 );\r
-\r
-    /***********************/\r
-    /* Filter and Decimate */\r
-    /***********************/\r
-    /* 0-8 kHz to 0-4 kHz and 4-8 kHz */\r
-    SKP_Silk_ana_filt_bank_1( pIn,          &psSilk_VAD->AnaState[  0 ], &X[ 0 ][ 0 ], &X[ 3 ][ 0 ], &scratch[ 0 ], framelength );        \r
-    \r
-    /* 0-4 kHz to 0-2 kHz and 2-4 kHz */\r
-    SKP_Silk_ana_filt_bank_1( &X[ 0 ][ 0 ], &psSilk_VAD->AnaState1[ 0 ], &X[ 0 ][ 0 ], &X[ 2 ][ 0 ], &scratch[ 0 ], SKP_RSHIFT( framelength, 1 ) );\r
-    \r
-    /* 0-2 kHz to 0-1 kHz and 1-2 kHz */\r
-    SKP_Silk_ana_filt_bank_1( &X[ 0 ][ 0 ], &psSilk_VAD->AnaState2[ 0 ], &X[ 0 ][ 0 ], &X[ 1 ][ 0 ], &scratch[ 0 ], SKP_RSHIFT( framelength, 2 ) );\r
-\r
-    /*********************************************/\r
-    /* HP filter on lowest band (differentiator) */\r
-    /*********************************************/\r
-    decimated_framelength = SKP_RSHIFT( framelength, 3 );\r
-    X[ 0 ][ decimated_framelength - 1 ] = SKP_RSHIFT( X[ 0 ][ decimated_framelength - 1 ], 1 );\r
-    HPstateTmp = X[ 0 ][ decimated_framelength - 1 ];\r
-    for( i = decimated_framelength - 1; i > 0; i-- ) {\r
-        X[ 0 ][ i - 1 ]  = SKP_RSHIFT( X[ 0 ][ i - 1 ], 1 );\r
-        X[ 0 ][ i ]     -= X[ 0 ][ i - 1 ];\r
-    }\r
-    X[ 0 ][ 0 ] -= psSilk_VAD->HPstate;\r
-    psSilk_VAD->HPstate = HPstateTmp;\r
-\r
-    /*************************************/\r
-    /* Calculate the energy in each band */\r
-    /*************************************/\r
-    for( b = 0; b < VAD_N_BANDS; b++ ) {        \r
-        /* Find the decimated framelength in the non-uniformly divided bands */\r
-        decimated_framelength = SKP_RSHIFT( framelength, SKP_min_int( VAD_N_BANDS - b, VAD_N_BANDS - 1 ) );\r
-\r
-        /* Split length into subframe lengths */\r
-        dec_subframe_length = SKP_RSHIFT( decimated_framelength, VAD_INTERNAL_SUBFRAMES_LOG2 );\r
-        dec_subframe_offset = 0;\r
-\r
-        /* Compute energy per sub-frame */\r
-        /* initialize with summed energy of last subframe */\r
-        Xnrg[ b ] = psSilk_VAD->XnrgSubfr[ b ];\r
-        for( s = 0; s < VAD_INTERNAL_SUBFRAMES; s++ ) {\r
-            sumSquared = 0;\r
-            for( i = 0; i < dec_subframe_length; i++ ) {\r
-                /* The energy will be less than dec_subframe_length * ( SKP_int16_MIN / 8 ) ^ 2.            */\r
-                /* Therefore we can accumulate with no risk of overflow (unless dec_subframe_length > 128)  */\r
-                x_tmp = SKP_RSHIFT( X[ b ][ i + dec_subframe_offset ], 3 );\r
-                sumSquared = SKP_SMLABB( sumSquared, x_tmp, x_tmp );\r
-\r
-                /* Safety check */\r
-                SKP_assert( sumSquared >= 0 );\r
-            }\r
-\r
-            /* Add/saturate summed energy of current subframe */\r
-            if( s < VAD_INTERNAL_SUBFRAMES - 1 ) {\r
-                Xnrg[ b ] = SKP_ADD_POS_SAT32( Xnrg[ b ], sumSquared );\r
-            } else {\r
-                /* Look-ahead subframe */\r
-                Xnrg[ b ] = SKP_ADD_POS_SAT32( Xnrg[ b ], SKP_RSHIFT( sumSquared, 1 ) );\r
-            }\r
-\r
-            dec_subframe_offset += dec_subframe_length;\r
-        }\r
-        psSilk_VAD->XnrgSubfr[ b ] = sumSquared; \r
-    }\r
-\r
-    /********************/\r
-    /* Noise estimation */\r
-    /********************/\r
-    SKP_Silk_VAD_GetNoiseLevels( &Xnrg[ 0 ], psSilk_VAD );\r
-\r
-    /***********************************************/\r
-    /* Signal-plus-noise to noise ratio estimation */\r
-    /***********************************************/\r
-    sumSquared = 0;\r
-    input_tilt = 0;\r
-    for( b = 0; b < VAD_N_BANDS; b++ ) {\r
-        speech_nrg = Xnrg[ b ] - psSilk_VAD->NL[ b ];\r
-        if( speech_nrg > 0 ) {\r
-            /* Divide, with sufficient resolution */\r
-            if( ( Xnrg[ b ] & 0xFF800000 ) == 0 ) {\r
-                NrgToNoiseRatio_Q8[ b ] = SKP_DIV32( SKP_LSHIFT( Xnrg[ b ], 8 ), psSilk_VAD->NL[ b ] + 1 );\r
-            } else {\r
-                NrgToNoiseRatio_Q8[ b ] = SKP_DIV32( Xnrg[ b ], SKP_RSHIFT( psSilk_VAD->NL[ b ], 8 ) + 1 );\r
-            }\r
-\r
-            /* Convert to log domain */\r
-            SNR_Q7 = SKP_Silk_lin2log( NrgToNoiseRatio_Q8[ b ] ) - 8 * 128;\r
-\r
-            /* Sum-of-squares */\r
-            sumSquared = SKP_SMLABB( sumSquared, SNR_Q7, SNR_Q7 );          /* Q14 */\r
-\r
-            /* Tilt measure */\r
-            if( speech_nrg < ( 1 << 20 ) ) {\r
-                /* Scale down SNR value for small subband speech energies */\r
-                SNR_Q7 = SKP_SMULWB( SKP_LSHIFT( SKP_Silk_SQRT_APPROX( speech_nrg ), 6 ), SNR_Q7 );\r
-            }\r
-            input_tilt = SKP_SMLAWB( input_tilt, tiltWeights[ b ], SNR_Q7 );\r
-        } else {\r
-            NrgToNoiseRatio_Q8[ b ] = 256;\r
-        }\r
-    }\r
-\r
-    /* Mean-of-squares */\r
-    sumSquared = SKP_DIV32_16( sumSquared, VAD_N_BANDS ); /* Q14 */\r
-\r
-    /* Root-mean-square approximation, scale to dBs, and write to output pointer */\r
-    *pSNR_dB_Q7 = ( SKP_int16 )( 3 * SKP_Silk_SQRT_APPROX( sumSquared ) );  /* Q7 */\r
-\r
-    /*********************************/\r
-    /* Speech Probability Estimation */\r
-    /*********************************/\r
-    SA_Q15 = SKP_Silk_sigm_Q15( SKP_SMULWB( VAD_SNR_FACTOR_Q16, *pSNR_dB_Q7 ) - VAD_NEGATIVE_OFFSET_Q5 );\r
-\r
-    /**************************/\r
-    /* Frequency Tilt Measure */\r
-    /**************************/\r
-    *pTilt_Q15 = SKP_LSHIFT( SKP_Silk_sigm_Q15( input_tilt ) - 16384, 1 );\r
-\r
-    /**************************************************/\r
-    /* Scale the sigmoid output based on power levels */\r
-    /**************************************************/\r
-    speech_nrg = 0;\r
-    for( b = 0; b < VAD_N_BANDS; b++ ) {\r
-        /* Accumulate signal-without-noise energies, higher frequency bands have more weight */\r
-        speech_nrg += ( b + 1 ) * SKP_RSHIFT( Xnrg[ b ] - psSilk_VAD->NL[ b ], 4 );\r
-    }\r
-\r
-    /* Power scaling */\r
-    if( speech_nrg <= 0 ) {\r
-        SA_Q15 = SKP_RSHIFT( SA_Q15, 1 ); \r
-    } else if( speech_nrg < 32768 ) {\r
-        /* square-root */\r
-        speech_nrg = SKP_Silk_SQRT_APPROX( SKP_LSHIFT( speech_nrg, 15 ) );\r
-        SA_Q15 = SKP_SMULWB( 32768 + speech_nrg, SA_Q15 ); \r
-    }\r
-\r
-    /* Copy the resulting speech activity in Q8 to *pSA_Q8 */\r
-    *pSA_Q8 = SKP_min_int( SKP_RSHIFT( SA_Q15, 7 ), SKP_uint8_MAX );\r
-\r
-    /***********************************/\r
-    /* Energy Level and SNR estimation */\r
-    /***********************************/\r
-    /* Smoothing coefficient */\r
-    smooth_coef_Q16 = SKP_SMULWB( VAD_SNR_SMOOTH_COEF_Q18, SKP_SMULWB( SA_Q15, SA_Q15 ) );\r
-    for( b = 0; b < VAD_N_BANDS; b++ ) {\r
-        /* compute smoothed energy-to-noise ratio per band */\r
-        psSilk_VAD->NrgRatioSmth_Q8[ b ] = SKP_SMLAWB( psSilk_VAD->NrgRatioSmth_Q8[ b ], \r
-            NrgToNoiseRatio_Q8[ b ] - psSilk_VAD->NrgRatioSmth_Q8[ b ], smooth_coef_Q16 );\r
-\r
-        /* signal to noise ratio in dB per band */\r
-        SNR_Q7 = 3 * ( SKP_Silk_lin2log( psSilk_VAD->NrgRatioSmth_Q8[b] ) - 8 * 128 );\r
-        /* quality = sigmoid( 0.25 * ( SNR_dB - 16 ) ); */\r
-        pQuality_Q15[ b ] = SKP_Silk_sigm_Q15( SKP_RSHIFT( SNR_Q7 - 16 * 128, 4 ) );\r
-    }\r
-\r
-    return( ret );\r
-}\r
-\r
-/**************************/\r
-/* Noise level estimation */\r
-/**************************/\r
-void SKP_Silk_VAD_GetNoiseLevels(\r
-    const SKP_int32                 pX[ VAD_N_BANDS ],  /* I    subband energies                            */\r
-    SKP_Silk_VAD_state              *psSilk_VAD         /* I/O  Pointer to Silk VAD state                   */ \r
-)\r
-{\r
-    SKP_int   k;\r
-    SKP_int32 nl, nrg, inv_nrg;\r
-    SKP_int   coef, min_coef;\r
-\r
-    /* Initially faster smoothing */\r
-    if( psSilk_VAD->counter < 1000 ) { /* 1000 = 20 sec */\r
-        min_coef = SKP_DIV32_16( SKP_int16_MAX, SKP_RSHIFT( psSilk_VAD->counter, 4 ) + 1 );  \r
-    } else {\r
-        min_coef = 0;\r
-    }\r
-\r
-    for( k = 0; k < VAD_N_BANDS; k++ ) {\r
-        /* Get old noise level estimate for current band */\r
-        nl = psSilk_VAD->NL[ k ];\r
-        SKP_assert( nl >= 0 );\r
-        \r
-        /* Add bias */\r
-        nrg = SKP_ADD_POS_SAT32( pX[ k ], psSilk_VAD->NoiseLevelBias[ k ] ); \r
-        SKP_assert( nrg > 0 );\r
-        \r
-        /* Invert energies */\r
-        inv_nrg = SKP_DIV32( SKP_int32_MAX, nrg );\r
-        SKP_assert( inv_nrg >= 0 );\r
-        \r
-        /* Less update when subband energy is high */\r
-        if( nrg > SKP_LSHIFT( nl, 3 ) ) {\r
-            coef = VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 >> 3;\r
-        } else if( nrg < nl ) {\r
-            coef = VAD_NOISE_LEVEL_SMOOTH_COEF_Q16;\r
-        } else {\r
-            coef = SKP_SMULWB( SKP_SMULWW( inv_nrg, nl ), VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 << 1 );\r
-        }\r
-\r
-        /* Initially faster smoothing */\r
-        coef = SKP_max_int( coef, min_coef );\r
-\r
-        /* Smooth inverse energies */\r
-        psSilk_VAD->inv_NL[ k ] = SKP_SMLAWB( psSilk_VAD->inv_NL[ k ], inv_nrg - psSilk_VAD->inv_NL[ k ], coef );\r
-        SKP_assert( psSilk_VAD->inv_NL[ k ] >= 0 );\r
-\r
-        /* Compute noise level by inverting again */\r
-        nl = SKP_DIV32( SKP_int32_MAX, psSilk_VAD->inv_NL[ k ] );\r
-        SKP_assert( nl >= 0 );\r
-\r
-        /* Limit noise levels (guarantee 7 bits of head room) */\r
-        nl = SKP_min( nl, 0x00FFFFFF );\r
-\r
-        /* Store as part of state */\r
-        psSilk_VAD->NL[ k ] = nl;\r
-    }\r
-\r
-    /* Increment frame counter */\r
-    psSilk_VAD->counter++;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*
+ * File Name:   SKP_Silk_VAD.c
+ * Description: Silk VAD.
+ */
+
+#include <stdlib.h>
+#include "SKP_Silk_main.h"
+
+/**********************************/
+/* Initialization of the Silk VAD */
+/**********************************/
+SKP_int SKP_Silk_VAD_Init(                              /* O    Return value, 0 if success                  */ 
+    SKP_Silk_VAD_state              *psSilk_VAD         /* I/O  Pointer to Silk VAD state                   */ 
+)
+{
+    SKP_int b, ret = 0;
+
+    /* reset state memory */
+    SKP_memset( psSilk_VAD, 0, sizeof( SKP_Silk_VAD_state ) );
+
+    /* init noise levels */
+    /* Initialize array with approx pink noise levels (psd proportional to inverse of frequency) */
+    for( b = 0; b < VAD_N_BANDS; b++ ) {
+        psSilk_VAD->NoiseLevelBias[ b ] = SKP_max_32( SKP_DIV32_16( VAD_NOISE_LEVELS_BIAS, b + 1 ), 1 );
+    }
+
+    /* Initialize state */
+    for( b = 0; b < VAD_N_BANDS; b++ ) {
+        psSilk_VAD->NL[ b ]     = SKP_MUL( 100, psSilk_VAD->NoiseLevelBias[ b ] );
+        psSilk_VAD->inv_NL[ b ] = SKP_DIV32( SKP_int32_MAX, psSilk_VAD->NL[ b ] );
+    }
+    psSilk_VAD->counter = 15;
+
+    /* init smoothed energy-to-noise ratio*/
+    for( b = 0; b < VAD_N_BANDS; b++ ) {
+        psSilk_VAD->NrgRatioSmth_Q8[ b ] = 100 * 256;       /* 100 * 256 --> 20 dB SNR */
+    }
+
+    return( ret );
+}
+
+/* Weighting factors for tilt measure */
+const static SKP_int32 tiltWeights[ VAD_N_BANDS ] = { 30000, 6000, -12000, -12000 };
+
+/***************************************/
+/* Get the speech activity level in Q8 */
+/***************************************/
+SKP_int SKP_Silk_VAD_GetSA_Q8(                                      /* O    Return value, 0 if success      */
+    SKP_Silk_VAD_state              *psSilk_VAD,                    /* I/O  Silk VAD state                  */
+    SKP_int                         *pSA_Q8,                        /* O    Speech activity level in Q8     */
+    SKP_int                         *pSNR_dB_Q7,                    /* O    SNR for current frame in Q7     */
+    SKP_int                         pQuality_Q15[ VAD_N_BANDS ],    /* O    Smoothed SNR for each band      */
+    SKP_int                         *pTilt_Q15,                     /* O    current frame's frequency tilt  */
+    const SKP_int16                 pIn[],                          /* I    PCM input       [framelength]   */
+    const SKP_int                   framelength                     /* I    Input frame length              */
+)
+{
+    SKP_int   SA_Q15, input_tilt;
+    SKP_int32 scratch[ 3 * MAX_FRAME_LENGTH / 2 ];
+    SKP_int   decimated_framelength, dec_subframe_length, dec_subframe_offset, SNR_Q7, i, b, s;
+    SKP_int32 sumSquared, smooth_coef_Q16;
+    SKP_int16 HPstateTmp;
+
+    SKP_int16 X[ VAD_N_BANDS ][ MAX_FRAME_LENGTH / 2 ];
+    SKP_int32 Xnrg[ VAD_N_BANDS ];
+    SKP_int32 NrgToNoiseRatio_Q8[ VAD_N_BANDS ];
+    SKP_int32 speech_nrg, x_tmp;
+    SKP_int   ret = 0;
+
+    /* Safety checks */
+    SKP_assert( VAD_N_BANDS == 4 );
+    SKP_assert( MAX_FRAME_LENGTH >= framelength );
+    SKP_assert( framelength <= 512 );
+
+    /***********************/
+    /* Filter and Decimate */
+    /***********************/
+    /* 0-8 kHz to 0-4 kHz and 4-8 kHz */
+    SKP_Silk_ana_filt_bank_1( pIn,          &psSilk_VAD->AnaState[  0 ], &X[ 0 ][ 0 ], &X[ 3 ][ 0 ], &scratch[ 0 ], framelength );        
+    
+    /* 0-4 kHz to 0-2 kHz and 2-4 kHz */
+    SKP_Silk_ana_filt_bank_1( &X[ 0 ][ 0 ], &psSilk_VAD->AnaState1[ 0 ], &X[ 0 ][ 0 ], &X[ 2 ][ 0 ], &scratch[ 0 ], SKP_RSHIFT( framelength, 1 ) );
+    
+    /* 0-2 kHz to 0-1 kHz and 1-2 kHz */
+    SKP_Silk_ana_filt_bank_1( &X[ 0 ][ 0 ], &psSilk_VAD->AnaState2[ 0 ], &X[ 0 ][ 0 ], &X[ 1 ][ 0 ], &scratch[ 0 ], SKP_RSHIFT( framelength, 2 ) );
+
+    /*********************************************/
+    /* HP filter on lowest band (differentiator) */
+    /*********************************************/
+    decimated_framelength = SKP_RSHIFT( framelength, 3 );
+    X[ 0 ][ decimated_framelength - 1 ] = SKP_RSHIFT( X[ 0 ][ decimated_framelength - 1 ], 1 );
+    HPstateTmp = X[ 0 ][ decimated_framelength - 1 ];
+    for( i = decimated_framelength - 1; i > 0; i-- ) {
+        X[ 0 ][ i - 1 ]  = SKP_RSHIFT( X[ 0 ][ i - 1 ], 1 );
+        X[ 0 ][ i ]     -= X[ 0 ][ i - 1 ];
+    }
+    X[ 0 ][ 0 ] -= psSilk_VAD->HPstate;
+    psSilk_VAD->HPstate = HPstateTmp;
+
+    /*************************************/
+    /* Calculate the energy in each band */
+    /*************************************/
+    for( b = 0; b < VAD_N_BANDS; b++ ) {        
+        /* Find the decimated framelength in the non-uniformly divided bands */
+        decimated_framelength = SKP_RSHIFT( framelength, SKP_min_int( VAD_N_BANDS - b, VAD_N_BANDS - 1 ) );
+
+        /* Split length into subframe lengths */
+        dec_subframe_length = SKP_RSHIFT( decimated_framelength, VAD_INTERNAL_SUBFRAMES_LOG2 );
+        dec_subframe_offset = 0;
+
+        /* Compute energy per sub-frame */
+        /* initialize with summed energy of last subframe */
+        Xnrg[ b ] = psSilk_VAD->XnrgSubfr[ b ];
+        for( s = 0; s < VAD_INTERNAL_SUBFRAMES; s++ ) {
+            sumSquared = 0;
+            for( i = 0; i < dec_subframe_length; i++ ) {
+                /* The energy will be less than dec_subframe_length * ( SKP_int16_MIN / 8 ) ^ 2.            */
+                /* Therefore we can accumulate with no risk of overflow (unless dec_subframe_length > 128)  */
+                x_tmp = SKP_RSHIFT( X[ b ][ i + dec_subframe_offset ], 3 );
+                sumSquared = SKP_SMLABB( sumSquared, x_tmp, x_tmp );
+
+                /* Safety check */
+                SKP_assert( sumSquared >= 0 );
+            }
+
+            /* Add/saturate summed energy of current subframe */
+            if( s < VAD_INTERNAL_SUBFRAMES - 1 ) {
+                Xnrg[ b ] = SKP_ADD_POS_SAT32( Xnrg[ b ], sumSquared );
+            } else {
+                /* Look-ahead subframe */
+                Xnrg[ b ] = SKP_ADD_POS_SAT32( Xnrg[ b ], SKP_RSHIFT( sumSquared, 1 ) );
+            }
+
+            dec_subframe_offset += dec_subframe_length;
+        }
+        psSilk_VAD->XnrgSubfr[ b ] = sumSquared; 
+    }
+
+    /********************/
+    /* Noise estimation */
+    /********************/
+    SKP_Silk_VAD_GetNoiseLevels( &Xnrg[ 0 ], psSilk_VAD );
+
+    /***********************************************/
+    /* Signal-plus-noise to noise ratio estimation */
+    /***********************************************/
+    sumSquared = 0;
+    input_tilt = 0;
+    for( b = 0; b < VAD_N_BANDS; b++ ) {
+        speech_nrg = Xnrg[ b ] - psSilk_VAD->NL[ b ];
+        if( speech_nrg > 0 ) {
+            /* Divide, with sufficient resolution */
+            if( ( Xnrg[ b ] & 0xFF800000 ) == 0 ) {
+                NrgToNoiseRatio_Q8[ b ] = SKP_DIV32( SKP_LSHIFT( Xnrg[ b ], 8 ), psSilk_VAD->NL[ b ] + 1 );
+            } else {
+                NrgToNoiseRatio_Q8[ b ] = SKP_DIV32( Xnrg[ b ], SKP_RSHIFT( psSilk_VAD->NL[ b ], 8 ) + 1 );
+            }
+
+            /* Convert to log domain */
+            SNR_Q7 = SKP_Silk_lin2log( NrgToNoiseRatio_Q8[ b ] ) - 8 * 128;
+
+            /* Sum-of-squares */
+            sumSquared = SKP_SMLABB( sumSquared, SNR_Q7, SNR_Q7 );          /* Q14 */
+
+            /* Tilt measure */
+            if( speech_nrg < ( 1 << 20 ) ) {
+                /* Scale down SNR value for small subband speech energies */
+                SNR_Q7 = SKP_SMULWB( SKP_LSHIFT( SKP_Silk_SQRT_APPROX( speech_nrg ), 6 ), SNR_Q7 );
+            }
+            input_tilt = SKP_SMLAWB( input_tilt, tiltWeights[ b ], SNR_Q7 );
+        } else {
+            NrgToNoiseRatio_Q8[ b ] = 256;
+        }
+    }
+
+    /* Mean-of-squares */
+    sumSquared = SKP_DIV32_16( sumSquared, VAD_N_BANDS ); /* Q14 */
+
+    /* Root-mean-square approximation, scale to dBs, and write to output pointer */
+    *pSNR_dB_Q7 = ( SKP_int16 )( 3 * SKP_Silk_SQRT_APPROX( sumSquared ) );  /* Q7 */
+
+    /*********************************/
+    /* Speech Probability Estimation */
+    /*********************************/
+    SA_Q15 = SKP_Silk_sigm_Q15( SKP_SMULWB( VAD_SNR_FACTOR_Q16, *pSNR_dB_Q7 ) - VAD_NEGATIVE_OFFSET_Q5 );
+
+    /**************************/
+    /* Frequency Tilt Measure */
+    /**************************/
+    *pTilt_Q15 = SKP_LSHIFT( SKP_Silk_sigm_Q15( input_tilt ) - 16384, 1 );
+
+    /**************************************************/
+    /* Scale the sigmoid output based on power levels */
+    /**************************************************/
+    speech_nrg = 0;
+    for( b = 0; b < VAD_N_BANDS; b++ ) {
+        /* Accumulate signal-without-noise energies, higher frequency bands have more weight */
+        speech_nrg += ( b + 1 ) * SKP_RSHIFT( Xnrg[ b ] - psSilk_VAD->NL[ b ], 4 );
+    }
+
+    /* Power scaling */
+    if( speech_nrg <= 0 ) {
+        SA_Q15 = SKP_RSHIFT( SA_Q15, 1 ); 
+    } else if( speech_nrg < 32768 ) {
+        /* square-root */
+        speech_nrg = SKP_Silk_SQRT_APPROX( SKP_LSHIFT( speech_nrg, 15 ) );
+        SA_Q15 = SKP_SMULWB( 32768 + speech_nrg, SA_Q15 ); 
+    }
+
+    /* Copy the resulting speech activity in Q8 to *pSA_Q8 */
+    *pSA_Q8 = SKP_min_int( SKP_RSHIFT( SA_Q15, 7 ), SKP_uint8_MAX );
+
+    /***********************************/
+    /* Energy Level and SNR estimation */
+    /***********************************/
+    /* Smoothing coefficient */
+    smooth_coef_Q16 = SKP_SMULWB( VAD_SNR_SMOOTH_COEF_Q18, SKP_SMULWB( SA_Q15, SA_Q15 ) );
+    for( b = 0; b < VAD_N_BANDS; b++ ) {
+        /* compute smoothed energy-to-noise ratio per band */
+        psSilk_VAD->NrgRatioSmth_Q8[ b ] = SKP_SMLAWB( psSilk_VAD->NrgRatioSmth_Q8[ b ], 
+            NrgToNoiseRatio_Q8[ b ] - psSilk_VAD->NrgRatioSmth_Q8[ b ], smooth_coef_Q16 );
+
+        /* signal to noise ratio in dB per band */
+        SNR_Q7 = 3 * ( SKP_Silk_lin2log( psSilk_VAD->NrgRatioSmth_Q8[b] ) - 8 * 128 );
+        /* quality = sigmoid( 0.25 * ( SNR_dB - 16 ) ); */
+        pQuality_Q15[ b ] = SKP_Silk_sigm_Q15( SKP_RSHIFT( SNR_Q7 - 16 * 128, 4 ) );
+    }
+
+    return( ret );
+}
+
+/**************************/
+/* Noise level estimation */
+/**************************/
+void SKP_Silk_VAD_GetNoiseLevels(
+    const SKP_int32                 pX[ VAD_N_BANDS ],  /* I    subband energies                            */
+    SKP_Silk_VAD_state              *psSilk_VAD         /* I/O  Pointer to Silk VAD state                   */ 
+)
+{
+    SKP_int   k;
+    SKP_int32 nl, nrg, inv_nrg;
+    SKP_int   coef, min_coef;
+
+    /* Initially faster smoothing */
+    if( psSilk_VAD->counter < 1000 ) { /* 1000 = 20 sec */
+        min_coef = SKP_DIV32_16( SKP_int16_MAX, SKP_RSHIFT( psSilk_VAD->counter, 4 ) + 1 );  
+    } else {
+        min_coef = 0;
+    }
+
+    for( k = 0; k < VAD_N_BANDS; k++ ) {
+        /* Get old noise level estimate for current band */
+        nl = psSilk_VAD->NL[ k ];
+        SKP_assert( nl >= 0 );
+        
+        /* Add bias */
+        nrg = SKP_ADD_POS_SAT32( pX[ k ], psSilk_VAD->NoiseLevelBias[ k ] ); 
+        SKP_assert( nrg > 0 );
+        
+        /* Invert energies */
+        inv_nrg = SKP_DIV32( SKP_int32_MAX, nrg );
+        SKP_assert( inv_nrg >= 0 );
+        
+        /* Less update when subband energy is high */
+        if( nrg > SKP_LSHIFT( nl, 3 ) ) {
+            coef = VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 >> 3;
+        } else if( nrg < nl ) {
+            coef = VAD_NOISE_LEVEL_SMOOTH_COEF_Q16;
+        } else {
+            coef = SKP_SMULWB( SKP_SMULWW( inv_nrg, nl ), VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 << 1 );
+        }
+
+        /* Initially faster smoothing */
+        coef = SKP_max_int( coef, min_coef );
+
+        /* Smooth inverse energies */
+        psSilk_VAD->inv_NL[ k ] = SKP_SMLAWB( psSilk_VAD->inv_NL[ k ], inv_nrg - psSilk_VAD->inv_NL[ k ], coef );
+        SKP_assert( psSilk_VAD->inv_NL[ k ] >= 0 );
+
+        /* Compute noise level by inverting again */
+        nl = SKP_DIV32( SKP_int32_MAX, psSilk_VAD->inv_NL[ k ] );
+        SKP_assert( nl >= 0 );
+
+        /* Limit noise levels (guarantee 7 bits of head room) */
+        nl = SKP_min( nl, 0x00FFFFFF );
+
+        /* Store as part of state */
+        psSilk_VAD->NL[ k ] = nl;
+    }
+
+    /* Increment frame counter */
+    psSilk_VAD->counter++;
+}
index ae780aa8482569ae58194d91daf760b7bd2e0095..58c98060660e5eb7e65db84f986d016806e3d812 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-\r
-/* Entropy constrained MATRIX-weighted VQ, hard-coded to 5-element vectors, for a single input data vector */\r
-void SKP_Silk_VQ_WMat_EC_FIX(\r
-    SKP_int                         *ind,               /* O    index of best codebook vector               */\r
-    SKP_int32                       *rate_dist_Q14,     /* O    best weighted quantization error + mu * rate*/\r
-    const SKP_int16                 *in_Q14,            /* I    input vector to be quantized                */\r
-    const SKP_int32                 *W_Q18,             /* I    weighting matrix                            */\r
-    const SKP_int16                 *cb_Q14,            /* I    codebook                                    */\r
-    const SKP_int16                 *cl_Q6,             /* I    code length for each codebook vector        */\r
-    const SKP_int                   mu_Q8,              /* I    tradeoff between weighted error and rate    */\r
-    SKP_int                         L                   /* I    number of vectors in codebook               */\r
-)\r
-{\r
-    SKP_int   k;\r
-    const SKP_int16 *cb_row_Q14;\r
-    SKP_int16 diff_Q14[ 5 ];\r
-    SKP_int32 sum1_Q14, sum2_Q16;\r
-\r
-    /* Loop over codebook */\r
-    *rate_dist_Q14 = SKP_int32_MAX;\r
-    cb_row_Q14 = cb_Q14;\r
-    for( k = 0; k < L; k++ ) {\r
-        diff_Q14[ 0 ] = in_Q14[ 0 ] - cb_row_Q14[ 0 ];\r
-        diff_Q14[ 1 ] = in_Q14[ 1 ] - cb_row_Q14[ 1 ];\r
-        diff_Q14[ 2 ] = in_Q14[ 2 ] - cb_row_Q14[ 2 ];\r
-        diff_Q14[ 3 ] = in_Q14[ 3 ] - cb_row_Q14[ 3 ];\r
-        diff_Q14[ 4 ] = in_Q14[ 4 ] - cb_row_Q14[ 4 ];\r
-\r
-        /* Weighted rate */\r
-        sum1_Q14 = SKP_SMULBB( mu_Q8, cl_Q6[ k ] );\r
-\r
-        SKP_assert( sum1_Q14 >= 0 );\r
-\r
-        /* first row of W_Q18 */\r
-        sum2_Q16 = SKP_SMULWB(           W_Q18[  1 ], diff_Q14[ 1 ] );\r
-        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  2 ], diff_Q14[ 2 ] );\r
-        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  3 ], diff_Q14[ 3 ] );\r
-        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  4 ], diff_Q14[ 4 ] );\r
-        sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );\r
-        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  0 ], diff_Q14[ 0 ] );\r
-        sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16,    diff_Q14[ 0 ] );\r
-\r
-        /* second row of W_Q18 */\r
-        sum2_Q16 = SKP_SMULWB(           W_Q18[  7 ], diff_Q14[ 2 ] ); \r
-        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  8 ], diff_Q14[ 3 ] );\r
-        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  9 ], diff_Q14[ 4 ] );\r
-        sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );\r
-        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  6 ], diff_Q14[ 1 ] );\r
-        sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16,    diff_Q14[ 1 ] );\r
-\r
-        /* third row of W_Q18 */\r
-        sum2_Q16 = SKP_SMULWB(           W_Q18[ 13 ], diff_Q14[ 3 ] ); \r
-        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 14 ], diff_Q14[ 4 ] );\r
-        sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );\r
-        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 12 ], diff_Q14[ 2 ] );\r
-        sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16,    diff_Q14[ 2 ] );\r
-\r
-        /* fourth row of W_Q18 */\r
-        sum2_Q16 = SKP_SMULWB(           W_Q18[ 19 ], diff_Q14[ 4 ] ); \r
-        sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );\r
-        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 18 ], diff_Q14[ 3 ] );\r
-        sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16,    diff_Q14[ 3 ] );\r
-\r
-        /* last row of W_Q18 */\r
-        sum2_Q16 = SKP_SMULWB(           W_Q18[ 24 ], diff_Q14[ 4 ] ); \r
-        sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16,    diff_Q14[ 4 ] );\r
-\r
-        SKP_assert( sum1_Q14 >= 0 );\r
-\r
-        /* find best */\r
-        if( sum1_Q14 < *rate_dist_Q14 ) {\r
-            *rate_dist_Q14 = sum1_Q14;\r
-            *ind = k;\r
-        }\r
-\r
-        /* Go to next cbk vector */\r
-        cb_row_Q14 += LTP_ORDER;\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+/* Entropy constrained MATRIX-weighted VQ, hard-coded to 5-element vectors, for a single input data vector */
+void SKP_Silk_VQ_WMat_EC_FIX(
+    SKP_int                         *ind,               /* O    index of best codebook vector               */
+    SKP_int32                       *rate_dist_Q14,     /* O    best weighted quantization error + mu * rate*/
+    const SKP_int16                 *in_Q14,            /* I    input vector to be quantized                */
+    const SKP_int32                 *W_Q18,             /* I    weighting matrix                            */
+    const SKP_int16                 *cb_Q14,            /* I    codebook                                    */
+    const SKP_int16                 *cl_Q6,             /* I    code length for each codebook vector        */
+    const SKP_int                   mu_Q8,              /* I    tradeoff between weighted error and rate    */
+    SKP_int                         L                   /* I    number of vectors in codebook               */
+)
+{
+    SKP_int   k;
+    const SKP_int16 *cb_row_Q14;
+    SKP_int16 diff_Q14[ 5 ];
+    SKP_int32 sum1_Q14, sum2_Q16;
+
+    /* Loop over codebook */
+    *rate_dist_Q14 = SKP_int32_MAX;
+    cb_row_Q14 = cb_Q14;
+    for( k = 0; k < L; k++ ) {
+        diff_Q14[ 0 ] = in_Q14[ 0 ] - cb_row_Q14[ 0 ];
+        diff_Q14[ 1 ] = in_Q14[ 1 ] - cb_row_Q14[ 1 ];
+        diff_Q14[ 2 ] = in_Q14[ 2 ] - cb_row_Q14[ 2 ];
+        diff_Q14[ 3 ] = in_Q14[ 3 ] - cb_row_Q14[ 3 ];
+        diff_Q14[ 4 ] = in_Q14[ 4 ] - cb_row_Q14[ 4 ];
+
+        /* Weighted rate */
+        sum1_Q14 = SKP_SMULBB( mu_Q8, cl_Q6[ k ] );
+
+        SKP_assert( sum1_Q14 >= 0 );
+
+        /* first row of W_Q18 */
+        sum2_Q16 = SKP_SMULWB(           W_Q18[  1 ], diff_Q14[ 1 ] );
+        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  2 ], diff_Q14[ 2 ] );
+        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  3 ], diff_Q14[ 3 ] );
+        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  4 ], diff_Q14[ 4 ] );
+        sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
+        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  0 ], diff_Q14[ 0 ] );
+        sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16,    diff_Q14[ 0 ] );
+
+        /* second row of W_Q18 */
+        sum2_Q16 = SKP_SMULWB(           W_Q18[  7 ], diff_Q14[ 2 ] ); 
+        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  8 ], diff_Q14[ 3 ] );
+        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  9 ], diff_Q14[ 4 ] );
+        sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
+        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[  6 ], diff_Q14[ 1 ] );
+        sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16,    diff_Q14[ 1 ] );
+
+        /* third row of W_Q18 */
+        sum2_Q16 = SKP_SMULWB(           W_Q18[ 13 ], diff_Q14[ 3 ] ); 
+        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 14 ], diff_Q14[ 4 ] );
+        sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
+        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 12 ], diff_Q14[ 2 ] );
+        sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16,    diff_Q14[ 2 ] );
+
+        /* fourth row of W_Q18 */
+        sum2_Q16 = SKP_SMULWB(           W_Q18[ 19 ], diff_Q14[ 4 ] ); 
+        sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
+        sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 18 ], diff_Q14[ 3 ] );
+        sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16,    diff_Q14[ 3 ] );
+
+        /* last row of W_Q18 */
+        sum2_Q16 = SKP_SMULWB(           W_Q18[ 24 ], diff_Q14[ 4 ] ); 
+        sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16,    diff_Q14[ 4 ] );
+
+        SKP_assert( sum1_Q14 >= 0 );
+
+        /* find best */
+        if( sum1_Q14 < *rate_dist_Q14 ) {
+            *rate_dist_Q14 = sum1_Q14;
+            *ind = k;
+        }
+
+        /* Go to next cbk vector */
+        cb_row_Q14 += LTP_ORDER;
+    }
+}
index 59b8068718194ce691763e753192140d41a0fc80..2e9ac6bbb141dd152a3a617b181fd9a3b24ee390 100644 (file)
@@ -1,80 +1,80 @@
-/***********************************************************************\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_ana_filt_bank_1.c                                                    *\r
- *                                                                          *\r
- * Split signal into two decimated bands using first-order allpass filters  *\r
- *                                                                          *\r
- * Copyright 2006 (c), Skype Limited                                        *\r
- * Date: 060221                                                             *\r
- *                                                                          */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Coefficients for 2-band filter bank based on first-order allpass filters */\r
-// old\r
-static SKP_int16 A_fb1_20[ 1 ] = {  5394 << 1 };\r
-static SKP_int16 A_fb1_21[ 1 ] = { 20623 << 1 };        /* wrap-around to negative number is intentional */\r
-\r
-/* Split signal into two decimated bands using first-order allpass filters */\r
-void SKP_Silk_ana_filt_bank_1(\r
-    const SKP_int16      *in,        /* I:   Input signal [N]        */\r
-    SKP_int32            *S,         /* I/O: State vector [2]        */\r
-    SKP_int16            *outL,      /* O:   Low band [N/2]          */\r
-    SKP_int16            *outH,      /* O:   High band [N/2]         */\r
-    SKP_int32            *scratch,   /* I:   Scratch memory [3*N/2]  */   // todo: remove - no longer used\r
-    const SKP_int32      N           /* I:   Number of input samples */\r
-)\r
-{\r
-    SKP_int      k, N2 = SKP_RSHIFT( N, 1 );\r
-    SKP_int32    in32, X, Y, out_1, out_2;\r
-\r
-    /* Internal variables and state are in Q10 format */\r
-    for( k = 0; k < N2; k++ ) {\r
-        /* Convert to Q10 */\r
-        in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 );\r
-\r
-        /* All-pass section for even input sample */\r
-        Y      = SKP_SUB32( in32, S[ 0 ] );\r
-        X      = SKP_SMLAWB( Y, Y, A_fb1_21[ 0 ] );\r
-        out_1  = SKP_ADD32( S[ 0 ], X );\r
-        S[ 0 ] = SKP_ADD32( in32, X );\r
-\r
-        /* Convert to Q10 */\r
-        in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 );\r
-\r
-        /* All-pass section for odd input sample */\r
-        Y      = SKP_SUB32( in32, S[ 1 ] );\r
-        X      = SKP_SMULWB( Y, A_fb1_20[ 0 ] );\r
-        out_2  = SKP_ADD32( S[ 1 ], X );\r
-        S[ 1 ] = SKP_ADD32( in32, X );\r
-\r
-        /* Add/subtract, convert back to int16 and store to output */\r
-        outL[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( SKP_ADD32( out_2, out_1 ), 11 ) );\r
-        outH[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SUB32( out_2, out_1 ), 11 ) );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                          *
+ * SKP_ana_filt_bank_1.c                                                    *
+ *                                                                          *
+ * Split signal into two decimated bands using first-order allpass filters  *
+ *                                                                          *
+ * Copyright 2006 (c), Skype Limited                                        *
+ * Date: 060221                                                             *
+ *                                                                          */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Coefficients for 2-band filter bank based on first-order allpass filters */
+// old
+static SKP_int16 A_fb1_20[ 1 ] = {  5394 << 1 };
+static SKP_int16 A_fb1_21[ 1 ] = { 20623 << 1 };        /* wrap-around to negative number is intentional */
+
+/* Split signal into two decimated bands using first-order allpass filters */
+void SKP_Silk_ana_filt_bank_1(
+    const SKP_int16      *in,        /* I:   Input signal [N]        */
+    SKP_int32            *S,         /* I/O: State vector [2]        */
+    SKP_int16            *outL,      /* O:   Low band [N/2]          */
+    SKP_int16            *outH,      /* O:   High band [N/2]         */
+    SKP_int32            *scratch,   /* I:   Scratch memory [3*N/2]  */   // todo: remove - no longer used
+    const SKP_int32      N           /* I:   Number of input samples */
+)
+{
+    SKP_int      k, N2 = SKP_RSHIFT( N, 1 );
+    SKP_int32    in32, X, Y, out_1, out_2;
+
+    /* Internal variables and state are in Q10 format */
+    for( k = 0; k < N2; k++ ) {
+        /* Convert to Q10 */
+        in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 );
+
+        /* All-pass section for even input sample */
+        Y      = SKP_SUB32( in32, S[ 0 ] );
+        X      = SKP_SMLAWB( Y, Y, A_fb1_21[ 0 ] );
+        out_1  = SKP_ADD32( S[ 0 ], X );
+        S[ 0 ] = SKP_ADD32( in32, X );
+
+        /* Convert to Q10 */
+        in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 );
+
+        /* All-pass section for odd input sample */
+        Y      = SKP_SUB32( in32, S[ 1 ] );
+        X      = SKP_SMULWB( Y, A_fb1_20[ 0 ] );
+        out_2  = SKP_ADD32( S[ 1 ], X );
+        S[ 1 ] = SKP_ADD32( in32, X );
+
+        /* Add/subtract, convert back to int16 and store to output */
+        outL[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( SKP_ADD32( out_2, out_1 ), 11 ) );
+        outH[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SUB32( out_2, out_1 ), 11 ) );
+    }
+}
index b4db18e655820773956246ada22b1c82977ce6aa..3c99099c754498227208918d7ae89be80ab41125 100644 (file)
-/***********************************************************************\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_SigProc_FIX.h"\r
-\r
-/* Apply sine window to signal vector.                                      */\r
-/* Window types:                                                            */\r
-/*    1 -> sine window from 0 to pi/2                                       */\r
-/*    2 -> sine window from pi/2 to pi                                      */\r
-/* Every other sample is linearly interpolated, for speed.                  */\r
-/* Window length must be between 16 and 120 (incl) and a multiple of 4.     */\r
-\r
-/* Matlab code for table: \r
-   for k=16:9*4:16+2*9*4, fprintf(' %7.d,', -round(65536*pi ./ (k:4:k+8*4))); fprintf('\n'); end\r
-*/\r
-static SKP_int16 freq_table_Q16[ 27 ] = {\r
-   12111,    9804,    8235,    7100,    6239,    5565,    5022,    4575,    4202,\r
-    3885,    3612,    3375,    3167,    2984,    2820,    2674,    2542,    2422,\r
-    2313,    2214,    2123,    2038,    1961,    1889,    1822,    1760,    1702,\r
-};\r
-\r
-\r
-void SKP_Silk_apply_sine_window_new(\r
-    SKP_int16                        px_win[],            /* O    Pointer to windowed signal                  */\r
-    const SKP_int16                  px[],                /* I    Pointer to input signal                     */\r
-    const SKP_int                    win_type,            /* I    Selects a window type                       */\r
-    const SKP_int                    length               /* I    Window length, multiple of 4                */\r
-)\r
-{\r
-    SKP_int   k, f_Q16, c_Q16;\r
-    SKP_int32 S0_Q16, S1_Q16;\r
-    SKP_assert( win_type == 1 || win_type == 2 );\r
-\r
-    /* Length must be in a range from 16 to 120 and a multiple of 4 */\r
-    SKP_assert( length >= 16 && length <= 120 );\r
-    SKP_assert( ( length & 3 ) == 0 );\r
-\r
-    /* Input pointer must be 4-byte aligned */\r
-    SKP_assert( ( ( SKP_int64 )( ( SKP_int8* )px - ( SKP_int8* )0 ) & 3 ) == 0 );\r
-\r
-    /* Frequency */\r
-    k = ( length >> 2 ) - 4;\r
-    SKP_assert( k >= 0 && k <= 26 );\r
-    f_Q16 = (SKP_int)freq_table_Q16[ k ];\r
-\r
-    /* Factor used for cosine approximation */\r
-    c_Q16 = SKP_SMULWB( f_Q16, -f_Q16 );\r
-    SKP_assert( c_Q16 >= -32768 );\r
-\r
-    /* initialize state */\r
-    if( win_type == 1 ) {\r
-        /* start from 0 */\r
-        S0_Q16 = 0;\r
-        /* approximation of sin(f) */\r
-        S1_Q16 = f_Q16 + SKP_RSHIFT( length, 3 );\r
-    } else {\r
-        /* start from 1 */\r
-        S0_Q16 = ( 1 << 16 );\r
-        /* approximation of cos(f) */\r
-        S1_Q16 = ( 1 << 16 ) + SKP_RSHIFT( c_Q16, 1 ) + SKP_RSHIFT( length, 4 );\r
-    }\r
-\r
-    /* Uses the recursive equation:   sin(n*f) = 2 * cos(f) * sin((n-1)*f) - sin((n-2)*f)    */\r
-    /* 4 samples at a time */\r
-    for( k = 0; k < length; k += 4 ) {\r
-        px_win[ k ]     = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px[ k ] );\r
-        px_win[ k + 1 ] = (SKP_int16)SKP_SMULWB( S1_Q16, px[ k + 1] );\r
-        S0_Q16 = SKP_SMULWB( S1_Q16, c_Q16 ) + SKP_LSHIFT( S1_Q16, 1 ) - S0_Q16 + 1;\r
-        S0_Q16 = SKP_min( S0_Q16, ( 1 << 16 ) );\r
-\r
-        px_win[ k + 2 ] = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px[ k + 2] );\r
-        px_win[ k + 3 ] = (SKP_int16)SKP_SMULWB( S0_Q16, px[ k + 3 ] );\r
-        S1_Q16 = SKP_SMULWB( S0_Q16, c_Q16 ) + SKP_LSHIFT( S0_Q16, 1 ) - S1_Q16;\r
-        S1_Q16 = SKP_min( S1_Q16, ( 1 << 16 ) );\r
-    }\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Apply sine window to signal vector.                                      */
+/* Window types:                                                            */
+/*    1 -> sine window from 0 to pi/2                                       */
+/*    2 -> sine window from pi/2 to pi                                      */
+/* Every other sample is linearly interpolated, for speed.                  */
+/* Window length must be between 16 and 120 (incl) and a multiple of 4.     */
+
+/* Matlab code for table: 
+   for k=16:9*4:16+2*9*4, fprintf(' %7.d,', -round(65536*pi ./ (k:4:k+8*4))); fprintf('\n'); end
+*/
+static SKP_int16 freq_table_Q16[ 27 ] = {
+   12111,    9804,    8235,    7100,    6239,    5565,    5022,    4575,    4202,
+    3885,    3612,    3375,    3167,    2984,    2820,    2674,    2542,    2422,
+    2313,    2214,    2123,    2038,    1961,    1889,    1822,    1760,    1702,
+};
+
+
+void SKP_Silk_apply_sine_window_new(
+    SKP_int16                        px_win[],            /* O    Pointer to windowed signal                  */
+    const SKP_int16                  px[],                /* I    Pointer to input signal                     */
+    const SKP_int                    win_type,            /* I    Selects a window type                       */
+    const SKP_int                    length               /* I    Window length, multiple of 4                */
+)
+{
+    SKP_int   k, f_Q16, c_Q16;
+    SKP_int32 S0_Q16, S1_Q16;
+    SKP_assert( win_type == 1 || win_type == 2 );
+
+    /* Length must be in a range from 16 to 120 and a multiple of 4 */
+    SKP_assert( length >= 16 && length <= 120 );
+    SKP_assert( ( length & 3 ) == 0 );
+
+    /* Input pointer must be 4-byte aligned */
+    SKP_assert( ( ( SKP_int64 )( ( SKP_int8* )px - ( SKP_int8* )0 ) & 3 ) == 0 );
+
+    /* Frequency */
+    k = ( length >> 2 ) - 4;
+    SKP_assert( k >= 0 && k <= 26 );
+    f_Q16 = (SKP_int)freq_table_Q16[ k ];
+
+    /* Factor used for cosine approximation */
+    c_Q16 = SKP_SMULWB( f_Q16, -f_Q16 );
+    SKP_assert( c_Q16 >= -32768 );
+
+    /* initialize state */
+    if( win_type == 1 ) {
+        /* start from 0 */
+        S0_Q16 = 0;
+        /* approximation of sin(f) */
+        S1_Q16 = f_Q16 + SKP_RSHIFT( length, 3 );
+    } else {
+        /* start from 1 */
+        S0_Q16 = ( 1 << 16 );
+        /* approximation of cos(f) */
+        S1_Q16 = ( 1 << 16 ) + SKP_RSHIFT( c_Q16, 1 ) + SKP_RSHIFT( length, 4 );
+    }
+
+    /* Uses the recursive equation:   sin(n*f) = 2 * cos(f) * sin((n-1)*f) - sin((n-2)*f)    */
+    /* 4 samples at a time */
+    for( k = 0; k < length; k += 4 ) {
+        px_win[ k ]     = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px[ k ] );
+        px_win[ k + 1 ] = (SKP_int16)SKP_SMULWB( S1_Q16, px[ k + 1] );
+        S0_Q16 = SKP_SMULWB( S1_Q16, c_Q16 ) + SKP_LSHIFT( S1_Q16, 1 ) - S0_Q16 + 1;
+        S0_Q16 = SKP_min( S0_Q16, ( 1 << 16 ) );
+
+        px_win[ k + 2 ] = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px[ k + 2] );
+        px_win[ k + 3 ] = (SKP_int16)SKP_SMULWB( S0_Q16, px[ k + 3 ] );
+        S1_Q16 = SKP_SMULWB( S0_Q16, c_Q16 ) + SKP_LSHIFT( S0_Q16, 1 ) - S1_Q16;
+        S1_Q16 = SKP_min( S1_Q16, ( 1 << 16 ) );
+    }
+}
+
index 3fd4fd30c158f237c954bff11ba1d5bf65ee7346..3dfa6f99ee240660f284665013137f48ff4395c1 100644 (file)
@@ -1,68 +1,68 @@
-/***********************************************************************\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_int16_array_maxabs.c                                      *\r
- *                                                                      *\r
- * Function that returns the maximum absolut value of                   *\r
- * the input vector                                                     *\r
- *                                                                      *\r
- * Copyright 2006 (c), Skype Limited                                    *\r
- * Date: 060221                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Function that returns the maximum absolut value of the input vector */\r
-SKP_int16 SKP_Silk_int16_array_maxabs(    /* O    Maximum absolute value, max: 2^15-1   */\r
-    const SKP_int16        *vec,            /* I    Input vector  [len]                   */\r
-    const SKP_int32        len              /* I    Length of input vector                */\r
-)                    \r
-{\r
-    SKP_int32 max = 0, i, lvl = 0, ind;\r
-       if( len == 0 ) return 0;\r
-\r
-    ind = len - 1;\r
-    max = SKP_SMULBB( vec[ ind ], vec[ ind ] );\r
-    for( i = len - 2; i >= 0; i-- ) {\r
-        lvl = SKP_SMULBB( vec[ i ], vec[ i ] );\r
-        if( lvl > max ) {\r
-            max = lvl;\r
-            ind = i;\r
-        }\r
-    }\r
-\r
-    /* Do not return 32768, as it will not fit in an int16 so may lead to problems later on */\r
-    if( max >= 1073676289 ) { // (2^15-1)^2 = 1073676289\r
-        return( SKP_int16_MAX );\r
-    } else {\r
-        if( vec[ ind ] < 0 ) {\r
-            return( -vec[ ind ] );\r
-        } else {\r
-            return(  vec[ ind ] );\r
-        }\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_int16_array_maxabs.c                                      *
+ *                                                                      *
+ * Function that returns the maximum absolut value of                   *
+ * the input vector                                                     *
+ *                                                                      *
+ * Copyright 2006 (c), Skype Limited                                    *
+ * Date: 060221                                                         *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Function that returns the maximum absolut value of the input vector */
+SKP_int16 SKP_Silk_int16_array_maxabs(    /* O    Maximum absolute value, max: 2^15-1   */
+    const SKP_int16        *vec,            /* I    Input vector  [len]                   */
+    const SKP_int32        len              /* I    Length of input vector                */
+)                    
+{
+    SKP_int32 max = 0, i, lvl = 0, ind;
+       if( len == 0 ) return 0;
+
+    ind = len - 1;
+    max = SKP_SMULBB( vec[ ind ], vec[ ind ] );
+    for( i = len - 2; i >= 0; i-- ) {
+        lvl = SKP_SMULBB( vec[ i ], vec[ i ] );
+        if( lvl > max ) {
+            max = lvl;
+            ind = i;
+        }
+    }
+
+    /* Do not return 32768, as it will not fit in an int16 so may lead to problems later on */
+    if( max >= 1073676289 ) { // (2^15-1)^2 = 1073676289
+        return( SKP_int16_MAX );
+    } else {
+        if( vec[ ind ] < 0 ) {
+            return( -vec[ ind ] );
+        } else {
+            return(  vec[ ind ] );
+        }
+    }
+}
index f7862b8949f4644d7be989460dd2383869128bfd..7da6f986d53bd6b991603bcf5c6bc0f9888683c8 100644 (file)
@@ -1,81 +1,81 @@
-/***********************************************************************\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_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
-void SKP_Silk_autocorr( \r
-    SKP_int32        *results,                   /* O    Result (length correlationCount)            */\r
-    SKP_int          *scale,                     /* O    Scaling of the correlation vector           */\r
-    const SKP_int16  *inputData,                 /* I    Input data to correlate                     */\r
-    const SKP_int    inputDataSize,              /* I    Length of input                             */\r
-    const SKP_int    correlationCount            /* I    Number of correlation taps to compute       */\r
-)\r
-{\r
-    SKP_int   i, lz, nRightShifts, corrCount;\r
-    SKP_int64 corr64;\r
-\r
-    corrCount = SKP_min_int( inputDataSize, correlationCount );\r
-\r
-    /* compute energy (zero-lag correlation) */\r
-    corr64 = SKP_Silk_inner_prod16_aligned_64( inputData, inputData, inputDataSize );\r
-\r
-    /* deal with all-zero input data */\r
-    corr64 += 1;\r
-\r
-    /* number of leading zeros */\r
-    lz = SKP_Silk_CLZ64( corr64 );\r
-\r
-    /* scaling: number of right shifts applied to correlations */\r
-    nRightShifts = 35 - lz;\r
-    *scale = nRightShifts;\r
-\r
-    if( nRightShifts <= 0 ) {\r
-        results[ 0 ] = SKP_LSHIFT( (SKP_int32)SKP_CHECK_FIT32( corr64 ), -nRightShifts );\r
-\r
-        /* compute remaining correlations based on int32 inner product */\r
-          for( i = 1; i < corrCount; i++ ) {\r
-            results[ i ] = SKP_LSHIFT( SKP_Silk_inner_prod_aligned( inputData, inputData + i, inputDataSize - i ), -nRightShifts );\r
-        }\r
-    } else {\r
-        results[ 0 ] = (SKP_int32)SKP_CHECK_FIT32( SKP_RSHIFT64( corr64, nRightShifts ) );\r
-\r
-        /* compute remaining correlations based on int64 inner product */\r
-          for( i = 1; i < corrCount; i++ ) {\r
-            results[ i ] =  (SKP_int32)SKP_CHECK_FIT32( SKP_RSHIFT64( SKP_Silk_inner_prod16_aligned_64( inputData, inputData + i, inputDataSize - i ), nRightShifts ) );\r
-        }\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_autocorr.c                                                *
+ *                                                                      *
+ * Calculates the autocorrelation                                       *
+ * The result has 29 non-zero bits for the first correlation, to leave  *
+ * some    room for adding white noise fractions etc.                   *
+ *                                                                      *
+ * Copyright 2008 (c), Skype Limited                                    *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Compute autocorrelation */
+void SKP_Silk_autocorr( 
+    SKP_int32        *results,                   /* O    Result (length correlationCount)            */
+    SKP_int          *scale,                     /* O    Scaling of the correlation vector           */
+    const SKP_int16  *inputData,                 /* I    Input data to correlate                     */
+    const SKP_int    inputDataSize,              /* I    Length of input                             */
+    const SKP_int    correlationCount            /* I    Number of correlation taps to compute       */
+)
+{
+    SKP_int   i, lz, nRightShifts, corrCount;
+    SKP_int64 corr64;
+
+    corrCount = SKP_min_int( inputDataSize, correlationCount );
+
+    /* compute energy (zero-lag correlation) */
+    corr64 = SKP_Silk_inner_prod16_aligned_64( inputData, inputData, inputDataSize );
+
+    /* deal with all-zero input data */
+    corr64 += 1;
+
+    /* number of leading zeros */
+    lz = SKP_Silk_CLZ64( corr64 );
+
+    /* scaling: number of right shifts applied to correlations */
+    nRightShifts = 35 - lz;
+    *scale = nRightShifts;
+
+    if( nRightShifts <= 0 ) {
+        results[ 0 ] = SKP_LSHIFT( (SKP_int32)SKP_CHECK_FIT32( corr64 ), -nRightShifts );
+
+        /* compute remaining correlations based on int32 inner product */
+          for( i = 1; i < corrCount; i++ ) {
+            results[ i ] = SKP_LSHIFT( SKP_Silk_inner_prod_aligned( inputData, inputData + i, inputDataSize - i ), -nRightShifts );
+        }
+    } else {
+        results[ 0 ] = (SKP_int32)SKP_CHECK_FIT32( SKP_RSHIFT64( corr64, nRightShifts ) );
+
+        /* compute remaining correlations based on int64 inner product */
+          for( i = 1; i < corrCount; i++ ) {
+            results[ i ] =  (SKP_int32)SKP_CHECK_FIT32( SKP_RSHIFT64( SKP_Silk_inner_prod16_aligned_64( inputData, inputData + i, inputDataSize - i ), nRightShifts ) );
+        }
+    }
+}
index 611809dc3281ed65fa506697dc4ad1cc98e4f07c..f634e77e49ed7a5747abb31f922afb3230eef5fc 100644 (file)
@@ -1,72 +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
-/*                                                                      *\r
- * SKP_Silk_biquad.c                                                  *\r
- *                                                                      *\r
- * Second order ARMA filter                                             *\r
- * Can handle slowly varying filter coefficients                        *\r
- *                                                                      *\r
- * Copyright 2006 (c), Skype Limited                                    *\r
- * Date: 060221                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Second order ARMA filter */\r
-/* Can handle slowly varying filter coefficients */\r
-void SKP_Silk_biquad(\r
-    const SKP_int16      *in,        /* I:    input signal               */\r
-    const SKP_int16      *B,         /* I:    MA coefficients, Q13 [3]   */\r
-    const SKP_int16      *A,         /* I:    AR coefficients, Q13 [2]   */\r
-    SKP_int32            *S,         /* I/O:  state vector [2]           */\r
-    SKP_int16            *out,       /* O:    output signal              */\r
-    const SKP_int32      len         /* I:    signal length              */\r
-)\r
-{\r
-    SKP_int   k, in16;\r
-    SKP_int32 A0_neg, A1_neg, S0, S1, out32, tmp32;\r
-\r
-    S0 = S[ 0 ];\r
-    S1 = S[ 1 ];\r
-    A0_neg = -A[ 0 ];\r
-    A1_neg = -A[ 1 ];\r
-    for( k = 0; k < len; k++ ) {\r
-        /* S[ 0 ], S[ 1 ]: Q13 */\r
-        in16  = in[ k ];\r
-        out32 = SKP_SMLABB( S0, in16, B[ 0 ] );\r
-\r
-        S0 = SKP_SMLABB( S1, in16, B[ 1 ] );\r
-        S0 += SKP_LSHIFT( SKP_SMULWB( out32, A0_neg ), 3 );\r
-\r
-        S1 = SKP_LSHIFT( SKP_SMULWB( out32, A1_neg ), 3 );\r
-        S1 = SKP_SMLABB( S1, in16, B[ 2 ] );\r
-        tmp32    = SKP_RSHIFT_ROUND( out32, 13 ) + 1;\r
-        out[ k ] = (SKP_int16)SKP_SAT16( tmp32 );\r
-    }\r
-    S[ 0 ] = S0;\r
-    S[ 1 ] = S1;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_biquad.c                                                  *
+ *                                                                      *
+ * Second order ARMA filter                                             *
+ * Can handle slowly varying filter coefficients                        *
+ *                                                                      *
+ * Copyright 2006 (c), Skype Limited                                    *
+ * Date: 060221                                                         *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Second order ARMA filter */
+/* Can handle slowly varying filter coefficients */
+void SKP_Silk_biquad(
+    const SKP_int16      *in,        /* I:    input signal               */
+    const SKP_int16      *B,         /* I:    MA coefficients, Q13 [3]   */
+    const SKP_int16      *A,         /* I:    AR coefficients, Q13 [2]   */
+    SKP_int32            *S,         /* I/O:  state vector [2]           */
+    SKP_int16            *out,       /* O:    output signal              */
+    const SKP_int32      len         /* I:    signal length              */
+)
+{
+    SKP_int   k, in16;
+    SKP_int32 A0_neg, A1_neg, S0, S1, out32, tmp32;
+
+    S0 = S[ 0 ];
+    S1 = S[ 1 ];
+    A0_neg = -A[ 0 ];
+    A1_neg = -A[ 1 ];
+    for( k = 0; k < len; k++ ) {
+        /* S[ 0 ], S[ 1 ]: Q13 */
+        in16  = in[ k ];
+        out32 = SKP_SMLABB( S0, in16, B[ 0 ] );
+
+        S0 = SKP_SMLABB( S1, in16, B[ 1 ] );
+        S0 += SKP_LSHIFT( SKP_SMULWB( out32, A0_neg ), 3 );
+
+        S1 = SKP_LSHIFT( SKP_SMULWB( out32, A1_neg ), 3 );
+        S1 = SKP_SMLABB( S1, in16, B[ 2 ] );
+        tmp32    = SKP_RSHIFT_ROUND( out32, 13 ) + 1;
+        out[ k ] = (SKP_int16)SKP_SAT16( tmp32 );
+    }
+    S[ 0 ] = S0;
+    S[ 1 ] = S1;
+}
index c97cdeed889c4d4800df3d9f87fb4ae91f87a892..9fb05901664d02c932559a734b07263a179a2d7a 100644 (file)
@@ -1,73 +1,73 @@
-/***********************************************************************\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_biquad_alt.c                                              *\r
- *                                                                      *\r
- * Second order ARMA filter                                             *\r
- * Can handle slowly varying filter coefficients                        *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-\r
-/* Second order ARMA filter, alternative implementation */\r
-void SKP_Silk_biquad_alt(\r
-    const SKP_int16      *in,            /* I:    Input signal                   */\r
-    const SKP_int32      *B_Q28,         /* I:    MA coefficients [3]            */\r
-    const SKP_int32      *A_Q28,         /* I:    AR coefficients [2]            */\r
-    SKP_int32            *S,             /* I/O: State vector [2]                */\r
-    SKP_int16            *out,           /* O:    Output signal                  */\r
-    const SKP_int32      len             /* I:    Signal length (must be even)   */\r
-)\r
-{\r
-    /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */\r
-    SKP_int   k;\r
-    SKP_int32 inval, A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14;\r
-\r
-    /* Negate A_Q28 values and split in two parts */\r
-    A0_L_Q28 = ( -A_Q28[ 0 ] ) & 0x00003FFF;        /* lower part */\r
-    A0_U_Q28 = SKP_RSHIFT( -A_Q28[ 0 ], 14 );       /* upper part */\r
-    A1_L_Q28 = ( -A_Q28[ 1 ] ) & 0x00003FFF;        /* lower part */\r
-    A1_U_Q28 = SKP_RSHIFT( -A_Q28[ 1 ], 14 );       /* upper part */\r
-    \r
-    for( k = 0; k < len; k++ ) {\r
-        /* S[ 0 ], S[ 1 ]: Q12 */\r
-        inval = in[ k ];\r
-        out32_Q14 = SKP_LSHIFT( SKP_SMLAWB( S[ 0 ], B_Q28[ 0 ], inval ), 2 );\r
-\r
-        S[ 0 ] = S[1] + SKP_RSHIFT_ROUND( SKP_SMULWB( out32_Q14, A0_L_Q28 ), 14 );\r
-        S[ 0 ] = SKP_SMLAWB( S[ 0 ], out32_Q14, A0_U_Q28 );\r
-        S[ 0 ] = SKP_SMLAWB( S[ 0 ], B_Q28[ 1 ], inval);\r
-\r
-        S[ 1 ] = SKP_RSHIFT_ROUND( SKP_SMULWB( out32_Q14, A1_L_Q28 ), 14 );\r
-        S[ 1 ] = SKP_SMLAWB( S[ 1 ], out32_Q14, A1_U_Q28 );\r
-        S[ 1 ] = SKP_SMLAWB( S[ 1 ], B_Q28[ 2 ], inval );\r
-\r
-        /* Scale back to Q0 and saturate */\r
-        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT( out32_Q14 + (1<<14) - 1, 14 ) );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_biquad_alt.c                                              *
+ *                                                                      *
+ * Second order ARMA filter                                             *
+ * Can handle slowly varying filter coefficients                        *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+
+/* Second order ARMA filter, alternative implementation */
+void SKP_Silk_biquad_alt(
+    const SKP_int16      *in,            /* I:    Input signal                   */
+    const SKP_int32      *B_Q28,         /* I:    MA coefficients [3]            */
+    const SKP_int32      *A_Q28,         /* I:    AR coefficients [2]            */
+    SKP_int32            *S,             /* I/O: State vector [2]                */
+    SKP_int16            *out,           /* O:    Output signal                  */
+    const SKP_int32      len             /* I:    Signal length (must be even)   */
+)
+{
+    /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */
+    SKP_int   k;
+    SKP_int32 inval, A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14;
+
+    /* Negate A_Q28 values and split in two parts */
+    A0_L_Q28 = ( -A_Q28[ 0 ] ) & 0x00003FFF;        /* lower part */
+    A0_U_Q28 = SKP_RSHIFT( -A_Q28[ 0 ], 14 );       /* upper part */
+    A1_L_Q28 = ( -A_Q28[ 1 ] ) & 0x00003FFF;        /* lower part */
+    A1_U_Q28 = SKP_RSHIFT( -A_Q28[ 1 ], 14 );       /* upper part */
+    
+    for( k = 0; k < len; k++ ) {
+        /* S[ 0 ], S[ 1 ]: Q12 */
+        inval = in[ k ];
+        out32_Q14 = SKP_LSHIFT( SKP_SMLAWB( S[ 0 ], B_Q28[ 0 ], inval ), 2 );
+
+        S[ 0 ] = S[1] + SKP_RSHIFT_ROUND( SKP_SMULWB( out32_Q14, A0_L_Q28 ), 14 );
+        S[ 0 ] = SKP_SMLAWB( S[ 0 ], out32_Q14, A0_U_Q28 );
+        S[ 0 ] = SKP_SMLAWB( S[ 0 ], B_Q28[ 1 ], inval);
+
+        S[ 1 ] = SKP_RSHIFT_ROUND( SKP_SMULWB( out32_Q14, A1_L_Q28 ), 14 );
+        S[ 1 ] = SKP_SMLAWB( S[ 1 ], out32_Q14, A1_U_Q28 );
+        S[ 1 ] = SKP_SMLAWB( S[ 1 ], B_Q28[ 2 ], inval );
+
+        /* Scale back to Q0 and saturate */
+        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT( out32_Q14 + (1<<14) - 1, 14 ) );
+    }
+}
index fbf9e874aa48bbd858897bca0643d1e23227ef6f..7e7d306f8a877c2d23e00007467fd9320a78cc64 100644 (file)
-/***********************************************************************\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_burg_modified.c                                           *\r
- *                                                                      *\r
- * Calculates the reflection coefficients from the input vector         *\r
- * Input vector contains nb_subfr sub vectors of length L_sub + D       *\r
- *                                                                      *\r
- * Copyright 2009 (c), Skype Limited                                    *\r
- * Date: 100105                                                         *\r
- */\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-#define MAX_FRAME_SIZE              544 // subfr_length * nb_subfr = ( 0.005 * 24000 + 16 ) * 4 = 544\r
-#define MAX_NB_SUBFR                4\r
-\r
-#define QA                          25\r
-#define N_BITS_HEAD_ROOM            2\r
-#define MIN_RSHIFTS                 -16\r
-#define MAX_RSHIFTS                 (32 - QA)\r
-\r
-/* Compute reflection coefficients from input signal */\r
-void SKP_Silk_burg_modified(\r
-    SKP_int32       *res_nrg,           /* O    residual energy                                                 */\r
-    SKP_int         *res_nrg_Q,         /* O    residual energy Q value                                         */\r
-    SKP_int32       A_Q16[],            /* O    prediction coefficients (length order)                          */\r
-    const SKP_int16 x[],                /* I    input signal, length: nb_subfr * ( D + subfr_length )           */\r
-    const SKP_int   subfr_length,       /* I    input signal subframe length (including D preceeding samples)   */\r
-    const SKP_int   nb_subfr,           /* I    number of subframes stacked in x                                */\r
-    const SKP_int32 WhiteNoiseFrac_Q32, /* I    fraction added to zero-lag autocorrelation                      */\r
-    const SKP_int   D                   /* I    order                                                           */\r
-)\r
-{\r
-    SKP_int         k, n, s, lz, rshifts, rshifts_extra;\r
-    SKP_int32       C0, num, nrg, rc_Q31, Atmp_QA, Atmp1, tmp1, tmp2, x1, x2;\r
-    const SKP_int16 *x_ptr;\r
-\r
-    SKP_int32       C_first_row[ SKP_Silk_MAX_ORDER_LPC ];\r
-    SKP_int32       C_last_row[  SKP_Silk_MAX_ORDER_LPC ];\r
-    SKP_int32       Af_QA[       SKP_Silk_MAX_ORDER_LPC ];\r
-\r
-    SKP_int32       CAf[ SKP_Silk_MAX_ORDER_LPC + 1 ];\r
-    SKP_int32       CAb[ SKP_Silk_MAX_ORDER_LPC + 1 ];\r
-\r
-    SKP_assert( subfr_length * nb_subfr <= MAX_FRAME_SIZE );\r
-    SKP_assert( nb_subfr <= MAX_NB_SUBFR );\r
-\r
-\r
-    /* Compute autocorrelations, added over subframes */\r
-    SKP_Silk_sum_sqr_shift( &C0, &rshifts, x, nb_subfr * subfr_length );\r
-    if( rshifts > MAX_RSHIFTS ) {\r
-        C0 = SKP_LSHIFT32( C0, rshifts - MAX_RSHIFTS );\r
-        SKP_assert( C0 > 0 );\r
-        rshifts = MAX_RSHIFTS;\r
-    } else {\r
-        lz = SKP_Silk_CLZ32( C0 ) - 1;\r
-        rshifts_extra = N_BITS_HEAD_ROOM - lz;\r
-        if( rshifts_extra > 0 ) {\r
-            rshifts_extra = SKP_min( rshifts_extra, MAX_RSHIFTS - rshifts );\r
-            C0 = SKP_RSHIFT32( C0, rshifts_extra );\r
-        } else {\r
-            rshifts_extra = SKP_max( rshifts_extra, MIN_RSHIFTS - rshifts );\r
-            C0 = SKP_LSHIFT32( C0, -rshifts_extra );\r
-        }\r
-        rshifts += rshifts_extra;\r
-    }\r
-    SKP_memset( C_first_row, 0, SKP_Silk_MAX_ORDER_LPC * sizeof( SKP_int32 ) );\r
-    if( rshifts > 0 ) {\r
-        for( s = 0; s < nb_subfr; s++ ) {\r
-            x_ptr = x + s * subfr_length;\r
-            for( n = 1; n < D + 1; n++ ) {\r
-                C_first_row[ n - 1 ] += (SKP_int32)SKP_RSHIFT64( \r
-                    SKP_Silk_inner_prod16_aligned_64( x_ptr, x_ptr + n, subfr_length - n ), rshifts );\r
-            }\r
-        }\r
-    } else {\r
-        for( s = 0; s < nb_subfr; s++ ) {\r
-            x_ptr = x + s * subfr_length;\r
-            for( n = 1; n < D + 1; n++ ) {\r
-                C_first_row[ n - 1 ] += SKP_LSHIFT32( \r
-                    SKP_Silk_inner_prod_aligned( x_ptr, x_ptr + n, subfr_length - n ), -rshifts );\r
-            }\r
-        }\r
-    }\r
-    SKP_memcpy( C_last_row, C_first_row, SKP_Silk_MAX_ORDER_LPC * sizeof( SKP_int32 ) );\r
-    \r
-    /* Initialize */\r
-    CAb[ 0 ] = CAf[ 0 ] = C0 + SKP_SMMUL( WhiteNoiseFrac_Q32, C0 ) + 1;         // Q(-rshifts)\r
-\r
-    for( n = 0; n < D; n++ ) {\r
-        /* Update first row of correlation matrix (without first element) */\r
-        /* Update last row of correlation matrix (without last element, stored in reversed order) */\r
-        /* Update C * Af */\r
-        /* Update C * flipud(Af) (stored in reversed order) */\r
-        if( rshifts > -2 ) {\r
-            for( s = 0; s < nb_subfr; s++ ) {\r
-                x_ptr = x + s * subfr_length;\r
-                x1  = -SKP_LSHIFT32( (SKP_int32)x_ptr[ n ],                    16 - rshifts );      // Q(16-rshifts)\r
-                x2  = -SKP_LSHIFT32( (SKP_int32)x_ptr[ subfr_length - n - 1 ], 16 - rshifts );      // Q(16-rshifts)\r
-                tmp1 = SKP_LSHIFT32( (SKP_int32)x_ptr[ n ],                    QA - 16 );           // Q(QA-16)\r
-                tmp2 = SKP_LSHIFT32( (SKP_int32)x_ptr[ subfr_length - n - 1 ], QA - 16 );           // Q(QA-16)\r
-                for( k = 0; k < n; k++ ) {\r
-                    C_first_row[ k ] = SKP_SMLAWB( C_first_row[ k ], x1, x_ptr[ n - k - 1 ]            ); // Q( -rshifts )\r
-                    C_last_row[ k ]  = SKP_SMLAWB( C_last_row[ k ],  x2, x_ptr[ subfr_length - n + k ] ); // Q( -rshifts )\r
-                    Atmp_QA = Af_QA[ k ];\r
-                    tmp1 = SKP_SMLAWB( tmp1, Atmp_QA, x_ptr[ n - k - 1 ]            );              // Q(QA-16)\r
-                    tmp2 = SKP_SMLAWB( tmp2, Atmp_QA, x_ptr[ subfr_length - n + k ] );              // Q(QA-16)\r
-                }\r
-                tmp1 = SKP_LSHIFT32( -tmp1, 32 - QA - rshifts );                                    // Q(16-rshifts)\r
-                tmp2 = SKP_LSHIFT32( -tmp2, 32 - QA - rshifts );                                    // Q(16-rshifts)\r
-                for( k = 0; k <= n; k++ ) {\r
-                    CAf[ k ] = SKP_SMLAWB( CAf[ k ], tmp1, x_ptr[ n - k ]                    );     // Q( -rshift )\r
-                    CAb[ k ] = SKP_SMLAWB( CAb[ k ], tmp2, x_ptr[ subfr_length - n + k - 1 ] );     // Q( -rshift )\r
-                }\r
-            }\r
-        } else {\r
-            for( s = 0; s < nb_subfr; s++ ) {\r
-                x_ptr = x + s * subfr_length;\r
-                x1  = -SKP_LSHIFT32( (SKP_int32)x_ptr[ n ],                    -rshifts );          // Q( -rshifts )\r
-                x2  = -SKP_LSHIFT32( (SKP_int32)x_ptr[ subfr_length - n - 1 ], -rshifts );          // Q( -rshifts )\r
-                tmp1 = SKP_LSHIFT32( (SKP_int32)x_ptr[ n ],                    17 );                // Q17\r
-                tmp2 = SKP_LSHIFT32( (SKP_int32)x_ptr[ subfr_length - n - 1 ], 17 );                // Q17\r
-                for( k = 0; k < n; k++ ) {\r
-                    C_first_row[ k ] = SKP_MLA( C_first_row[ k ], x1, x_ptr[ n - k - 1 ]            ); // Q( -rshifts )\r
-                    C_last_row[ k ]  = SKP_MLA( C_last_row[ k ],  x2, x_ptr[ subfr_length - n + k ] ); // Q( -rshifts )\r
-                    Atmp1 = SKP_RSHIFT_ROUND( Af_QA[ k ], QA - 17 );                                // Q17\r
-                    tmp1 = SKP_MLA( tmp1, x_ptr[ n - k - 1 ],            Atmp1 );                   // Q17\r
-                    tmp2 = SKP_MLA( tmp2, x_ptr[ subfr_length - n + k ], Atmp1 );                   // Q17\r
-                }\r
-                tmp1 = -tmp1;                                                                       // Q17\r
-                tmp2 = -tmp2;                                                                       // Q17\r
-                for( k = 0; k <= n; k++ ) {\r
-                    CAf[ k ] = SKP_SMLAWW( CAf[ k ], tmp1, \r
-                        SKP_LSHIFT32( (SKP_int32)x_ptr[ n - k ], -rshifts - 1 ) );                  // Q( -rshift )\r
-                    CAb[ k ] = SKP_SMLAWW( CAb[ k ], tmp2, \r
-                        SKP_LSHIFT32( (SKP_int32)x_ptr[ subfr_length - n + k - 1 ], -rshifts - 1 ) );// Q( -rshift )\r
-                }\r
-            }\r
-        }\r
-\r
-        /* Calculate nominator and denominator for the next order reflection (parcor) coefficient */\r
-        tmp1 = C_first_row[ n ];                                                            // Q( -rshifts )\r
-        tmp2 = C_last_row[ n ];                                                             // Q( -rshifts )\r
-        num  = 0;                                                                           // Q( -rshifts )\r
-        nrg  = SKP_ADD32( CAb[ 0 ], CAf[ 0 ] );                                             // Q( 1-rshifts )\r
-        for( k = 0; k < n; k++ ) {\r
-            Atmp_QA = Af_QA[ k ];\r
-            lz = SKP_Silk_CLZ32( SKP_abs( Atmp_QA ) ) - 1;\r
-            lz = SKP_min( 32 - QA, lz );\r
-            Atmp1 = SKP_LSHIFT32( Atmp_QA, lz );                                            // Q( QA + lz )\r
-\r
-            tmp1 = SKP_ADD_LSHIFT32( tmp1, SKP_SMMUL( C_last_row[  n - k - 1 ], Atmp1 ), 32 - QA - lz );    // Q( -rshifts )\r
-            tmp2 = SKP_ADD_LSHIFT32( tmp2, SKP_SMMUL( C_first_row[ n - k - 1 ], Atmp1 ), 32 - QA - lz );    // Q( -rshifts )\r
-            num  = SKP_ADD_LSHIFT32( num,  SKP_SMMUL( CAb[ n - k ],             Atmp1 ), 32 - QA - lz );    // Q( -rshifts )\r
-            nrg  = SKP_ADD_LSHIFT32( nrg,  SKP_SMMUL( SKP_ADD32( CAb[ k + 1 ], CAf[ k + 1 ] ), \r
-                                                                                Atmp1 ), 32 - QA - lz );    // Q( 1-rshifts )\r
-        }\r
-        CAf[ n + 1 ] = tmp1;                                                                // Q( -rshifts )\r
-        CAb[ n + 1 ] = tmp2;                                                                // Q( -rshifts )\r
-        num = SKP_ADD32( num, tmp2 );                                                       // Q( -rshifts )\r
-        num = SKP_LSHIFT32( -num, 1 );                                                      // Q( 1-rshifts )\r
-\r
-        /* Calculate the next order reflection (parcor) coefficient */\r
-        if( SKP_abs( num ) < nrg ) {\r
-            rc_Q31 = SKP_DIV32_varQ( num, nrg, 31 );\r
-        } else {\r
-            /* Negative energy or ratio too high; set remaining coefficients to zero and exit loop */\r
-            SKP_memset( &Af_QA[ n ], 0, ( D - n ) * sizeof( SKP_int32 ) );\r
-            SKP_assert( 0 );\r
-            break;\r
-        }\r
-\r
-        /* Update the AR coefficients */\r
-        for( k = 0; k < (n + 1) >> 1; k++ ) {\r
-            tmp1 = Af_QA[ k ];                                                              // QA\r
-            tmp2 = Af_QA[ n - k - 1 ];                                                      // QA\r
-            Af_QA[ k ]         = SKP_ADD_LSHIFT32( tmp1, SKP_SMMUL( tmp2, rc_Q31 ), 1 );    // QA\r
-            Af_QA[ n - k - 1 ] = SKP_ADD_LSHIFT32( tmp2, SKP_SMMUL( tmp1, rc_Q31 ), 1 );    // QA\r
-        }\r
-        Af_QA[ n ] = SKP_RSHIFT32( rc_Q31, 31 - QA );                                       // QA\r
-\r
-        /* Update C * Af and C * Ab */\r
-        for( k = 0; k <= n + 1; k++ ) {\r
-            tmp1 = CAf[ k ];                                                                // Q( -rshifts )\r
-            tmp2 = CAb[ n - k + 1 ];                                                        // Q( -rshifts )\r
-            CAf[ k ]         = SKP_ADD_LSHIFT32( tmp1, SKP_SMMUL( tmp2, rc_Q31 ), 1 );      // Q( -rshifts )\r
-            CAb[ n - k + 1 ] = SKP_ADD_LSHIFT32( tmp2, SKP_SMMUL( tmp1, rc_Q31 ), 1 );      // Q( -rshifts )\r
-        }\r
-    }\r
-\r
-    /* Return residual energy */\r
-    nrg  = CAf[ 0 ];                                                                        // Q( -rshifts )\r
-    tmp1 = 1 << 16;                                                                         // Q16\r
-    for( k = 0; k < D; k++ ) {\r
-        Atmp1 = SKP_RSHIFT_ROUND( Af_QA[ k ], QA - 16 );                                    // Q16\r
-        nrg  = SKP_SMLAWW( nrg, CAf[ k + 1 ], Atmp1 );                                      // Q( -rshifts )\r
-        tmp1 = SKP_SMLAWW( tmp1, Atmp1, Atmp1 );                                            // Q16\r
-        A_Q16[ k ] = -Atmp1;\r
-    }\r
-    *res_nrg = SKP_SMLAWW( nrg, SKP_SMMUL( WhiteNoiseFrac_Q32, C0 ), -tmp1 );               // Q( -rshifts )\r
-    *res_nrg_Q = -rshifts;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_burg_modified.c                                           *
+ *                                                                      *
+ * Calculates the reflection coefficients from the input vector         *
+ * Input vector contains nb_subfr sub vectors of length L_sub + D       *
+ *                                                                      *
+ * Copyright 2009 (c), Skype Limited                                    *
+ * Date: 100105                                                         *
+ */
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+#define MAX_FRAME_SIZE              544 // subfr_length * nb_subfr = ( 0.005 * 24000 + 16 ) * 4 = 544
+#define MAX_NB_SUBFR                4
+
+#define QA                          25
+#define N_BITS_HEAD_ROOM            2
+#define MIN_RSHIFTS                 -16
+#define MAX_RSHIFTS                 (32 - QA)
+
+/* Compute reflection coefficients from input signal */
+void SKP_Silk_burg_modified(
+    SKP_int32       *res_nrg,           /* O    residual energy                                                 */
+    SKP_int         *res_nrg_Q,         /* O    residual energy Q value                                         */
+    SKP_int32       A_Q16[],            /* O    prediction coefficients (length order)                          */
+    const SKP_int16 x[],                /* I    input signal, length: nb_subfr * ( D + subfr_length )           */
+    const SKP_int   subfr_length,       /* I    input signal subframe length (including D preceeding samples)   */
+    const SKP_int   nb_subfr,           /* I    number of subframes stacked in x                                */
+    const SKP_int32 WhiteNoiseFrac_Q32, /* I    fraction added to zero-lag autocorrelation                      */
+    const SKP_int   D                   /* I    order                                                           */
+)
+{
+    SKP_int         k, n, s, lz, rshifts, rshifts_extra;
+    SKP_int32       C0, num, nrg, rc_Q31, Atmp_QA, Atmp1, tmp1, tmp2, x1, x2;
+    const SKP_int16 *x_ptr;
+
+    SKP_int32       C_first_row[ SKP_Silk_MAX_ORDER_LPC ];
+    SKP_int32       C_last_row[  SKP_Silk_MAX_ORDER_LPC ];
+    SKP_int32       Af_QA[       SKP_Silk_MAX_ORDER_LPC ];
+
+    SKP_int32       CAf[ SKP_Silk_MAX_ORDER_LPC + 1 ];
+    SKP_int32       CAb[ SKP_Silk_MAX_ORDER_LPC + 1 ];
+
+    SKP_assert( subfr_length * nb_subfr <= MAX_FRAME_SIZE );
+    SKP_assert( nb_subfr <= MAX_NB_SUBFR );
+
+
+    /* Compute autocorrelations, added over subframes */
+    SKP_Silk_sum_sqr_shift( &C0, &rshifts, x, nb_subfr * subfr_length );
+    if( rshifts > MAX_RSHIFTS ) {
+        C0 = SKP_LSHIFT32( C0, rshifts - MAX_RSHIFTS );
+        SKP_assert( C0 > 0 );
+        rshifts = MAX_RSHIFTS;
+    } else {
+        lz = SKP_Silk_CLZ32( C0 ) - 1;
+        rshifts_extra = N_BITS_HEAD_ROOM - lz;
+        if( rshifts_extra > 0 ) {
+            rshifts_extra = SKP_min( rshifts_extra, MAX_RSHIFTS - rshifts );
+            C0 = SKP_RSHIFT32( C0, rshifts_extra );
+        } else {
+            rshifts_extra = SKP_max( rshifts_extra, MIN_RSHIFTS - rshifts );
+            C0 = SKP_LSHIFT32( C0, -rshifts_extra );
+        }
+        rshifts += rshifts_extra;
+    }
+    SKP_memset( C_first_row, 0, SKP_Silk_MAX_ORDER_LPC * sizeof( SKP_int32 ) );
+    if( rshifts > 0 ) {
+        for( s = 0; s < nb_subfr; s++ ) {
+            x_ptr = x + s * subfr_length;
+            for( n = 1; n < D + 1; n++ ) {
+                C_first_row[ n - 1 ] += (SKP_int32)SKP_RSHIFT64( 
+                    SKP_Silk_inner_prod16_aligned_64( x_ptr, x_ptr + n, subfr_length - n ), rshifts );
+            }
+        }
+    } else {
+        for( s = 0; s < nb_subfr; s++ ) {
+            x_ptr = x + s * subfr_length;
+            for( n = 1; n < D + 1; n++ ) {
+                C_first_row[ n - 1 ] += SKP_LSHIFT32( 
+                    SKP_Silk_inner_prod_aligned( x_ptr, x_ptr + n, subfr_length - n ), -rshifts );
+            }
+        }
+    }
+    SKP_memcpy( C_last_row, C_first_row, SKP_Silk_MAX_ORDER_LPC * sizeof( SKP_int32 ) );
+    
+    /* Initialize */
+    CAb[ 0 ] = CAf[ 0 ] = C0 + SKP_SMMUL( WhiteNoiseFrac_Q32, C0 ) + 1;         // Q(-rshifts)
+
+    for( n = 0; n < D; n++ ) {
+        /* Update first row of correlation matrix (without first element) */
+        /* Update last row of correlation matrix (without last element, stored in reversed order) */
+        /* Update C * Af */
+        /* Update C * flipud(Af) (stored in reversed order) */
+        if( rshifts > -2 ) {
+            for( s = 0; s < nb_subfr; s++ ) {
+                x_ptr = x + s * subfr_length;
+                x1  = -SKP_LSHIFT32( (SKP_int32)x_ptr[ n ],                    16 - rshifts );      // Q(16-rshifts)
+                x2  = -SKP_LSHIFT32( (SKP_int32)x_ptr[ subfr_length - n - 1 ], 16 - rshifts );      // Q(16-rshifts)
+                tmp1 = SKP_LSHIFT32( (SKP_int32)x_ptr[ n ],                    QA - 16 );           // Q(QA-16)
+                tmp2 = SKP_LSHIFT32( (SKP_int32)x_ptr[ subfr_length - n - 1 ], QA - 16 );           // Q(QA-16)
+                for( k = 0; k < n; k++ ) {
+                    C_first_row[ k ] = SKP_SMLAWB( C_first_row[ k ], x1, x_ptr[ n - k - 1 ]            ); // Q( -rshifts )
+                    C_last_row[ k ]  = SKP_SMLAWB( C_last_row[ k ],  x2, x_ptr[ subfr_length - n + k ] ); // Q( -rshifts )
+                    Atmp_QA = Af_QA[ k ];
+                    tmp1 = SKP_SMLAWB( tmp1, Atmp_QA, x_ptr[ n - k - 1 ]            );              // Q(QA-16)
+                    tmp2 = SKP_SMLAWB( tmp2, Atmp_QA, x_ptr[ subfr_length - n + k ] );              // Q(QA-16)
+                }
+                tmp1 = SKP_LSHIFT32( -tmp1, 32 - QA - rshifts );                                    // Q(16-rshifts)
+                tmp2 = SKP_LSHIFT32( -tmp2, 32 - QA - rshifts );                                    // Q(16-rshifts)
+                for( k = 0; k <= n; k++ ) {
+                    CAf[ k ] = SKP_SMLAWB( CAf[ k ], tmp1, x_ptr[ n - k ]                    );     // Q( -rshift )
+                    CAb[ k ] = SKP_SMLAWB( CAb[ k ], tmp2, x_ptr[ subfr_length - n + k - 1 ] );     // Q( -rshift )
+                }
+            }
+        } else {
+            for( s = 0; s < nb_subfr; s++ ) {
+                x_ptr = x + s * subfr_length;
+                x1  = -SKP_LSHIFT32( (SKP_int32)x_ptr[ n ],                    -rshifts );          // Q( -rshifts )
+                x2  = -SKP_LSHIFT32( (SKP_int32)x_ptr[ subfr_length - n - 1 ], -rshifts );          // Q( -rshifts )
+                tmp1 = SKP_LSHIFT32( (SKP_int32)x_ptr[ n ],                    17 );                // Q17
+                tmp2 = SKP_LSHIFT32( (SKP_int32)x_ptr[ subfr_length - n - 1 ], 17 );                // Q17
+                for( k = 0; k < n; k++ ) {
+                    C_first_row[ k ] = SKP_MLA( C_first_row[ k ], x1, x_ptr[ n - k - 1 ]            ); // Q( -rshifts )
+                    C_last_row[ k ]  = SKP_MLA( C_last_row[ k ],  x2, x_ptr[ subfr_length - n + k ] ); // Q( -rshifts )
+                    Atmp1 = SKP_RSHIFT_ROUND( Af_QA[ k ], QA - 17 );                                // Q17
+                    tmp1 = SKP_MLA( tmp1, x_ptr[ n - k - 1 ],            Atmp1 );                   // Q17
+                    tmp2 = SKP_MLA( tmp2, x_ptr[ subfr_length - n + k ], Atmp1 );                   // Q17
+                }
+                tmp1 = -tmp1;                                                                       // Q17
+                tmp2 = -tmp2;                                                                       // Q17
+                for( k = 0; k <= n; k++ ) {
+                    CAf[ k ] = SKP_SMLAWW( CAf[ k ], tmp1, 
+                        SKP_LSHIFT32( (SKP_int32)x_ptr[ n - k ], -rshifts - 1 ) );                  // Q( -rshift )
+                    CAb[ k ] = SKP_SMLAWW( CAb[ k ], tmp2, 
+                        SKP_LSHIFT32( (SKP_int32)x_ptr[ subfr_length - n + k - 1 ], -rshifts - 1 ) );// Q( -rshift )
+                }
+            }
+        }
+
+        /* Calculate nominator and denominator for the next order reflection (parcor) coefficient */
+        tmp1 = C_first_row[ n ];                                                            // Q( -rshifts )
+        tmp2 = C_last_row[ n ];                                                             // Q( -rshifts )
+        num  = 0;                                                                           // Q( -rshifts )
+        nrg  = SKP_ADD32( CAb[ 0 ], CAf[ 0 ] );                                             // Q( 1-rshifts )
+        for( k = 0; k < n; k++ ) {
+            Atmp_QA = Af_QA[ k ];
+            lz = SKP_Silk_CLZ32( SKP_abs( Atmp_QA ) ) - 1;
+            lz = SKP_min( 32 - QA, lz );
+            Atmp1 = SKP_LSHIFT32( Atmp_QA, lz );                                            // Q( QA + lz )
+
+            tmp1 = SKP_ADD_LSHIFT32( tmp1, SKP_SMMUL( C_last_row[  n - k - 1 ], Atmp1 ), 32 - QA - lz );    // Q( -rshifts )
+            tmp2 = SKP_ADD_LSHIFT32( tmp2, SKP_SMMUL( C_first_row[ n - k - 1 ], Atmp1 ), 32 - QA - lz );    // Q( -rshifts )
+            num  = SKP_ADD_LSHIFT32( num,  SKP_SMMUL( CAb[ n - k ],             Atmp1 ), 32 - QA - lz );    // Q( -rshifts )
+            nrg  = SKP_ADD_LSHIFT32( nrg,  SKP_SMMUL( SKP_ADD32( CAb[ k + 1 ], CAf[ k + 1 ] ), 
+                                                                                Atmp1 ), 32 - QA - lz );    // Q( 1-rshifts )
+        }
+        CAf[ n + 1 ] = tmp1;                                                                // Q( -rshifts )
+        CAb[ n + 1 ] = tmp2;                                                                // Q( -rshifts )
+        num = SKP_ADD32( num, tmp2 );                                                       // Q( -rshifts )
+        num = SKP_LSHIFT32( -num, 1 );                                                      // Q( 1-rshifts )
+
+        /* Calculate the next order reflection (parcor) coefficient */
+        if( SKP_abs( num ) < nrg ) {
+            rc_Q31 = SKP_DIV32_varQ( num, nrg, 31 );
+        } else {
+            /* Negative energy or ratio too high; set remaining coefficients to zero and exit loop */
+            SKP_memset( &Af_QA[ n ], 0, ( D - n ) * sizeof( SKP_int32 ) );
+            SKP_assert( 0 );
+            break;
+        }
+
+        /* Update the AR coefficients */
+        for( k = 0; k < (n + 1) >> 1; k++ ) {
+            tmp1 = Af_QA[ k ];                                                              // QA
+            tmp2 = Af_QA[ n - k - 1 ];                                                      // QA
+            Af_QA[ k ]         = SKP_ADD_LSHIFT32( tmp1, SKP_SMMUL( tmp2, rc_Q31 ), 1 );    // QA
+            Af_QA[ n - k - 1 ] = SKP_ADD_LSHIFT32( tmp2, SKP_SMMUL( tmp1, rc_Q31 ), 1 );    // QA
+        }
+        Af_QA[ n ] = SKP_RSHIFT32( rc_Q31, 31 - QA );                                       // QA
+
+        /* Update C * Af and C * Ab */
+        for( k = 0; k <= n + 1; k++ ) {
+            tmp1 = CAf[ k ];                                                                // Q( -rshifts )
+            tmp2 = CAb[ n - k + 1 ];                                                        // Q( -rshifts )
+            CAf[ k ]         = SKP_ADD_LSHIFT32( tmp1, SKP_SMMUL( tmp2, rc_Q31 ), 1 );      // Q( -rshifts )
+            CAb[ n - k + 1 ] = SKP_ADD_LSHIFT32( tmp2, SKP_SMMUL( tmp1, rc_Q31 ), 1 );      // Q( -rshifts )
+        }
+    }
+
+    /* Return residual energy */
+    nrg  = CAf[ 0 ];                                                                        // Q( -rshifts )
+    tmp1 = 1 << 16;                                                                         // Q16
+    for( k = 0; k < D; k++ ) {
+        Atmp1 = SKP_RSHIFT_ROUND( Af_QA[ k ], QA - 16 );                                    // Q16
+        nrg  = SKP_SMLAWW( nrg, CAf[ k + 1 ], Atmp1 );                                      // Q( -rshifts )
+        tmp1 = SKP_SMLAWW( tmp1, Atmp1, Atmp1 );                                            // Q16
+        A_Q16[ k ] = -Atmp1;
+    }
+    *res_nrg = SKP_SMLAWW( nrg, SKP_SMMUL( WhiteNoiseFrac_Q32, C0 ), -tmp1 );               // Q( -rshifts )
+    *res_nrg_Q = -rshifts;
+}
index 9cdc64a0a20093b838f3c07974ef52f540aaf6a4..0d38b0806d07f33e5d33cc14e7e47287dcffc33a 100644 (file)
@@ -1,49 +1,49 @@
-/***********************************************************************\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_SigProc_FIX.h"\r
-\r
-/* Chirp (bandwidth expand) LP AR filter */\r
-void SKP_Silk_bwexpander( \r
-    SKP_int16            *ar,        /* I/O  AR filter to be expanded (without leading 1)    */\r
-    const SKP_int        d,          /* I    Length of ar                                    */\r
-    SKP_int32            chirp_Q16   /* I    Chirp factor (typically in the range 0 to 1)    */\r
-)\r
-{\r
-    SKP_int   i;\r
-    SKP_int32 chirp_minus_one_Q16;\r
-\r
-    chirp_minus_one_Q16 = chirp_Q16 - 65536;\r
-\r
-    /* NB: Dont use SKP_SMULWB, instead of SKP_RSHIFT_ROUND( SKP_MUL() , 16 ), below. */\r
-    /* Bias in SKP_SMULWB can lead to unstable filters                                */\r
-    for( i = 0; i < d - 1; i++ ) {\r
-        ar[ i ]    = (SKP_int16)SKP_RSHIFT_ROUND( SKP_MUL( chirp_Q16, ar[ i ]             ), 16 );\r
-        chirp_Q16 +=            SKP_RSHIFT_ROUND( SKP_MUL( chirp_Q16, chirp_minus_one_Q16 ), 16 );\r
-    }\r
-    ar[ d - 1 ] = (SKP_int16)SKP_RSHIFT_ROUND( SKP_MUL( chirp_Q16, ar[ d - 1 ] ), 16 );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Chirp (bandwidth expand) LP AR filter */
+void SKP_Silk_bwexpander( 
+    SKP_int16            *ar,        /* I/O  AR filter to be expanded (without leading 1)    */
+    const SKP_int        d,          /* I    Length of ar                                    */
+    SKP_int32            chirp_Q16   /* I    Chirp factor (typically in the range 0 to 1)    */
+)
+{
+    SKP_int   i;
+    SKP_int32 chirp_minus_one_Q16;
+
+    chirp_minus_one_Q16 = chirp_Q16 - 65536;
+
+    /* NB: Dont use SKP_SMULWB, instead of SKP_RSHIFT_ROUND( SKP_MUL() , 16 ), below. */
+    /* Bias in SKP_SMULWB can lead to unstable filters                                */
+    for( i = 0; i < d - 1; i++ ) {
+        ar[ i ]    = (SKP_int16)SKP_RSHIFT_ROUND( SKP_MUL( chirp_Q16, ar[ i ]             ), 16 );
+        chirp_Q16 +=            SKP_RSHIFT_ROUND( SKP_MUL( chirp_Q16, chirp_minus_one_Q16 ), 16 );
+    }
+    ar[ d - 1 ] = (SKP_int16)SKP_RSHIFT_ROUND( SKP_MUL( chirp_Q16, ar[ d - 1 ] ), 16 );
+}
index f5f5e907adc17795a2fe7b7d1cc154a4e515359c..785d20dc0408fbbb05bbb519a387adb7cc10a79a 100644 (file)
@@ -1,46 +1,46 @@
-/***********************************************************************\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_SigProc_FIX.h"\r
-\r
-/* Chirp (bandwidth expand) LP AR filter */\r
-void SKP_Silk_bwexpander_32( \r
-    SKP_int32        *ar,      /* I/O    AR filter to be expanded (without leading 1)    */\r
-    const SKP_int    d,        /* I    Length of ar                                      */\r
-    SKP_int32        chirp_Q16 /* I    Chirp factor in Q16                               */\r
-)\r
-{\r
-    SKP_int   i;\r
-    SKP_int32 tmp_chirp_Q16;\r
-\r
-    tmp_chirp_Q16 = chirp_Q16;\r
-    for( i = 0; i < d - 1; i++ ) {\r
-        ar[ i ]       = SKP_SMULWW( ar[ i ],   tmp_chirp_Q16 );\r
-        tmp_chirp_Q16 = SKP_SMULWW( chirp_Q16, tmp_chirp_Q16 );\r
-    }\r
-    ar[ d - 1 ] = SKP_SMULWW( ar[ d - 1 ], tmp_chirp_Q16 );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Chirp (bandwidth expand) LP AR filter */
+void SKP_Silk_bwexpander_32( 
+    SKP_int32        *ar,      /* I/O    AR filter to be expanded (without leading 1)    */
+    const SKP_int    d,        /* I    Length of ar                                      */
+    SKP_int32        chirp_Q16 /* I    Chirp factor in Q16                               */
+)
+{
+    SKP_int   i;
+    SKP_int32 tmp_chirp_Q16;
+
+    tmp_chirp_Q16 = chirp_Q16;
+    for( i = 0; i < d - 1; i++ ) {
+        ar[ i ]       = SKP_SMULWW( ar[ i ],   tmp_chirp_Q16 );
+        tmp_chirp_Q16 = SKP_SMULWW( chirp_Q16, tmp_chirp_Q16 );
+    }
+    ar[ d - 1 ] = SKP_SMULWW( ar[ d - 1 ], tmp_chirp_Q16 );
+}
index e335fda678df9b519b664a94223ddd8b0378c3f1..04ae83036919ad66386a82871a7a242cd6d73019 100644 (file)
@@ -1,91 +1,91 @@
-/***********************************************************************\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
-//#define SKP_enc_map(a)                ((a) > 0 ? 1 : 0)\r
-//#define SKP_dec_map(a)                ((a) > 0 ? 1 : -1)\r
-/* shifting avoids if-statement */\r
-#define SKP_enc_map(a)                  ( SKP_RSHIFT( (a), 15 ) + 1 )\r
-#define SKP_dec_map(a)                  ( SKP_LSHIFT( (a),  1 ) - 1 )\r
-\r
-/* Encodes signs of excitation */\r
-void SKP_Silk_encode_signs(\r
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  Range coder state                       */\r
-    const SKP_int8                  q[],                /* I    Pulse signal                            */\r
-    const SKP_int                   length,             /* I    Length of input                         */\r
-    const SKP_int                   sigtype,            /* I    Signal type                             */\r
-    const SKP_int                   QuantOffsetType,    /* I    Quantization offset type                */\r
-    const SKP_int                   RateLevelIndex      /* I    Rate level index                        */\r
-)\r
-{\r
-    SKP_int i;\r
-    SKP_int inData;\r
-    SKP_uint16 cdf[ 3 ];\r
-\r
-    i = SKP_SMULBB( N_RATE_LEVELS - 1, SKP_LSHIFT( sigtype, 1 ) + QuantOffsetType ) + RateLevelIndex;\r
-    cdf[ 0 ] = 0;\r
-    cdf[ 1 ] = SKP_Silk_sign_CDF[ i ];\r
-    cdf[ 2 ] = 65535;\r
-    \r
-    for( i = 0; i < length; i++ ) {\r
-        if( q[ i ] != 0 ) {\r
-            inData = SKP_enc_map( q[ i ] ); /* - = 0, + = 1 */\r
-            SKP_Silk_range_encoder( sRC, inData, cdf );\r
-        }\r
-    }\r
-}\r
-\r
-/* Decodes signs of excitation */\r
-void SKP_Silk_decode_signs(\r
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  Range coder state                           */\r
-    SKP_int                         q[],                /* I/O  pulse signal                                */\r
-    const SKP_int                   length,             /* I    length of output                            */\r
-    const SKP_int                   sigtype,            /* I    Signal type                                 */\r
-    const SKP_int                   QuantOffsetType,    /* I    Quantization offset type                    */\r
-    const SKP_int                   RateLevelIndex      /* I    Rate Level Index                            */\r
-)\r
-{\r
-    SKP_int i;\r
-    SKP_int data;\r
-    SKP_uint16 cdf[ 3 ];\r
-\r
-    i = SKP_SMULBB( N_RATE_LEVELS - 1, SKP_LSHIFT( sigtype, 1 ) + QuantOffsetType ) + RateLevelIndex;\r
-    cdf[ 0 ] = 0;\r
-    cdf[ 1 ] = SKP_Silk_sign_CDF[ i ];\r
-    cdf[ 2 ] = 65535;\r
-    \r
-    for( i = 0; i < length; i++ ) {\r
-        if( q[ i ] > 0 ) {\r
-            SKP_Silk_range_decoder( &data, sRC, cdf, 1 );\r
-            /* attach sign */\r
-            /* implementation with shift, subtraction, multiplication */\r
-            q[ i ] *= SKP_dec_map( data );\r
-        }\r
-    }\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+//#define SKP_enc_map(a)                ((a) > 0 ? 1 : 0)
+//#define SKP_dec_map(a)                ((a) > 0 ? 1 : -1)
+/* shifting avoids if-statement */
+#define SKP_enc_map(a)                  ( SKP_RSHIFT( (a), 15 ) + 1 )
+#define SKP_dec_map(a)                  ( SKP_LSHIFT( (a),  1 ) - 1 )
+
+/* Encodes signs of excitation */
+void SKP_Silk_encode_signs(
+    SKP_Silk_range_coder_state      *sRC,               /* I/O  Range coder state                       */
+    const SKP_int8                  q[],                /* I    Pulse signal                            */
+    const SKP_int                   length,             /* I    Length of input                         */
+    const SKP_int                   sigtype,            /* I    Signal type                             */
+    const SKP_int                   QuantOffsetType,    /* I    Quantization offset type                */
+    const SKP_int                   RateLevelIndex      /* I    Rate level index                        */
+)
+{
+    SKP_int i;
+    SKP_int inData;
+    SKP_uint16 cdf[ 3 ];
+
+    i = SKP_SMULBB( N_RATE_LEVELS - 1, SKP_LSHIFT( sigtype, 1 ) + QuantOffsetType ) + RateLevelIndex;
+    cdf[ 0 ] = 0;
+    cdf[ 1 ] = SKP_Silk_sign_CDF[ i ];
+    cdf[ 2 ] = 65535;
+    
+    for( i = 0; i < length; i++ ) {
+        if( q[ i ] != 0 ) {
+            inData = SKP_enc_map( q[ i ] ); /* - = 0, + = 1 */
+            SKP_Silk_range_encoder( sRC, inData, cdf );
+        }
+    }
+}
+
+/* Decodes signs of excitation */
+void SKP_Silk_decode_signs(
+    SKP_Silk_range_coder_state      *sRC,               /* I/O  Range coder state                           */
+    SKP_int                         q[],                /* I/O  pulse signal                                */
+    const SKP_int                   length,             /* I    length of output                            */
+    const SKP_int                   sigtype,            /* I    Signal type                                 */
+    const SKP_int                   QuantOffsetType,    /* I    Quantization offset type                    */
+    const SKP_int                   RateLevelIndex      /* I    Rate Level Index                            */
+)
+{
+    SKP_int i;
+    SKP_int data;
+    SKP_uint16 cdf[ 3 ];
+
+    i = SKP_SMULBB( N_RATE_LEVELS - 1, SKP_LSHIFT( sigtype, 1 ) + QuantOffsetType ) + RateLevelIndex;
+    cdf[ 0 ] = 0;
+    cdf[ 1 ] = SKP_Silk_sign_CDF[ i ];
+    cdf[ 2 ] = 65535;
+    
+    for( i = 0; i < length; i++ ) {
+        if( q[ i ] > 0 ) {
+            SKP_Silk_range_decoder( &data, sRC, cdf, 1 );
+            /* attach sign */
+            /* implementation with shift, subtraction, multiplication */
+            q[ i ] *= SKP_dec_map( data );
+        }
+    }
+}
+
index cf5b70222fc32592cad20c509f872ec743611aa8..f5708ebb94cb5bad810b83e1bd093bbae2d20a2b 100644 (file)
@@ -1,76 +1,76 @@
-/***********************************************************************\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
-#ifndef SIGPROC_COMMON_PITCH_EST_DEFINES_H\r
-#define SIGPROC_COMMON_PITCH_EST_DEFINES_H\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/************************************************************/\r
-/* Definitions For Fix pitch estimator                      */\r
-/************************************************************/\r
-\r
-#define PITCH_EST_MAX_FS_KHZ                24 /* Maximum sampling frequency used */\r
-\r
-#define PITCH_EST_FRAME_LENGTH_MS           40 /* 40 ms */\r
-\r
-#define PITCH_EST_MAX_FRAME_LENGTH          (PITCH_EST_FRAME_LENGTH_MS * PITCH_EST_MAX_FS_KHZ)\r
-#define PITCH_EST_MAX_FRAME_LENGTH_ST_1     (PITCH_EST_MAX_FRAME_LENGTH >> 2)\r
-#define PITCH_EST_MAX_FRAME_LENGTH_ST_2     (PITCH_EST_MAX_FRAME_LENGTH >> 1)\r
-#define PITCH_EST_MAX_SF_FRAME_LENGTH       (PITCH_EST_SUB_FRAME * PITCH_EST_MAX_FS_KHZ)\r
-\r
-#define PITCH_EST_MAX_LAG_MS                18            /* 18 ms -> 56 Hz */\r
-#define PITCH_EST_MIN_LAG_MS                2            /* 2 ms -> 500 Hz */\r
-#define PITCH_EST_MAX_LAG                   (PITCH_EST_MAX_LAG_MS * PITCH_EST_MAX_FS_KHZ)\r
-#define PITCH_EST_MIN_LAG                   (PITCH_EST_MIN_LAG_MS * PITCH_EST_MAX_FS_KHZ)\r
-\r
-#define PITCH_EST_NB_SUBFR                  4\r
-\r
-#define PITCH_EST_D_SRCH_LENGTH             24\r
-\r
-#define PITCH_EST_MAX_DECIMATE_STATE_LENGTH 7\r
-\r
-#define PITCH_EST_NB_STAGE3_LAGS            5\r
-\r
-#define PITCH_EST_NB_CBKS_STAGE2            3\r
-#define PITCH_EST_NB_CBKS_STAGE2_EXT        11\r
-\r
-#define PITCH_EST_CB_mn2                    1\r
-#define PITCH_EST_CB_mx2                    2\r
-\r
-#define PITCH_EST_NB_CBKS_STAGE3_MAX        34\r
-#define PITCH_EST_NB_CBKS_STAGE3_MID        24\r
-#define PITCH_EST_NB_CBKS_STAGE3_MIN        16\r
-\r
-extern const SKP_int16 SKP_Silk_CB_lags_stage2[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE2_EXT];\r
-extern const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX];\r
-extern const SKP_int16 SKP_Silk_Lag_range_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ];\r
-extern const SKP_int16 SKP_Silk_cbk_sizes_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ];\r
-extern const SKP_int16 SKP_Silk_cbk_offsets_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ];\r
-\r
-#endif\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SIGPROC_COMMON_PITCH_EST_DEFINES_H
+#define SIGPROC_COMMON_PITCH_EST_DEFINES_H
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+/************************************************************/
+/* Definitions For Fix pitch estimator                      */
+/************************************************************/
+
+#define PITCH_EST_MAX_FS_KHZ                24 /* Maximum sampling frequency used */
+
+#define PITCH_EST_FRAME_LENGTH_MS           40 /* 40 ms */
+
+#define PITCH_EST_MAX_FRAME_LENGTH          (PITCH_EST_FRAME_LENGTH_MS * PITCH_EST_MAX_FS_KHZ)
+#define PITCH_EST_MAX_FRAME_LENGTH_ST_1     (PITCH_EST_MAX_FRAME_LENGTH >> 2)
+#define PITCH_EST_MAX_FRAME_LENGTH_ST_2     (PITCH_EST_MAX_FRAME_LENGTH >> 1)
+#define PITCH_EST_MAX_SF_FRAME_LENGTH       (PITCH_EST_SUB_FRAME * PITCH_EST_MAX_FS_KHZ)
+
+#define PITCH_EST_MAX_LAG_MS                18            /* 18 ms -> 56 Hz */
+#define PITCH_EST_MIN_LAG_MS                2            /* 2 ms -> 500 Hz */
+#define PITCH_EST_MAX_LAG                   (PITCH_EST_MAX_LAG_MS * PITCH_EST_MAX_FS_KHZ)
+#define PITCH_EST_MIN_LAG                   (PITCH_EST_MIN_LAG_MS * PITCH_EST_MAX_FS_KHZ)
+
+#define PITCH_EST_NB_SUBFR                  4
+
+#define PITCH_EST_D_SRCH_LENGTH             24
+
+#define PITCH_EST_MAX_DECIMATE_STATE_LENGTH 7
+
+#define PITCH_EST_NB_STAGE3_LAGS            5
+
+#define PITCH_EST_NB_CBKS_STAGE2            3
+#define PITCH_EST_NB_CBKS_STAGE2_EXT        11
+
+#define PITCH_EST_CB_mn2                    1
+#define PITCH_EST_CB_mx2                    2
+
+#define PITCH_EST_NB_CBKS_STAGE3_MAX        34
+#define PITCH_EST_NB_CBKS_STAGE3_MID        24
+#define PITCH_EST_NB_CBKS_STAGE3_MIN        16
+
+extern const SKP_int16 SKP_Silk_CB_lags_stage2[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE2_EXT];
+extern const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX];
+extern const SKP_int16 SKP_Silk_Lag_range_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ];
+extern const SKP_int16 SKP_Silk_cbk_sizes_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ];
+extern const SKP_int16 SKP_Silk_cbk_offsets_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ];
+
+#endif
+
index bf8b318098d4ab8e90b11f79490e87496dceb152..2ee426431ae1e1c046a89944ca42d9d5bb33a3ad 100644 (file)
-/***********************************************************************\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
-/* 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
-    const SKP_int32             TargetRate_bps      /* I    Target max bitrate (bps)                    */\r
-)\r
-{\r
-    SKP_int fs_kHz;\r
-\r
-    fs_kHz = psEncC->fs_kHz;\r
-    if( fs_kHz == 0 ) {\r
-        /* Encoder has just been initialized */\r
-        if( TargetRate_bps >= SWB2WB_BITRATE_BPS ) {\r
-            fs_kHz = 24;\r
-        } else if( TargetRate_bps >= WB2MB_BITRATE_BPS ) {\r
-            fs_kHz = 16;\r
-        } else if( TargetRate_bps >= MB2NB_BITRATE_BPS ) {\r
-            fs_kHz = 12;\r
-        } else {\r
-            fs_kHz = 8;\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
-    } else if( SKP_SMULBB( fs_kHz, 1000 ) > psEncC->API_fs_Hz || fs_kHz > psEncC->maxInternal_fs_kHz ) {\r
-        /* Make sure internal rate is not higher than external rate or maximum allowed */\r
-        fs_kHz = SKP_DIV32_16( psEncC->API_fs_Hz, 1000 );\r
-        fs_kHz = SKP_min( fs_kHz, psEncC->maxInternal_fs_kHz );\r
-    } else {\r
-        /* State machine for the internal sampling rate switching */\r
-        if( psEncC->API_fs_Hz > 8000 ) {\r
-            /* Accumulate the difference between the target rate and limit for switching down */\r
-            psEncC->bitrateDiff += SKP_MUL( psEncC->PacketSize_ms, psEncC->TargetRate_bps - psEncC->bitrate_threshold_down );\r
-            psEncC->bitrateDiff  = SKP_min( psEncC->bitrateDiff, 0 );\r
-\r
-            if( psEncC->vadFlag == NO_VOICE_ACTIVITY ) { /* Low speech activity */\r
-                /* Check if we should switch down */\r
-#if SWITCH_TRANSITION_FILTERING \r
-                if( ( psEncC->sLP.transition_frame_no == 0 ) &&                         /* Transition phase not active */\r
-                    ( psEncC->bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ||              /* Bitrate threshold is met */\r
-                    ( psEncC->sSWBdetect.WB_detected * psEncC->fs_kHz == 24 ) ) ) {     /* Forced down-switching due to WB input */\r
-                        psEncC->sLP.transition_frame_no = 1;                            /* Begin transition phase */\r
-                        psEncC->sLP.mode                = 0;                            /* Switch down */\r
-                } else if( \r
-                    ( psEncC->sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) &&    /* Transition phase complete */\r
-                    ( psEncC->sLP.mode == 0 ) ) {                                       /* Ready to switch down */\r
-                        psEncC->sLP.transition_frame_no = 0;                            /* Ready for new transition phase */\r
-#else\r
-                if( psEncC->bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) {               /* Bitrate threshold is met */ \r
-#endif            \r
-                    psEncC->bitrateDiff = 0;\r
-\r
-                    /* Switch to a lower sample frequency */\r
-                    if( psEncC->fs_kHz == 24 ) {\r
-                        fs_kHz = 16;\r
-                    } else if( psEncC->fs_kHz == 16 ) {\r
-                        fs_kHz = 12;\r
-                    } else {\r
-                        SKP_assert( psEncC->fs_kHz == 12 );\r
-                        fs_kHz = 8;\r
-                    }\r
-                }\r
-\r
-                /* Check if we should switch up */\r
-                if( ( ( psEncC->fs_kHz * 1000 < psEncC->API_fs_Hz ) &&\r
-                    ( psEncC->TargetRate_bps >= psEncC->bitrate_threshold_up ) && \r
-                    ( psEncC->sSWBdetect.WB_detected * psEncC->fs_kHz < 16 ) ) && \r
-                    ( ( ( psEncC->fs_kHz == 16 ) && ( psEncC->maxInternal_fs_kHz >= 24 ) ) || \r
-                    (   ( psEncC->fs_kHz == 12 ) && ( psEncC->maxInternal_fs_kHz >= 16 ) ) ||\r
-                    (   ( psEncC->fs_kHz ==  8 ) && ( psEncC->maxInternal_fs_kHz >= 12 ) ) ) \r
-#if SWITCH_TRANSITION_FILTERING\r
-                    && ( psEncC->sLP.transition_frame_no == 0 ) ) { /* No transition phase running, ready to switch */\r
-                        psEncC->sLP.mode = 1; /* Switch up */\r
-#else\r
-                    ) {\r
-#endif\r
-                    psEncC->bitrateDiff = 0;\r
-\r
-                    /* Switch to a higher sample frequency */\r
-                    if( psEncC->fs_kHz == 8 ) {\r
-                        fs_kHz = 12;\r
-                    } else if( psEncC->fs_kHz == 12 ) {\r
-                        fs_kHz = 16;\r
-                    } else {\r
-                        SKP_assert( psEncC->fs_kHz == 16 );\r
-                        fs_kHz = 24;\r
-                    }\r
-                }\r
-            }\r
-        }\r
-\r
-#if SWITCH_TRANSITION_FILTERING\r
-        /* After switching up, stop transition filter during speech inactivity */\r
-        if( ( psEncC->sLP.mode == 1 ) &&\r
-            ( psEncC->sLP.transition_frame_no >= TRANSITION_FRAMES_UP ) && \r
-            ( psEncC->vadFlag == NO_VOICE_ACTIVITY ) ) {\r
-\r
-                psEncC->sLP.transition_frame_no = 0;\r
-\r
-                /* Reset transition filter state */\r
-                SKP_memset( psEncC->sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) );\r
-        }\r
-#endif\r
-    }\r
-\r
-\r
-\r
-    return fs_kHz;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Control internal sampling rate */
+SKP_int SKP_Silk_control_audio_bandwidth(
+    SKP_Silk_encoder_state      *psEncC,            /* I/O  Pointer to Silk encoder state               */
+    const SKP_int32             TargetRate_bps      /* I    Target max bitrate (bps)                    */
+)
+{
+    SKP_int fs_kHz;
+
+    fs_kHz = psEncC->fs_kHz;
+    if( fs_kHz == 0 ) {
+        /* Encoder has just been initialized */
+        if( TargetRate_bps >= SWB2WB_BITRATE_BPS ) {
+            fs_kHz = 24;
+        } else if( TargetRate_bps >= WB2MB_BITRATE_BPS ) {
+            fs_kHz = 16;
+        } else if( TargetRate_bps >= MB2NB_BITRATE_BPS ) {
+            fs_kHz = 12;
+        } else {
+            fs_kHz = 8;
+        }
+        /* Make sure internal rate is not higher than external rate or maximum allowed, or lower than minimum allowed */
+        fs_kHz = SKP_min( fs_kHz, SKP_DIV32_16( psEncC->API_fs_Hz, 1000 ) );
+        fs_kHz = SKP_min( fs_kHz, psEncC->maxInternal_fs_kHz );
+    } else if( SKP_SMULBB( fs_kHz, 1000 ) > psEncC->API_fs_Hz || fs_kHz > psEncC->maxInternal_fs_kHz ) {
+        /* Make sure internal rate is not higher than external rate or maximum allowed */
+        fs_kHz = SKP_DIV32_16( psEncC->API_fs_Hz, 1000 );
+        fs_kHz = SKP_min( fs_kHz, psEncC->maxInternal_fs_kHz );
+    } else {
+        /* State machine for the internal sampling rate switching */
+        if( psEncC->API_fs_Hz > 8000 ) {
+            /* Accumulate the difference between the target rate and limit for switching down */
+            psEncC->bitrateDiff += SKP_MUL( psEncC->PacketSize_ms, psEncC->TargetRate_bps - psEncC->bitrate_threshold_down );
+            psEncC->bitrateDiff  = SKP_min( psEncC->bitrateDiff, 0 );
+
+            if( psEncC->vadFlag == NO_VOICE_ACTIVITY ) { /* Low speech activity */
+                /* Check if we should switch down */
+#if SWITCH_TRANSITION_FILTERING 
+                if( ( psEncC->sLP.transition_frame_no == 0 ) &&                         /* Transition phase not active */
+                    ( psEncC->bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ||              /* Bitrate threshold is met */
+                    ( psEncC->sSWBdetect.WB_detected * psEncC->fs_kHz == 24 ) ) ) {     /* Forced down-switching due to WB input */
+                        psEncC->sLP.transition_frame_no = 1;                            /* Begin transition phase */
+                        psEncC->sLP.mode                = 0;                            /* Switch down */
+                } else if( 
+                    ( psEncC->sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) &&    /* Transition phase complete */
+                    ( psEncC->sLP.mode == 0 ) ) {                                       /* Ready to switch down */
+                        psEncC->sLP.transition_frame_no = 0;                            /* Ready for new transition phase */
+#else
+                if( psEncC->bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) {               /* Bitrate threshold is met */ 
+#endif            
+                    psEncC->bitrateDiff = 0;
+
+                    /* Switch to a lower sample frequency */
+                    if( psEncC->fs_kHz == 24 ) {
+                        fs_kHz = 16;
+                    } else if( psEncC->fs_kHz == 16 ) {
+                        fs_kHz = 12;
+                    } else {
+                        SKP_assert( psEncC->fs_kHz == 12 );
+                        fs_kHz = 8;
+                    }
+                }
+
+                /* Check if we should switch up */
+                if( ( ( psEncC->fs_kHz * 1000 < psEncC->API_fs_Hz ) &&
+                    ( psEncC->TargetRate_bps >= psEncC->bitrate_threshold_up ) && 
+                    ( psEncC->sSWBdetect.WB_detected * psEncC->fs_kHz < 16 ) ) && 
+                    ( ( ( psEncC->fs_kHz == 16 ) && ( psEncC->maxInternal_fs_kHz >= 24 ) ) || 
+                    (   ( psEncC->fs_kHz == 12 ) && ( psEncC->maxInternal_fs_kHz >= 16 ) ) ||
+                    (   ( psEncC->fs_kHz ==  8 ) && ( psEncC->maxInternal_fs_kHz >= 12 ) ) ) 
+#if SWITCH_TRANSITION_FILTERING
+                    && ( psEncC->sLP.transition_frame_no == 0 ) ) { /* No transition phase running, ready to switch */
+                        psEncC->sLP.mode = 1; /* Switch up */
+#else
+                    ) {
+#endif
+                    psEncC->bitrateDiff = 0;
+
+                    /* Switch to a higher sample frequency */
+                    if( psEncC->fs_kHz == 8 ) {
+                        fs_kHz = 12;
+                    } else if( psEncC->fs_kHz == 12 ) {
+                        fs_kHz = 16;
+                    } else {
+                        SKP_assert( psEncC->fs_kHz == 16 );
+                        fs_kHz = 24;
+                    }
+                }
+            }
+        }
+
+#if SWITCH_TRANSITION_FILTERING
+        /* After switching up, stop transition filter during speech inactivity */
+        if( ( psEncC->sLP.mode == 1 ) &&
+            ( psEncC->sLP.transition_frame_no >= TRANSITION_FRAMES_UP ) && 
+            ( psEncC->vadFlag == NO_VOICE_ACTIVITY ) ) {
+
+                psEncC->sLP.transition_frame_no = 0;
+
+                /* Reset transition filter state */
+                SKP_memset( psEncC->sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) );
+        }
+#endif
+    }
+
+
+
+    return fs_kHz;
+}
index 6b4c80dbc3dd23770f3a6973f2782e67c9dfa157..496a228b9cd80258164f44a9ef324e8c17938ecb 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-#include "SKP_Silk_setup_complexity.h"\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_resamplers_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */\r
-    SKP_int                         fs_kHz              /* I    Internal sampling rate (kHz)            */\r
-);\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_packetsize_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */\r
-    SKP_int                         PacketSize_ms       /* I    Packet length (ms)                      */\r
-);\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_fs_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */\r
-    SKP_int                         fs_kHz              /* I    Internal sampling rate (kHz)            */\r
-);\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_rate_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */\r
-    SKP_int                         TargetRate_bps      /* I    Target max bitrate (if SNR_dB == 0)     */\r
-);\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_LBRR_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc              /* I/O  Pointer to Silk encoder state FIX       */\r
-);\r
-\r
-/* Control 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               DTX_enabled,            /* I    Enable / disable DTX                    */\r
-    const SKP_int               Complexity              /* I    Complexity (0->low; 1->medium; 2->high) */\r
-)\r
-{\r
-    SKP_int   fs_kHz, ret = 0;\r
-\r
-    if( psEnc->sCmn.controlled_since_last_payload != 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_FIX( 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_FIX( psEnc, fs_kHz );\r
-\r
-    /********************************************/\r
-    /* Set packet size                          */\r
-    /********************************************/\r
-    ret += SKP_Silk_setup_packetsize_FIX( psEnc, PacketSize_ms );\r
-\r
-    /********************************************/\r
-    /* Set internal sampling frequency          */\r
-    /********************************************/\r
-    ret += SKP_Silk_setup_fs_FIX( psEnc, fs_kHz );\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_FIX( 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_FIX( psEnc );\r
-\r
-    /********************************************/\r
-    /* Set DTX mode                             */\r
-    /********************************************/\r
-    if( DTX_enabled < 0 || DTX_enabled > 1 ) {\r
-        ret = SKP_SILK_ENC_INVALID_DTX_SETTING;\r
-    }\r
-    psEnc->sCmn.useDTX = DTX_enabled;\r
-    psEnc->sCmn.controlled_since_last_payload = 1;\r
-\r
-    return ret;\r
-}\r
-\r
-/* Control low bitrate redundancy usage */\r
-void SKP_Silk_LBRR_ctrl_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,     /* I    Encoder state FIX                           */\r
-    SKP_Silk_encoder_control        *psEncCtrlC /* I/O  Encoder control                             */\r
-)\r
-{\r
-    SKP_int LBRR_usage;\r
-\r
-    if( psEnc->sCmn.LBRR_enabled ) {\r
-        /* Control LBRR */\r
-\r
-        /* Usage Control based on sensitivity and packet loss caracteristics */\r
-        /* For now only enable adding to next for active frames. Make more complex later */\r
-        LBRR_usage = SKP_SILK_NO_LBRR;\r
-        if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { // nb! maybe multiply loss prob and speech activity \r
-            LBRR_usage = SKP_SILK_ADD_LBRR_TO_PLUS1;\r
-        }\r
-        psEncCtrlC->LBRR_usage = LBRR_usage;\r
-    } else {\r
-        psEncCtrlC->LBRR_usage = SKP_SILK_NO_LBRR;\r
-    }\r
-}\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_resamplers_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */\r
-    SKP_int                         fs_kHz              /* I    Internal sampling rate (kHz)            */\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
-\r
-            SKP_int32 nSamples_temp = SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + LA_SHAPE_MS * psEnc->sCmn.fs_kHz;\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
-\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, 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
-\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
-\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, SKP_SMULBB( fs_kHz, 1000 ) );\r
-\r
-            } else {\r
-                /* Copy data */\r
-                SKP_memcpy( x_buf_API_fs_Hz, psEnc->x_buf, 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
-            }\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_packetsize_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */\r
-    SKP_int                         PacketSize_ms       /* I    Packet length (ms)                      */\r
-)\r
-{\r
-    SKP_int ret = SKP_SILK_NO_ERROR;\r
-\r
-    /* Set packet size */\r
-    if( ( PacketSize_ms !=  20 ) && \r
-        ( PacketSize_ms !=  40 ) && \r
-        ( PacketSize_ms !=  60 ) && \r
-        ( PacketSize_ms !=  80 ) && \r
-        ( PacketSize_ms != 100 ) ) {\r
-        ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED;\r
-    } else {\r
-        if( PacketSize_ms != psEnc->sCmn.PacketSize_ms ) {\r
-            psEnc->sCmn.PacketSize_ms = PacketSize_ms;\r
-\r
-            /* Packet length changes. Reset LBRR buffer */\r
-            SKP_Silk_LBRR_reset( &psEnc->sCmn );\r
-        }\r
-    }\r
-    return(ret);\r
-}\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_fs_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */\r
-    SKP_int                         fs_kHz              /* I    Internal sampling rate (kHz)            */\r
-)\r
-{\r
-    SKP_int ret = SKP_SILK_NO_ERROR;\r
-\r
-    /* Set internal sampling frequency */\r
-    if( psEnc->sCmn.fs_kHz != fs_kHz ) {\r
-        /* reset part of the state */\r
-        SKP_memset( &psEnc->sShape,          0,                            sizeof( SKP_Silk_shape_state_FIX ) );\r
-        SKP_memset( &psEnc->sPrefilt,        0,                            sizeof( SKP_Silk_prefilter_state_FIX ) );\r
-        SKP_memset( &psEnc->sNSQ,            0,                            sizeof( SKP_Silk_nsq_state ) );\r
-        SKP_memset( &psEnc->sPred,           0,                            sizeof( SKP_Silk_predict_state_FIX ) );\r
-        SKP_memset( psEnc->sNSQ.xq,          0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) );\r
-        SKP_memset( psEnc->sNSQ_LBRR.xq,     0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) );\r
-        SKP_memset( psEnc->sCmn.LBRR_buffer, 0,           MAX_LBRR_DELAY * sizeof( SKP_SILK_LBRR_struct ) );\r
-#if SWITCH_TRANSITION_FILTERING\r
-        SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) );\r
-        if( psEnc->sCmn.sLP.mode == 1 ) {\r
-            /* Begin transition phase */\r
-            psEnc->sCmn.sLP.transition_frame_no = 1;\r
-        } else {\r
-            /* End transition phase */\r
-            psEnc->sCmn.sLP.transition_frame_no = 0;\r
-        }\r
-#endif\r
-        psEnc->sCmn.inputBufIx          = 0;\r
-        psEnc->sCmn.nFramesInPayloadBuf = 0;\r
-        psEnc->sCmn.nBytesInPayloadBuf  = 0;\r
-        psEnc->sCmn.oldest_LBRR_idx     = 0;\r
-        psEnc->sCmn.TargetRate_bps      = 0; /* Ensures that psEnc->SNR_dB is recomputed */\r
-\r
-        SKP_memset( psEnc->sPred.prev_NLSFq_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );\r
-\r
-        /* Initialize non-zero parameters */\r
-        psEnc->sCmn.prevLag                 = 100;\r
-        psEnc->sCmn.prev_sigtype            = SIG_TYPE_UNVOICED;\r
-        psEnc->sCmn.first_frame_after_reset = 1;\r
-        psEnc->sPrefilt.lagPrev             = 100;\r
-        psEnc->sShape.LastGainIndex         = 1;\r
-        psEnc->sNSQ.lagPrev                 = 100;\r
-        psEnc->sNSQ.prev_inv_gain_Q16       = 65536;\r
-        psEnc->sNSQ_LBRR.prev_inv_gain_Q16  = 65536;\r
-\r
-        psEnc->sCmn.fs_kHz = fs_kHz;\r
-        if( psEnc->sCmn.fs_kHz == 8 ) {\r
-            psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER;\r
-            psEnc->sCmn.psNLSF_CB[ 0 ]  = &SKP_Silk_NLSF_CB0_10;\r
-            psEnc->sCmn.psNLSF_CB[ 1 ]  = &SKP_Silk_NLSF_CB1_10;\r
-        } else {\r
-            psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER;\r
-            psEnc->sCmn.psNLSF_CB[ 0 ]  = &SKP_Silk_NLSF_CB0_16;\r
-            psEnc->sCmn.psNLSF_CB[ 1 ]  = &SKP_Silk_NLSF_CB1_16;\r
-        }\r
-        psEnc->sCmn.frame_length   = SKP_SMULBB( FRAME_LENGTH_MS, fs_kHz );\r
-        psEnc->sCmn.subfr_length   = SKP_DIV32_16( psEnc->sCmn.frame_length, NB_SUBFR );\r
-        psEnc->sCmn.la_pitch       = SKP_SMULBB( LA_PITCH_MS, fs_kHz );\r
-        psEnc->sPred.min_pitch_lag = SKP_SMULBB(  3, fs_kHz );\r
-        psEnc->sPred.max_pitch_lag = SKP_SMULBB( 18, fs_kHz );\r
-        psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );\r
-        if( psEnc->sCmn.fs_kHz == 24 ) {\r
-            psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_SWB, 8 );\r
-            psEnc->sCmn.bitrate_threshold_up   = SKP_int32_MAX;\r
-            psEnc->sCmn.bitrate_threshold_down = SWB2WB_BITRATE_BPS; \r
-        } else if( psEnc->sCmn.fs_kHz == 16 ) {\r
-            psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 8 );\r
-            psEnc->sCmn.bitrate_threshold_up   = WB2SWB_BITRATE_BPS;\r
-            psEnc->sCmn.bitrate_threshold_down = WB2MB_BITRATE_BPS; \r
-        } else if( psEnc->sCmn.fs_kHz == 12 ) {\r
-            psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 8 );\r
-            psEnc->sCmn.bitrate_threshold_up   = MB2WB_BITRATE_BPS;\r
-            psEnc->sCmn.bitrate_threshold_down = MB2NB_BITRATE_BPS;\r
-        } else {\r
-            psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 8 );\r
-            psEnc->sCmn.bitrate_threshold_up   = NB2MB_BITRATE_BPS;\r
-            psEnc->sCmn.bitrate_threshold_down = 0;\r
-        }\r
-        psEnc->sCmn.fs_kHz_changed = 1;\r
-\r
-        /* Check that settings are valid */\r
-        SKP_assert( ( psEnc->sCmn.subfr_length * NB_SUBFR ) == psEnc->sCmn.frame_length );\r
-    }\r
-    return( ret );\r
-}\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_rate_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */\r
-    SKP_int                         TargetRate_bps      /* I    Target max bitrate (if SNR_dB == 0)     */\r
-)\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
-    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
-            rateTable = TargetRate_table_SWB;\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
-    }\r
-    return( ret );\r
-}\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_LBRR_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc              /* I/O  Pointer to Silk encoder state FIX       */\r
-)\r
-{\r
-    SKP_int   ret = SKP_SILK_NO_ERROR;\r
-#if USE_LBRR\r
-    SKP_int32 LBRRRate_thres_bps;\r
-\r
-    if( psEnc->sCmn.useInBandFEC < 0 || psEnc->sCmn.useInBandFEC > 1 ) {\r
-        ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING;\r
-    }\r
-    \r
-    psEnc->sCmn.LBRR_enabled = psEnc->sCmn.useInBandFEC;\r
-    if( psEnc->sCmn.fs_kHz == 8 ) {\r
-        LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 9000;\r
-    } else if( psEnc->sCmn.fs_kHz == 12 ) {\r
-        LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 6000;;\r
-    } else if( psEnc->sCmn.fs_kHz == 16 ) {\r
-        LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 3000;\r
-    } else {\r
-        LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS;\r
-    }\r
-\r
-    if( psEnc->sCmn.TargetRate_bps >= LBRRRate_thres_bps ) {\r
-        /* Set gain increase / rate reduction for LBRR usage */\r
-        /* Coarsely tuned with PESQ for now. */\r
-        /* Linear regression coefs G = 8 - 0.5 * loss */\r
-        /* Meaning that at 16% loss main rate and redundant rate is the same, -> G = 0 */\r
-        psEnc->sCmn.LBRR_GainIncreases = SKP_max_int( 8 - SKP_RSHIFT( psEnc->sCmn.PacketLoss_perc, 1 ), 0 );\r
-\r
-        /* Set main stream rate compensation */\r
-        if( psEnc->sCmn.LBRR_enabled && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) {\r
-            /* Tuned to give approx same mean / weighted bitrate as no inband FEC */\r
-            psEnc->inBandFEC_SNR_comp_Q8 = SKP_FIX_CONST( 6.0f, 8 ) - SKP_LSHIFT( psEnc->sCmn.LBRR_GainIncreases, 7 );\r
-        } else {\r
-            psEnc->inBandFEC_SNR_comp_Q8 = 0;\r
-            psEnc->sCmn.LBRR_enabled     = 0;\r
-        }\r
-    } else {\r
-        psEnc->inBandFEC_SNR_comp_Q8     = 0;\r
-        psEnc->sCmn.LBRR_enabled         = 0;\r
-    }\r
-#else\r
-    if( INBandFEC_enabled != 0 ) {\r
-        ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING;\r
-    }\r
-    psEnc->sCmn.LBRR_enabled = 0;\r
-#endif\r
-    return ret;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_setup_complexity.h"
+
+SKP_INLINE SKP_int SKP_Silk_setup_resamplers_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */
+    SKP_int                         fs_kHz              /* I    Internal sampling rate (kHz)            */
+);
+
+SKP_INLINE SKP_int SKP_Silk_setup_packetsize_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */
+    SKP_int                         PacketSize_ms       /* I    Packet length (ms)                      */
+);
+
+SKP_INLINE SKP_int SKP_Silk_setup_fs_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */
+    SKP_int                         fs_kHz              /* I    Internal sampling rate (kHz)            */
+);
+
+SKP_INLINE SKP_int SKP_Silk_setup_rate_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */
+    SKP_int                         TargetRate_bps      /* I    Target max bitrate (if SNR_dB == 0)     */
+);
+
+SKP_INLINE SKP_int SKP_Silk_setup_LBRR_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc              /* I/O  Pointer to Silk encoder state FIX       */
+);
+
+/* Control encoder */
+SKP_int SKP_Silk_control_encoder_FIX( 
+    SKP_Silk_encoder_state_FIX  *psEnc,                 /* I/O  Pointer to Silk encoder state           */
+    const SKP_int               PacketSize_ms,          /* I    Packet length (ms)                      */
+    const SKP_int32             TargetRate_bps,         /* I    Target max bitrate (bps)                */
+    const SKP_int               PacketLoss_perc,        /* I    Packet loss rate (in percent)           */
+    const SKP_int               DTX_enabled,            /* I    Enable / disable DTX                    */
+    const SKP_int               Complexity              /* I    Complexity (0->low; 1->medium; 2->high) */
+)
+{
+    SKP_int   fs_kHz, ret = 0;
+
+    if( psEnc->sCmn.controlled_since_last_payload != 0 ) {
+        if( psEnc->sCmn.API_fs_Hz != psEnc->sCmn.prev_API_fs_Hz && psEnc->sCmn.fs_kHz > 0 ) {
+            /* Change in API sampling rate in the middle of encoding a packet */
+            ret += SKP_Silk_setup_resamplers_FIX( psEnc, psEnc->sCmn.fs_kHz );
+        }
+        return ret;
+    }
+
+    /* Beyond this point we know that there are no previously coded frames in the payload buffer */
+
+    /********************************************/
+    /* Determine internal sampling rate         */
+    /********************************************/
+    fs_kHz = SKP_Silk_control_audio_bandwidth( &psEnc->sCmn, TargetRate_bps );
+
+    /********************************************/
+    /* Prepare resampler and buffered data      */
+    /********************************************/
+    ret += SKP_Silk_setup_resamplers_FIX( psEnc, fs_kHz );
+
+    /********************************************/
+    /* Set packet size                          */
+    /********************************************/
+    ret += SKP_Silk_setup_packetsize_FIX( psEnc, PacketSize_ms );
+
+    /********************************************/
+    /* Set internal sampling frequency          */
+    /********************************************/
+    ret += SKP_Silk_setup_fs_FIX( psEnc, fs_kHz );
+
+    /********************************************/
+    /* Set encoding complexity                  */
+    /********************************************/
+    ret += SKP_Silk_setup_complexity( &psEnc->sCmn, Complexity );
+
+    /********************************************/
+    /* Set bitrate/coding quality               */
+    /********************************************/
+    ret += SKP_Silk_setup_rate_FIX( psEnc, TargetRate_bps );
+
+    /********************************************/
+    /* Set packet loss rate measured by farend  */
+    /********************************************/
+    if( ( PacketLoss_perc < 0 ) || ( PacketLoss_perc > 100 ) ) {
+        ret = SKP_SILK_ENC_INVALID_LOSS_RATE;
+    }
+    psEnc->sCmn.PacketLoss_perc = PacketLoss_perc;
+
+    /********************************************/
+    /* Set LBRR usage                           */
+    /********************************************/
+    ret += SKP_Silk_setup_LBRR_FIX( psEnc );
+
+    /********************************************/
+    /* Set DTX mode                             */
+    /********************************************/
+    if( DTX_enabled < 0 || DTX_enabled > 1 ) {
+        ret = SKP_SILK_ENC_INVALID_DTX_SETTING;
+    }
+    psEnc->sCmn.useDTX = DTX_enabled;
+    psEnc->sCmn.controlled_since_last_payload = 1;
+
+    return ret;
+}
+
+/* Control low bitrate redundancy usage */
+void SKP_Silk_LBRR_ctrl_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,     /* I    Encoder state FIX                           */
+    SKP_Silk_encoder_control        *psEncCtrlC /* I/O  Encoder control                             */
+)
+{
+    SKP_int LBRR_usage;
+
+    if( psEnc->sCmn.LBRR_enabled ) {
+        /* Control LBRR */
+
+        /* Usage Control based on sensitivity and packet loss caracteristics */
+        /* For now only enable adding to next for active frames. Make more complex later */
+        LBRR_usage = SKP_SILK_NO_LBRR;
+        if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { // nb! maybe multiply loss prob and speech activity 
+            LBRR_usage = SKP_SILK_ADD_LBRR_TO_PLUS1;
+        }
+        psEncCtrlC->LBRR_usage = LBRR_usage;
+    } else {
+        psEncCtrlC->LBRR_usage = SKP_SILK_NO_LBRR;
+    }
+}
+
+SKP_INLINE SKP_int SKP_Silk_setup_resamplers_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */
+    SKP_int                         fs_kHz              /* I    Internal sampling rate (kHz)            */
+)
+{
+    SKP_int ret = SKP_SILK_NO_ERROR;
+    
+    if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != psEnc->sCmn.API_fs_Hz ) {
+
+        if( psEnc->sCmn.fs_kHz == 0 ) {
+            /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */
+            ret += SKP_Silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, fs_kHz * 1000 );
+        } else {
+            /* Allocate space for worst case temporary upsampling, 8 to 48 kHz, so a factor 6 */
+            SKP_int16 x_buf_API_fs_Hz[ ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * ( MAX_API_FS_KHZ / 8 ) ];
+
+            SKP_int32 nSamples_temp = SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + LA_SHAPE_MS * psEnc->sCmn.fs_kHz;
+
+            if( SKP_SMULBB( fs_kHz, 1000 ) < psEnc->sCmn.API_fs_Hz && psEnc->sCmn.fs_kHz != 0 ) {
+                /* Resample buffered data in x_buf to API_fs_Hz */
+
+                SKP_Silk_resampler_state_struct  temp_resampler_state;
+
+                /* Initialize resampler for temporary resampling of x_buf data to API_fs_Hz */
+                ret += SKP_Silk_resampler_init( &temp_resampler_state, SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ), psEnc->sCmn.API_fs_Hz );
+
+                /* Temporary resampling of x_buf data to API_fs_Hz */
+                ret += SKP_Silk_resampler( &temp_resampler_state, x_buf_API_fs_Hz, psEnc->x_buf, nSamples_temp );
+
+                /* Calculate number of samples that has been temporarily upsampled */
+                nSamples_temp = SKP_DIV32_16( nSamples_temp * psEnc->sCmn.API_fs_Hz, SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ) );
+
+                /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */
+                ret += SKP_Silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, SKP_SMULBB( fs_kHz, 1000 ) );
+
+            } else {
+                /* Copy data */
+                SKP_memcpy( x_buf_API_fs_Hz, psEnc->x_buf, nSamples_temp * sizeof( SKP_int16 ) );
+            }
+
+            if( 1000 * fs_kHz != psEnc->sCmn.API_fs_Hz ) {
+                /* Correct resampler state (unless resampling by a factor 1) by resampling buffered data from API_fs_Hz to fs_kHz */
+                ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, psEnc->x_buf, x_buf_API_fs_Hz, nSamples_temp );
+            }
+        }
+    }
+
+    psEnc->sCmn.prev_API_fs_Hz = psEnc->sCmn.API_fs_Hz;
+
+    return(ret);
+}
+
+SKP_INLINE SKP_int SKP_Silk_setup_packetsize_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */
+    SKP_int                         PacketSize_ms       /* I    Packet length (ms)                      */
+)
+{
+    SKP_int ret = SKP_SILK_NO_ERROR;
+
+    /* Set packet size */
+    if( ( PacketSize_ms !=  20 ) && 
+        ( PacketSize_ms !=  40 ) && 
+        ( PacketSize_ms !=  60 ) && 
+        ( PacketSize_ms !=  80 ) && 
+        ( PacketSize_ms != 100 ) ) {
+        ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED;
+    } else {
+        if( PacketSize_ms != psEnc->sCmn.PacketSize_ms ) {
+            psEnc->sCmn.PacketSize_ms = PacketSize_ms;
+
+            /* Packet length changes. Reset LBRR buffer */
+            SKP_Silk_LBRR_reset( &psEnc->sCmn );
+        }
+    }
+    return(ret);
+}
+
+SKP_INLINE SKP_int SKP_Silk_setup_fs_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */
+    SKP_int                         fs_kHz              /* I    Internal sampling rate (kHz)            */
+)
+{
+    SKP_int ret = SKP_SILK_NO_ERROR;
+
+    /* Set internal sampling frequency */
+    if( psEnc->sCmn.fs_kHz != fs_kHz ) {
+        /* reset part of the state */
+        SKP_memset( &psEnc->sShape,          0,                            sizeof( SKP_Silk_shape_state_FIX ) );
+        SKP_memset( &psEnc->sPrefilt,        0,                            sizeof( SKP_Silk_prefilter_state_FIX ) );
+        SKP_memset( &psEnc->sNSQ,            0,                            sizeof( SKP_Silk_nsq_state ) );
+        SKP_memset( &psEnc->sPred,           0,                            sizeof( SKP_Silk_predict_state_FIX ) );
+        SKP_memset( psEnc->sNSQ.xq,          0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) );
+        SKP_memset( psEnc->sNSQ_LBRR.xq,     0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) );
+        SKP_memset( psEnc->sCmn.LBRR_buffer, 0,           MAX_LBRR_DELAY * sizeof( SKP_SILK_LBRR_struct ) );
+#if SWITCH_TRANSITION_FILTERING
+        SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) );
+        if( psEnc->sCmn.sLP.mode == 1 ) {
+            /* Begin transition phase */
+            psEnc->sCmn.sLP.transition_frame_no = 1;
+        } else {
+            /* End transition phase */
+            psEnc->sCmn.sLP.transition_frame_no = 0;
+        }
+#endif
+        psEnc->sCmn.inputBufIx          = 0;
+        psEnc->sCmn.nFramesInPayloadBuf = 0;
+        psEnc->sCmn.nBytesInPayloadBuf  = 0;
+        psEnc->sCmn.oldest_LBRR_idx     = 0;
+        psEnc->sCmn.TargetRate_bps      = 0; /* Ensures that psEnc->SNR_dB is recomputed */
+
+        SKP_memset( psEnc->sPred.prev_NLSFq_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );
+
+        /* Initialize non-zero parameters */
+        psEnc->sCmn.prevLag                 = 100;
+        psEnc->sCmn.prev_sigtype            = SIG_TYPE_UNVOICED;
+        psEnc->sCmn.first_frame_after_reset = 1;
+        psEnc->sPrefilt.lagPrev             = 100;
+        psEnc->sShape.LastGainIndex         = 1;
+        psEnc->sNSQ.lagPrev                 = 100;
+        psEnc->sNSQ.prev_inv_gain_Q16       = 65536;
+        psEnc->sNSQ_LBRR.prev_inv_gain_Q16  = 65536;
+
+        psEnc->sCmn.fs_kHz = fs_kHz;
+        if( psEnc->sCmn.fs_kHz == 8 ) {
+            psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER;
+            psEnc->sCmn.psNLSF_CB[ 0 ]  = &SKP_Silk_NLSF_CB0_10;
+            psEnc->sCmn.psNLSF_CB[ 1 ]  = &SKP_Silk_NLSF_CB1_10;
+        } else {
+            psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER;
+            psEnc->sCmn.psNLSF_CB[ 0 ]  = &SKP_Silk_NLSF_CB0_16;
+            psEnc->sCmn.psNLSF_CB[ 1 ]  = &SKP_Silk_NLSF_CB1_16;
+        }
+        psEnc->sCmn.frame_length   = SKP_SMULBB( FRAME_LENGTH_MS, fs_kHz );
+        psEnc->sCmn.subfr_length   = SKP_DIV32_16( psEnc->sCmn.frame_length, NB_SUBFR );
+        psEnc->sCmn.la_pitch       = SKP_SMULBB( LA_PITCH_MS, fs_kHz );
+        psEnc->sPred.min_pitch_lag = SKP_SMULBB(  3, fs_kHz );
+        psEnc->sPred.max_pitch_lag = SKP_SMULBB( 18, fs_kHz );
+        psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );
+        if( psEnc->sCmn.fs_kHz == 24 ) {
+            psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_SWB, 8 );
+            psEnc->sCmn.bitrate_threshold_up   = SKP_int32_MAX;
+            psEnc->sCmn.bitrate_threshold_down = SWB2WB_BITRATE_BPS; 
+        } else if( psEnc->sCmn.fs_kHz == 16 ) {
+            psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 8 );
+            psEnc->sCmn.bitrate_threshold_up   = WB2SWB_BITRATE_BPS;
+            psEnc->sCmn.bitrate_threshold_down = WB2MB_BITRATE_BPS; 
+        } else if( psEnc->sCmn.fs_kHz == 12 ) {
+            psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 8 );
+            psEnc->sCmn.bitrate_threshold_up   = MB2WB_BITRATE_BPS;
+            psEnc->sCmn.bitrate_threshold_down = MB2NB_BITRATE_BPS;
+        } else {
+            psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 8 );
+            psEnc->sCmn.bitrate_threshold_up   = NB2MB_BITRATE_BPS;
+            psEnc->sCmn.bitrate_threshold_down = 0;
+        }
+        psEnc->sCmn.fs_kHz_changed = 1;
+
+        /* Check that settings are valid */
+        SKP_assert( ( psEnc->sCmn.subfr_length * NB_SUBFR ) == psEnc->sCmn.frame_length );
+    }
+    return( ret );
+}
+
+SKP_INLINE SKP_int SKP_Silk_setup_rate_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state FIX       */
+    SKP_int                         TargetRate_bps      /* I    Target max bitrate (if SNR_dB == 0)     */
+)
+{
+    SKP_int k, ret = SKP_SILK_NO_ERROR;
+    SKP_int32 frac_Q6;
+    const SKP_int32 *rateTable;
+
+    /* Set bitrate/coding quality */
+    if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) {
+        psEnc->sCmn.TargetRate_bps = TargetRate_bps;
+
+        /* If new TargetRate_bps, translate to SNR_dB value */
+        if( psEnc->sCmn.fs_kHz == 8 ) {
+            rateTable = TargetRate_table_NB;
+        } else if( psEnc->sCmn.fs_kHz == 12 ) {
+            rateTable = TargetRate_table_MB;
+        } else if( psEnc->sCmn.fs_kHz == 16 ) {
+            rateTable = TargetRate_table_WB;
+        } else {
+            rateTable = TargetRate_table_SWB;
+        }
+        for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) {
+            /* Find bitrate interval in table and interpolate */
+            if( TargetRate_bps < rateTable[ k ] ) {
+                frac_Q6 = SKP_DIV32( SKP_LSHIFT( TargetRate_bps - rateTable[ k - 1 ], 6 ), 
+                                                 rateTable[ k ] - rateTable[ k - 1 ] );
+                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 ] );
+                break;
+            }
+        }
+    }
+    return( ret );
+}
+
+SKP_INLINE SKP_int SKP_Silk_setup_LBRR_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc              /* I/O  Pointer to Silk encoder state FIX       */
+)
+{
+    SKP_int   ret = SKP_SILK_NO_ERROR;
+#if USE_LBRR
+    SKP_int32 LBRRRate_thres_bps;
+
+    if( psEnc->sCmn.useInBandFEC < 0 || psEnc->sCmn.useInBandFEC > 1 ) {
+        ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING;
+    }
+    
+    psEnc->sCmn.LBRR_enabled = psEnc->sCmn.useInBandFEC;
+    if( psEnc->sCmn.fs_kHz == 8 ) {
+        LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 9000;
+    } else if( psEnc->sCmn.fs_kHz == 12 ) {
+        LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 6000;;
+    } else if( psEnc->sCmn.fs_kHz == 16 ) {
+        LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 3000;
+    } else {
+        LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS;
+    }
+
+    if( psEnc->sCmn.TargetRate_bps >= LBRRRate_thres_bps ) {
+        /* Set gain increase / rate reduction for LBRR usage */
+        /* Coarsely tuned with PESQ for now. */
+        /* Linear regression coefs G = 8 - 0.5 * loss */
+        /* Meaning that at 16% loss main rate and redundant rate is the same, -> G = 0 */
+        psEnc->sCmn.LBRR_GainIncreases = SKP_max_int( 8 - SKP_RSHIFT( psEnc->sCmn.PacketLoss_perc, 1 ), 0 );
+
+        /* Set main stream rate compensation */
+        if( psEnc->sCmn.LBRR_enabled && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) {
+            /* Tuned to give approx same mean / weighted bitrate as no inband FEC */
+            psEnc->inBandFEC_SNR_comp_Q8 = SKP_FIX_CONST( 6.0f, 8 ) - SKP_LSHIFT( psEnc->sCmn.LBRR_GainIncreases, 7 );
+        } else {
+            psEnc->inBandFEC_SNR_comp_Q8 = 0;
+            psEnc->sCmn.LBRR_enabled     = 0;
+        }
+    } else {
+        psEnc->inBandFEC_SNR_comp_Q8     = 0;
+        psEnc->sCmn.LBRR_enabled         = 0;
+    }
+#else
+    if( INBandFEC_enabled != 0 ) {
+        ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING;
+    }
+    psEnc->sCmn.LBRR_enabled = 0;
+#endif
+    return ret;
+}
index 240270c1f28c880c7e61cd67a989c250ea859a71..c359061602b7d30388abc4ebf1d27baa612da51a 100644 (file)
-/***********************************************************************\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
- * Correlation Matrix Computations for LS estimate. \r
- **********************************************************************/\r
-\r
-#include "SKP_Silk_main_FIX.h"\r
-\r
-/* Calculates correlation vector X'*t */\r
-void SKP_Silk_corrVector_FIX(\r
-    const SKP_int16                 *x,         /* I    x vector [L + order - 1] used to form data matrix X */\r
-    const SKP_int16                 *t,         /* I    target vector [L]                                   */\r
-    const SKP_int                   L,          /* I    Length of vectors                                   */\r
-    const SKP_int                   order,      /* I    Max lag for correlation                             */\r
-    SKP_int32                       *Xt,        /* O    Pointer to X'*t correlation vector [order]          */\r
-    const SKP_int                   rshifts     /* I    Right shifts of correlations                        */\r
-)\r
-{\r
-    SKP_int         lag, i;\r
-    const SKP_int16 *ptr1, *ptr2;\r
-    SKP_int32       inner_prod;\r
-\r
-    ptr1 = &x[ order - 1 ]; /* Points to first sample of column 0 of X: X[:,0] */\r
-    ptr2 = t;\r
-    /* Calculate X'*t */\r
-    if( rshifts > 0 ) {\r
-        /* Right shifting used */\r
-        for( lag = 0; lag < order; lag++ ) {\r
-            inner_prod = 0;\r
-            for( i = 0; i < L; i++ ) {\r
-                inner_prod += SKP_RSHIFT32( SKP_SMULBB( ptr1[ i ], ptr2[i] ), rshifts );\r
-            }\r
-            Xt[ lag ] = inner_prod; /* X[:,lag]'*t */\r
-            ptr1--; /* Go to next column of X */\r
-        }\r
-    } else {\r
-        SKP_assert( rshifts == 0 );\r
-        for( lag = 0; lag < order; lag++ ) {\r
-            Xt[ lag ] = SKP_Silk_inner_prod_aligned( ptr1, ptr2, L ); /* X[:,lag]'*t */\r
-            ptr1--; /* Go to next column of X */\r
-        }\r
-    }\r
-}\r
-\r
-/* Calculates correlation matrix X'*X */\r
-void SKP_Silk_corrMatrix_FIX(\r
-    const SKP_int16                 *x,         /* I    x vector [L + order - 1] used to form data matrix X */\r
-    const SKP_int                   L,          /* I    Length of vectors                                   */\r
-    const SKP_int                   order,      /* I    Max lag for correlation                             */\r
-    const SKP_int                   head_room,  /* I    Desired headroom                                    */\r
-    SKP_int32                       *XX,        /* O    Pointer to X'*X correlation matrix [ order x order ]*/\r
-    SKP_int                         *rshifts    /* I/O  Right shifts of correlations                        */\r
-)\r
-{\r
-    SKP_int         i, j, lag, rshifts_local, head_room_rshifts;\r
-    SKP_int32       energy;\r
-    const SKP_int16 *ptr1, *ptr2;\r
-\r
-    /* Calculate energy to find shift used to fit in 32 bits */\r
-    SKP_Silk_sum_sqr_shift( &energy, &rshifts_local, x, L + order - 1 );\r
-\r
-    /* Add shifts to get the desired head room */\r
-    head_room_rshifts = SKP_max( head_room - SKP_Silk_CLZ32( energy ), 0 );\r
-    \r
-    energy = SKP_RSHIFT32( energy, head_room_rshifts );\r
-    rshifts_local += head_room_rshifts;\r
-\r
-    /* Calculate energy of first column (0) of X: X[:,0]'*X[:,0] */\r
-    /* Remove contribution of first order - 1 samples */\r
-    for( i = 0; i < order - 1; i++ ) {\r
-        energy -= SKP_RSHIFT32( SKP_SMULBB( x[ i ], x[ i ] ), rshifts_local );\r
-    }\r
-    if( rshifts_local < *rshifts ) {\r
-        /* Adjust energy */\r
-        energy = SKP_RSHIFT32( energy, *rshifts - rshifts_local );\r
-        rshifts_local = *rshifts;\r
-    }\r
-\r
-    /* Calculate energy of remaining columns of X: X[:,j]'*X[:,j] */\r
-    /* Fill out the diagonal of the correlation matrix */\r
-    matrix_ptr( XX, 0, 0, order ) = energy;\r
-    ptr1 = &x[ order - 1 ]; /* First sample of column 0 of X */\r
-    for( j = 1; j < order; j++ ) {\r
-        energy = SKP_SUB32( energy, SKP_RSHIFT32( SKP_SMULBB( ptr1[ L - j ], ptr1[ L - j ] ), rshifts_local ) );\r
-        energy = SKP_ADD32( energy, SKP_RSHIFT32( SKP_SMULBB( ptr1[ -j ], ptr1[ -j ] ), rshifts_local ) );\r
-        matrix_ptr( XX, j, j, order ) = energy;\r
-    }\r
-\r
-    ptr2 = &x[ order - 2 ]; /* First sample of column 1 of X */\r
-    /* Calculate the remaining elements of the correlation matrix */\r
-    if( rshifts_local > 0 ) {\r
-        /* Right shifting used */\r
-        for( lag = 1; lag < order; lag++ ) {\r
-            /* Inner product of column 0 and column lag: X[:,0]'*X[:,lag] */\r
-            energy = 0;\r
-            for( i = 0; i < L; i++ ) {\r
-                energy += SKP_RSHIFT32( SKP_SMULBB( ptr1[ i ], ptr2[i] ), rshifts_local );\r
-            }\r
-            /* Calculate remaining off diagonal: X[:,j]'*X[:,j + lag] */\r
-            matrix_ptr( XX, lag, 0, order ) = energy;\r
-            matrix_ptr( XX, 0, lag, order ) = energy;\r
-            for( j = 1; j < ( order - lag ); j++ ) {\r
-                energy = SKP_SUB32( energy, SKP_RSHIFT32( SKP_SMULBB( ptr1[ L - j ], ptr2[ L - j ] ), rshifts_local ) );\r
-                energy = SKP_ADD32( energy, SKP_RSHIFT32( SKP_SMULBB( ptr1[ -j ], ptr2[ -j ] ), rshifts_local ) );\r
-                matrix_ptr( XX, lag + j, j, order ) = energy;\r
-                matrix_ptr( XX, j, lag + j, order ) = energy;\r
-            }\r
-            ptr2--; /* Update pointer to first sample of next column (lag) in X */\r
-        }\r
-    } else {\r
-        for( lag = 1; lag < order; lag++ ) {\r
-            /* Inner product of column 0 and column lag: X[:,0]'*X[:,lag] */\r
-            energy = SKP_Silk_inner_prod_aligned( ptr1, ptr2, L );\r
-            matrix_ptr( XX, lag, 0, order ) = energy;\r
-            matrix_ptr( XX, 0, lag, order ) = energy;\r
-            /* Calculate remaining off diagonal: X[:,j]'*X[:,j + lag] */\r
-            for( j = 1; j < ( order - lag ); j++ ) {\r
-                energy = SKP_SUB32( energy, SKP_SMULBB( ptr1[ L - j ], ptr2[ L - j ] ) );\r
-                energy = SKP_SMLABB( energy, ptr1[ -j ], ptr2[ -j ] );\r
-                matrix_ptr( XX, lag + j, j, order ) = energy;\r
-                matrix_ptr( XX, j, lag + j, order ) = energy;\r
-            }\r
-            ptr2--;/* Update pointer to first sample of next column (lag) in X */\r
-        }\r
-    }\r
-    *rshifts = rshifts_local;\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/**********************************************************************
+ * Correlation Matrix Computations for LS estimate. 
+ **********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+/* Calculates correlation vector X'*t */
+void SKP_Silk_corrVector_FIX(
+    const SKP_int16                 *x,         /* I    x vector [L + order - 1] used to form data matrix X */
+    const SKP_int16                 *t,         /* I    target vector [L]                                   */
+    const SKP_int                   L,          /* I    Length of vectors                                   */
+    const SKP_int                   order,      /* I    Max lag for correlation                             */
+    SKP_int32                       *Xt,        /* O    Pointer to X'*t correlation vector [order]          */
+    const SKP_int                   rshifts     /* I    Right shifts of correlations                        */
+)
+{
+    SKP_int         lag, i;
+    const SKP_int16 *ptr1, *ptr2;
+    SKP_int32       inner_prod;
+
+    ptr1 = &x[ order - 1 ]; /* Points to first sample of column 0 of X: X[:,0] */
+    ptr2 = t;
+    /* Calculate X'*t */
+    if( rshifts > 0 ) {
+        /* Right shifting used */
+        for( lag = 0; lag < order; lag++ ) {
+            inner_prod = 0;
+            for( i = 0; i < L; i++ ) {
+                inner_prod += SKP_RSHIFT32( SKP_SMULBB( ptr1[ i ], ptr2[i] ), rshifts );
+            }
+            Xt[ lag ] = inner_prod; /* X[:,lag]'*t */
+            ptr1--; /* Go to next column of X */
+        }
+    } else {
+        SKP_assert( rshifts == 0 );
+        for( lag = 0; lag < order; lag++ ) {
+            Xt[ lag ] = SKP_Silk_inner_prod_aligned( ptr1, ptr2, L ); /* X[:,lag]'*t */
+            ptr1--; /* Go to next column of X */
+        }
+    }
+}
+
+/* Calculates correlation matrix X'*X */
+void SKP_Silk_corrMatrix_FIX(
+    const SKP_int16                 *x,         /* I    x vector [L + order - 1] used to form data matrix X */
+    const SKP_int                   L,          /* I    Length of vectors                                   */
+    const SKP_int                   order,      /* I    Max lag for correlation                             */
+    const SKP_int                   head_room,  /* I    Desired headroom                                    */
+    SKP_int32                       *XX,        /* O    Pointer to X'*X correlation matrix [ order x order ]*/
+    SKP_int                         *rshifts    /* I/O  Right shifts of correlations                        */
+)
+{
+    SKP_int         i, j, lag, rshifts_local, head_room_rshifts;
+    SKP_int32       energy;
+    const SKP_int16 *ptr1, *ptr2;
+
+    /* Calculate energy to find shift used to fit in 32 bits */
+    SKP_Silk_sum_sqr_shift( &energy, &rshifts_local, x, L + order - 1 );
+
+    /* Add shifts to get the desired head room */
+    head_room_rshifts = SKP_max( head_room - SKP_Silk_CLZ32( energy ), 0 );
+    
+    energy = SKP_RSHIFT32( energy, head_room_rshifts );
+    rshifts_local += head_room_rshifts;
+
+    /* Calculate energy of first column (0) of X: X[:,0]'*X[:,0] */
+    /* Remove contribution of first order - 1 samples */
+    for( i = 0; i < order - 1; i++ ) {
+        energy -= SKP_RSHIFT32( SKP_SMULBB( x[ i ], x[ i ] ), rshifts_local );
+    }
+    if( rshifts_local < *rshifts ) {
+        /* Adjust energy */
+        energy = SKP_RSHIFT32( energy, *rshifts - rshifts_local );
+        rshifts_local = *rshifts;
+    }
+
+    /* Calculate energy of remaining columns of X: X[:,j]'*X[:,j] */
+    /* Fill out the diagonal of the correlation matrix */
+    matrix_ptr( XX, 0, 0, order ) = energy;
+    ptr1 = &x[ order - 1 ]; /* First sample of column 0 of X */
+    for( j = 1; j < order; j++ ) {
+        energy = SKP_SUB32( energy, SKP_RSHIFT32( SKP_SMULBB( ptr1[ L - j ], ptr1[ L - j ] ), rshifts_local ) );
+        energy = SKP_ADD32( energy, SKP_RSHIFT32( SKP_SMULBB( ptr1[ -j ], ptr1[ -j ] ), rshifts_local ) );
+        matrix_ptr( XX, j, j, order ) = energy;
+    }
+
+    ptr2 = &x[ order - 2 ]; /* First sample of column 1 of X */
+    /* Calculate the remaining elements of the correlation matrix */
+    if( rshifts_local > 0 ) {
+        /* Right shifting used */
+        for( lag = 1; lag < order; lag++ ) {
+            /* Inner product of column 0 and column lag: X[:,0]'*X[:,lag] */
+            energy = 0;
+            for( i = 0; i < L; i++ ) {
+                energy += SKP_RSHIFT32( SKP_SMULBB( ptr1[ i ], ptr2[i] ), rshifts_local );
+            }
+            /* Calculate remaining off diagonal: X[:,j]'*X[:,j + lag] */
+            matrix_ptr( XX, lag, 0, order ) = energy;
+            matrix_ptr( XX, 0, lag, order ) = energy;
+            for( j = 1; j < ( order - lag ); j++ ) {
+                energy = SKP_SUB32( energy, SKP_RSHIFT32( SKP_SMULBB( ptr1[ L - j ], ptr2[ L - j ] ), rshifts_local ) );
+                energy = SKP_ADD32( energy, SKP_RSHIFT32( SKP_SMULBB( ptr1[ -j ], ptr2[ -j ] ), rshifts_local ) );
+                matrix_ptr( XX, lag + j, j, order ) = energy;
+                matrix_ptr( XX, j, lag + j, order ) = energy;
+            }
+            ptr2--; /* Update pointer to first sample of next column (lag) in X */
+        }
+    } else {
+        for( lag = 1; lag < order; lag++ ) {
+            /* Inner product of column 0 and column lag: X[:,0]'*X[:,lag] */
+            energy = SKP_Silk_inner_prod_aligned( ptr1, ptr2, L );
+            matrix_ptr( XX, lag, 0, order ) = energy;
+            matrix_ptr( XX, 0, lag, order ) = energy;
+            /* Calculate remaining off diagonal: X[:,j]'*X[:,j + lag] */
+            for( j = 1; j < ( order - lag ); j++ ) {
+                energy = SKP_SUB32( energy, SKP_SMULBB( ptr1[ L - j ], ptr2[ L - j ] ) );
+                energy = SKP_SMLABB( energy, ptr1[ -j ], ptr2[ -j ] );
+                matrix_ptr( XX, lag + j, j, order ) = energy;
+                matrix_ptr( XX, j, lag + j, order ) = energy;
+            }
+            ptr2--;/* Update pointer to first sample of next column (lag) in X */
+        }
+    }
+    *rshifts = rshifts_local;
+}
+
index e8380066572552a73c851c21df18a3547179b33d..5d2bd3f70192dce79c69a78a8d720f3e83ad333e 100644 (file)
@@ -1,53 +1,53 @@
-/***********************************************************************\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
-/************************/\r
-/* Init Decoder State   */\r
-/************************/\r
-SKP_int SKP_Silk_init_decoder(\r
-    SKP_Silk_decoder_state      *psDec              /* I/O  Decoder state pointer                       */\r
-)\r
-{\r
-    SKP_memset( psDec, 0, sizeof( SKP_Silk_decoder_state ) );\r
-    /* Set sampling rate to 24 kHz, and init non-zero values */\r
-    SKP_Silk_decoder_set_fs( psDec, 24 );\r
-\r
-    /* Used to deactivate e.g. LSF interpolation and fluctuation reduction */\r
-    psDec->first_frame_after_reset = 1;\r
-    psDec->prev_inv_gain_Q16 = 65536;\r
-\r
-    /* Reset CNG state */\r
-    SKP_Silk_CNG_Reset( psDec );\r
-\r
-    SKP_Silk_PLC_Reset( psDec );\r
-    \r
-    return(0);\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+
+/************************/
+/* Init Decoder State   */
+/************************/
+SKP_int SKP_Silk_init_decoder(
+    SKP_Silk_decoder_state      *psDec              /* I/O  Decoder state pointer                       */
+)
+{
+    SKP_memset( psDec, 0, sizeof( SKP_Silk_decoder_state ) );
+    /* Set sampling rate to 24 kHz, and init non-zero values */
+    SKP_Silk_decoder_set_fs( psDec, 24 );
+
+    /* Used to deactivate e.g. LSF interpolation and fluctuation reduction */
+    psDec->first_frame_after_reset = 1;
+    psDec->prev_inv_gain_Q16 = 65536;
+
+    /* Reset CNG state */
+    SKP_Silk_CNG_Reset( psDec );
+
+    SKP_Silk_PLC_Reset( psDec );
+    
+    return(0);
+}
+
index 35090d427d1e4ad98a6fe6f629d6642b06ceb240..31d31526d6ab9b3b22237f7983ece9078bb12a14 100644 (file)
-/***********************************************************************\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_SDK_API.h"\r
-#include "SKP_Silk_main.h"\r
-\r
-/*********************/\r
-/* Decoder functions */\r
-/*********************/\r
-\r
-SKP_int SKP_Silk_SDK_Get_Decoder_Size( SKP_int32 *decSizeBytes ) \r
-{\r
-    SKP_int ret = 0;\r
-\r
-    *decSizeBytes = sizeof( SKP_Silk_decoder_state );\r
-\r
-    return ret;\r
-}\r
-\r
-/* Reset decoder state */\r
-SKP_int SKP_Silk_SDK_InitDecoder(\r
-    void* decState                                      /* I/O: State                                          */\r
-)\r
-{\r
-    SKP_int ret = 0;\r
-    SKP_Silk_decoder_state *struc;\r
-\r
-    struc = (SKP_Silk_decoder_state *)decState;\r
-\r
-    ret  = SKP_Silk_init_decoder( struc );\r
-\r
-    return ret;\r
-}\r
-\r
-/* Decode a frame */\r
-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                              */\r
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
-    const SKP_int                       nBytesIn,       /* I:   Number of input Bytes                           */\r
-    SKP_int16                           *samplesOut,    /* O:   Decoded output speech vector                    */\r
-    SKP_int16                           *nSamplesOut    /* I/O: Number of samples (vector/decoded)              */\r
-)\r
-{\r
-    SKP_int ret = 0, used_bytes, prev_fs_kHz;\r
-    SKP_Silk_decoder_state *psDec;\r
-    SKP_int16 samplesOutInternal[ MAX_API_FS_KHZ * FRAME_LENGTH_MS ];\r
-    SKP_int16 *pSamplesOutInternal;\r
-\r
-    psDec = (SKP_Silk_decoder_state *)decState;\r
-\r
-    /* We need this buffer to have room for an internal frame */\r
-    pSamplesOutInternal = samplesOut;\r
-    if( psDec->fs_kHz * 1000 > decControl->API_sampleRate ) {\r
-        pSamplesOutInternal = samplesOutInternal;\r
-    }\r
-\r
-    /**********************************/\r
-    /* Test if first frame in payload */\r
-    /**********************************/\r
-    if( psDec->moreInternalDecoderFrames == 0 ) {\r
-        /* First Frame in Payload */\r
-        psDec->nFramesDecoded = 0;  /* Used to count frames in packet */\r
-    }\r
-\r
-    if( psDec->moreInternalDecoderFrames == 0 &&    /* First frame in packet    */\r
-        lostFlag == 0 &&                            /* Not packet loss          */\r
-        nBytesIn > MAX_ARITHM_BYTES ) {             /* Too long payload         */\r
-            /* Avoid trying to decode a too large packet */\r
-            lostFlag = 1;\r
-            ret = SKP_SILK_DEC_PAYLOAD_TOO_LARGE;\r
-    }\r
-            \r
-    /* Save previous sample frequency */\r
-    prev_fs_kHz = psDec->fs_kHz;\r
-    \r
-    /* Call decoder for one frame */\r
-    ret += SKP_Silk_decode_frame( psDec, pSamplesOutInternal, nSamplesOut, inData, nBytesIn, \r
-            lostFlag, &used_bytes );\r
-    \r
-    if( used_bytes ) { /* Only Call if not a packet loss */\r
-        if( psDec->nBytesLeft > 0 && psDec->FrameTermination == SKP_SILK_MORE_FRAMES && psDec->nFramesDecoded < 5 ) {\r
-            /* We have more frames in the Payload */\r
-            psDec->moreInternalDecoderFrames = 1;\r
-        } else {\r
-            /* Last frame in Payload */\r
-            psDec->moreInternalDecoderFrames = 0;\r
-            psDec->nFramesInPacket = psDec->nFramesDecoded;\r
-        \r
-            /* Track inband FEC usage */\r
-            if( psDec->vadFlag == VOICE_ACTIVITY ) {\r
-                if( psDec->FrameTermination == SKP_SILK_LAST_FRAME ) {\r
-                    psDec->no_FEC_counter++;\r
-                    if( psDec->no_FEC_counter > NO_LBRR_THRES ) {\r
-                        psDec->inband_FEC_offset = 0;\r
-                    }\r
-                } else if( psDec->FrameTermination == SKP_SILK_LBRR_VER1 ) {\r
-                    psDec->inband_FEC_offset = 1; /* FEC info with 1 packet delay */\r
-                    psDec->no_FEC_counter    = 0;\r
-                } else if( psDec->FrameTermination == SKP_SILK_LBRR_VER2 ) {\r
-                    psDec->inband_FEC_offset = 2; /* FEC info with 2 packets delay */\r
-                    psDec->no_FEC_counter    = 0;\r
-                }\r
-            }\r
-        }\r
-    }\r
-\r
-    if( MAX_API_FS_KHZ * 1000 < decControl->API_sampleRate ||\r
-        8000       > decControl->API_sampleRate ) {\r
-        ret = SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY;\r
-        return( ret );\r
-    }\r
-\r
-    /* Resample if needed */\r
-    if( psDec->fs_kHz * 1000 != decControl->API_sampleRate ) { \r
-        SKP_int16 samplesOut_tmp[ MAX_API_FS_KHZ * FRAME_LENGTH_MS ];\r
-        SKP_assert( psDec->fs_kHz <= MAX_API_FS_KHZ );\r
-\r
-        /* Copy to a tmp buffer as the resampling writes to samplesOut */\r
-        SKP_memcpy( samplesOut_tmp, pSamplesOutInternal, *nSamplesOut * sizeof( SKP_int16 ) );\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
-        }\r
-\r
-        /* Resample the output to API_sampleRate */\r
-        ret += SKP_Silk_resampler( &psDec->resampler_state, samplesOut, samplesOut_tmp, *nSamplesOut );\r
-\r
-        /* Update the number of output samples */\r
-        *nSamplesOut = SKP_DIV32( ( SKP_int32 )*nSamplesOut * decControl->API_sampleRate, psDec->fs_kHz * 1000 );\r
-    } else if( prev_fs_kHz * 1000 > decControl->API_sampleRate ) { \r
-        SKP_memcpy( samplesOut, pSamplesOutInternal, *nSamplesOut * sizeof( SKP_int16 ) );\r
-    }\r
-\r
-    psDec->prev_API_sampleRate = decControl->API_sampleRate;\r
-\r
-    /* Copy all parameters that are needed out of internal structure to the control stucture */\r
-    decControl->frameSize                 = (SKP_uint16)( decControl->API_sampleRate / 50 ) ;\r
-    decControl->framesPerPacket           = ( SKP_int )psDec->nFramesInPacket;\r
-    decControl->inBandFECOffset           = ( SKP_int )psDec->inband_FEC_offset;\r
-    decControl->moreInternalDecoderFrames = ( SKP_int )psDec->moreInternalDecoderFrames;\r
-\r
-    return ret;\r
-}\r
-\r
-/* Function to find LBRR information in a packet */\r
-void SKP_Silk_SDK_search_for_LBRR(\r
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
-    const SKP_int                       nBytesIn,       /* I:   Number of input Bytes                           */\r
-    SKP_int                             lost_offset,    /* I:   Offset from lost packet                         */\r
-    SKP_uint8                           *LBRRData,      /* O:   LBRR payload                                    */\r
-    SKP_int16                           *nLBRRBytes     /* O:   Number of LBRR Bytes                            */\r
-)\r
-{\r
-    SKP_Silk_decoder_state   sDec; // Local decoder state to avoid interfering with running decoder */\r
-    SKP_Silk_decoder_control sDecCtrl;\r
-    SKP_int TempQ[ MAX_FRAME_LENGTH ];\r
-\r
-    if( lost_offset < 1 || lost_offset > MAX_LBRR_DELAY ) {\r
-        /* No useful FEC in this packet */\r
-        *nLBRRBytes = 0;\r
-        return;\r
-    }\r
-\r
-    sDec.nFramesDecoded = 0;\r
-    sDec.fs_kHz         = 0; /* Force update parameters LPC_order etc */\r
-       sDec.lossCnt        = 0; /* Avoid running bw expansion of the LPC parameters when searching for LBRR data */\r
-    SKP_memset( sDec.prevNLSF_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );\r
-    SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );\r
-    \r
-    while(1) {\r
-        SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );\r
-    \r
-        if( sDec.sRC.error ) {\r
-            /* Corrupt stream */\r
-            *nLBRRBytes = 0;\r
-            return;\r
-        };\r
-        if( ( sDec.FrameTermination - 1 ) & lost_offset && sDec.FrameTermination > 0 && sDec.nBytesLeft >= 0 ) {\r
-            /* The wanted FEC is present in the packet */\r
-            *nLBRRBytes = sDec.nBytesLeft;\r
-            SKP_memcpy( LBRRData, &inData[ nBytesIn - sDec.nBytesLeft ], sDec.nBytesLeft * sizeof( SKP_uint8 ) );\r
-            break;\r
-        }\r
-        if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {\r
-            sDec.nFramesDecoded++;\r
-        } else {\r
-            LBRRData = NULL;\r
-            *nLBRRBytes = 0;\r
-            break;\r
-        }\r
-    }\r
-}\r
-\r
-/* Getting type of content for a packet */\r
-void SKP_Silk_SDK_get_TOC(\r
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
-    const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */\r
-    SKP_Silk_TOC_struct                 *Silk_TOC       /* O:   Type of content                                 */\r
-)\r
-{\r
-    SKP_Silk_decoder_state      sDec; // Local Decoder state to avoid interfering with running decoder */\r
-    SKP_Silk_decoder_control    sDecCtrl;\r
-    SKP_int TempQ[ MAX_FRAME_LENGTH ];\r
-\r
-    sDec.nFramesDecoded = 0;\r
-    sDec.fs_kHz         = 0; /* Force update parameters LPC_order etc */\r
-    SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );\r
-\r
-    Silk_TOC->corrupt = 0;\r
-    while( 1 ) {\r
-        SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );\r
-        \r
-        Silk_TOC->vadFlags[     sDec.nFramesDecoded ] = sDec.vadFlag;\r
-        Silk_TOC->sigtypeFlags[ sDec.nFramesDecoded ] = sDecCtrl.sigtype;\r
-    \r
-        if( sDec.sRC.error ) {\r
-            /* Corrupt stream */\r
-            Silk_TOC->corrupt = 1;\r
-            break;\r
-        };\r
-    \r
-        if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {\r
-            sDec.nFramesDecoded++;\r
-        } else {\r
-            break;\r
-        }\r
-    }\r
-    if( Silk_TOC->corrupt || sDec.FrameTermination == SKP_SILK_MORE_FRAMES || \r
-        sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET ) {\r
-        /* Corrupt packet */\r
-        SKP_memset( Silk_TOC, 0, sizeof( SKP_Silk_TOC_struct ) );\r
-        Silk_TOC->corrupt = 1;\r
-    } else {\r
-        Silk_TOC->framesInPacket = sDec.nFramesDecoded + 1;\r
-        Silk_TOC->fs_kHz         = sDec.fs_kHz;\r
-        if( sDec.FrameTermination == SKP_SILK_LAST_FRAME ) {\r
-            Silk_TOC->inbandLBRR = sDec.FrameTermination;\r
-        } else {\r
-            Silk_TOC->inbandLBRR = sDec.FrameTermination - 1;\r
-        }\r
-    }\r
-}\r
-\r
-/**************************/\r
-/* Get the version number */\r
-/**************************/\r
-/* Return a pointer to string specifying the version */ \r
-const char *SKP_Silk_SDK_get_version()\r
-{\r
-    static const char version[] = "1.0.8";\r
-    return version;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_SDK_API.h"
+#include "SKP_Silk_main.h"
+
+/*********************/
+/* Decoder functions */
+/*********************/
+
+SKP_int SKP_Silk_SDK_Get_Decoder_Size( SKP_int32 *decSizeBytes ) 
+{
+    SKP_int ret = 0;
+
+    *decSizeBytes = sizeof( SKP_Silk_decoder_state );
+
+    return ret;
+}
+
+/* Reset decoder state */
+SKP_int SKP_Silk_SDK_InitDecoder(
+    void* decState                                      /* I/O: State                                          */
+)
+{
+    SKP_int ret = 0;
+    SKP_Silk_decoder_state *struc;
+
+    struc = (SKP_Silk_decoder_state *)decState;
+
+    ret  = SKP_Silk_init_decoder( struc );
+
+    return ret;
+}
+
+/* Decode a frame */
+SKP_int SKP_Silk_SDK_Decode(
+    void*                               decState,       /* I/O: State                                           */
+    SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control structure                               */
+    SKP_int                             lostFlag,       /* I:   0: no loss, 1 loss                              */
+    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
+    const SKP_int                       nBytesIn,       /* I:   Number of input Bytes                           */
+    SKP_int16                           *samplesOut,    /* O:   Decoded output speech vector                    */
+    SKP_int16                           *nSamplesOut    /* I/O: Number of samples (vector/decoded)              */
+)
+{
+    SKP_int ret = 0, used_bytes, prev_fs_kHz;
+    SKP_Silk_decoder_state *psDec;
+    SKP_int16 samplesOutInternal[ MAX_API_FS_KHZ * FRAME_LENGTH_MS ];
+    SKP_int16 *pSamplesOutInternal;
+
+    psDec = (SKP_Silk_decoder_state *)decState;
+
+    /* We need this buffer to have room for an internal frame */
+    pSamplesOutInternal = samplesOut;
+    if( psDec->fs_kHz * 1000 > decControl->API_sampleRate ) {
+        pSamplesOutInternal = samplesOutInternal;
+    }
+
+    /**********************************/
+    /* Test if first frame in payload */
+    /**********************************/
+    if( psDec->moreInternalDecoderFrames == 0 ) {
+        /* First Frame in Payload */
+        psDec->nFramesDecoded = 0;  /* Used to count frames in packet */
+    }
+
+    if( psDec->moreInternalDecoderFrames == 0 &&    /* First frame in packet    */
+        lostFlag == 0 &&                            /* Not packet loss          */
+        nBytesIn > MAX_ARITHM_BYTES ) {             /* Too long payload         */
+            /* Avoid trying to decode a too large packet */
+            lostFlag = 1;
+            ret = SKP_SILK_DEC_PAYLOAD_TOO_LARGE;
+    }
+            
+    /* Save previous sample frequency */
+    prev_fs_kHz = psDec->fs_kHz;
+    
+    /* Call decoder for one frame */
+    ret += SKP_Silk_decode_frame( psDec, pSamplesOutInternal, nSamplesOut, inData, nBytesIn, 
+            lostFlag, &used_bytes );
+    
+    if( used_bytes ) { /* Only Call if not a packet loss */
+        if( psDec->nBytesLeft > 0 && psDec->FrameTermination == SKP_SILK_MORE_FRAMES && psDec->nFramesDecoded < 5 ) {
+            /* We have more frames in the Payload */
+            psDec->moreInternalDecoderFrames = 1;
+        } else {
+            /* Last frame in Payload */
+            psDec->moreInternalDecoderFrames = 0;
+            psDec->nFramesInPacket = psDec->nFramesDecoded;
+        
+            /* Track inband FEC usage */
+            if( psDec->vadFlag == VOICE_ACTIVITY ) {
+                if( psDec->FrameTermination == SKP_SILK_LAST_FRAME ) {
+                    psDec->no_FEC_counter++;
+                    if( psDec->no_FEC_counter > NO_LBRR_THRES ) {
+                        psDec->inband_FEC_offset = 0;
+                    }
+                } else if( psDec->FrameTermination == SKP_SILK_LBRR_VER1 ) {
+                    psDec->inband_FEC_offset = 1; /* FEC info with 1 packet delay */
+                    psDec->no_FEC_counter    = 0;
+                } else if( psDec->FrameTermination == SKP_SILK_LBRR_VER2 ) {
+                    psDec->inband_FEC_offset = 2; /* FEC info with 2 packets delay */
+                    psDec->no_FEC_counter    = 0;
+                }
+            }
+        }
+    }
+
+    if( MAX_API_FS_KHZ * 1000 < decControl->API_sampleRate ||
+        8000       > decControl->API_sampleRate ) {
+        ret = SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY;
+        return( ret );
+    }
+
+    /* Resample if needed */
+    if( psDec->fs_kHz * 1000 != decControl->API_sampleRate ) { 
+        SKP_int16 samplesOut_tmp[ MAX_API_FS_KHZ * FRAME_LENGTH_MS ];
+        SKP_assert( psDec->fs_kHz <= MAX_API_FS_KHZ );
+
+        /* Copy to a tmp buffer as the resampling writes to samplesOut */
+        SKP_memcpy( samplesOut_tmp, pSamplesOutInternal, *nSamplesOut * sizeof( SKP_int16 ) );
+
+        /* (Re-)initialize resampler state when switching internal sampling frequency */
+        if( prev_fs_kHz != psDec->fs_kHz || psDec->prev_API_sampleRate != decControl->API_sampleRate ) {
+            ret = SKP_Silk_resampler_init( &psDec->resampler_state, SKP_SMULBB( psDec->fs_kHz, 1000 ), decControl->API_sampleRate );
+        }
+
+        /* Resample the output to API_sampleRate */
+        ret += SKP_Silk_resampler( &psDec->resampler_state, samplesOut, samplesOut_tmp, *nSamplesOut );
+
+        /* Update the number of output samples */
+        *nSamplesOut = SKP_DIV32( ( SKP_int32 )*nSamplesOut * decControl->API_sampleRate, psDec->fs_kHz * 1000 );
+    } else if( prev_fs_kHz * 1000 > decControl->API_sampleRate ) { 
+        SKP_memcpy( samplesOut, pSamplesOutInternal, *nSamplesOut * sizeof( SKP_int16 ) );
+    }
+
+    psDec->prev_API_sampleRate = decControl->API_sampleRate;
+
+    /* Copy all parameters that are needed out of internal structure to the control stucture */
+    decControl->frameSize                 = (SKP_uint16)( decControl->API_sampleRate / 50 ) ;
+    decControl->framesPerPacket           = ( SKP_int )psDec->nFramesInPacket;
+    decControl->inBandFECOffset           = ( SKP_int )psDec->inband_FEC_offset;
+    decControl->moreInternalDecoderFrames = ( SKP_int )psDec->moreInternalDecoderFrames;
+
+    return ret;
+}
+
+/* Function to find LBRR information in a packet */
+void SKP_Silk_SDK_search_for_LBRR(
+    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
+    const SKP_int                       nBytesIn,       /* I:   Number of input Bytes                           */
+    SKP_int                             lost_offset,    /* I:   Offset from lost packet                         */
+    SKP_uint8                           *LBRRData,      /* O:   LBRR payload                                    */
+    SKP_int16                           *nLBRRBytes     /* O:   Number of LBRR Bytes                            */
+)
+{
+    SKP_Silk_decoder_state   sDec; // Local decoder state to avoid interfering with running decoder */
+    SKP_Silk_decoder_control sDecCtrl;
+    SKP_int TempQ[ MAX_FRAME_LENGTH ];
+
+    if( lost_offset < 1 || lost_offset > MAX_LBRR_DELAY ) {
+        /* No useful FEC in this packet */
+        *nLBRRBytes = 0;
+        return;
+    }
+
+    sDec.nFramesDecoded = 0;
+    sDec.fs_kHz         = 0; /* Force update parameters LPC_order etc */
+       sDec.lossCnt        = 0; /* Avoid running bw expansion of the LPC parameters when searching for LBRR data */
+    SKP_memset( sDec.prevNLSF_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );
+    SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );
+    
+    while(1) {
+        SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );
+    
+        if( sDec.sRC.error ) {
+            /* Corrupt stream */
+            *nLBRRBytes = 0;
+            return;
+        };
+        if( ( sDec.FrameTermination - 1 ) & lost_offset && sDec.FrameTermination > 0 && sDec.nBytesLeft >= 0 ) {
+            /* The wanted FEC is present in the packet */
+            *nLBRRBytes = sDec.nBytesLeft;
+            SKP_memcpy( LBRRData, &inData[ nBytesIn - sDec.nBytesLeft ], sDec.nBytesLeft * sizeof( SKP_uint8 ) );
+            break;
+        }
+        if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {
+            sDec.nFramesDecoded++;
+        } else {
+            LBRRData = NULL;
+            *nLBRRBytes = 0;
+            break;
+        }
+    }
+}
+
+/* Getting type of content for a packet */
+void SKP_Silk_SDK_get_TOC(
+    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
+    const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */
+    SKP_Silk_TOC_struct                 *Silk_TOC       /* O:   Type of content                                 */
+)
+{
+    SKP_Silk_decoder_state      sDec; // Local Decoder state to avoid interfering with running decoder */
+    SKP_Silk_decoder_control    sDecCtrl;
+    SKP_int TempQ[ MAX_FRAME_LENGTH ];
+
+    sDec.nFramesDecoded = 0;
+    sDec.fs_kHz         = 0; /* Force update parameters LPC_order etc */
+    SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );
+
+    Silk_TOC->corrupt = 0;
+    while( 1 ) {
+        SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );
+        
+        Silk_TOC->vadFlags[     sDec.nFramesDecoded ] = sDec.vadFlag;
+        Silk_TOC->sigtypeFlags[ sDec.nFramesDecoded ] = sDecCtrl.sigtype;
+    
+        if( sDec.sRC.error ) {
+            /* Corrupt stream */
+            Silk_TOC->corrupt = 1;
+            break;
+        };
+    
+        if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {
+            sDec.nFramesDecoded++;
+        } else {
+            break;
+        }
+    }
+    if( Silk_TOC->corrupt || sDec.FrameTermination == SKP_SILK_MORE_FRAMES || 
+        sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET ) {
+        /* Corrupt packet */
+        SKP_memset( Silk_TOC, 0, sizeof( SKP_Silk_TOC_struct ) );
+        Silk_TOC->corrupt = 1;
+    } else {
+        Silk_TOC->framesInPacket = sDec.nFramesDecoded + 1;
+        Silk_TOC->fs_kHz         = sDec.fs_kHz;
+        if( sDec.FrameTermination == SKP_SILK_LAST_FRAME ) {
+            Silk_TOC->inbandLBRR = sDec.FrameTermination;
+        } else {
+            Silk_TOC->inbandLBRR = sDec.FrameTermination - 1;
+        }
+    }
+}
+
+/**************************/
+/* Get the version number */
+/**************************/
+/* Return a pointer to string specifying the version */ 
+const char *SKP_Silk_SDK_get_version()
+{
+    static const char version[] = "1.0.8";
+    return version;
+}
index 440d0c9affffd3acb9229ddef3ebc140036c5d77..0384f3fc49904eabaf271c44bc391a08a41eded0 100644 (file)
-/***********************************************************************\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
-void SKP_Silk_decode_short_term_prediction(\r
-SKP_int32      *vec_Q10,\r
-SKP_int32      *pres_Q10,\r
-SKP_int32      *sLPC_Q14,\r
-SKP_int16      *A_Q12_tmp, \r
-SKP_int                LPC_order,\r
-SKP_int                subfr_length\r
-);\r
-\r
-\r
-/**********************************************************/\r
-/* Core decoder. Performs inverse NSQ operation LTP + LPC */\r
-/**********************************************************/\r
-void SKP_Silk_decode_core(\r
-    SKP_Silk_decoder_state      *psDec,                             /* I/O  Decoder state               */\r
-    SKP_Silk_decoder_control    *psDecCtrl,                         /* I    Decoder control             */\r
-    SKP_int16                   xq[],                               /* O    Decoded speech              */\r
-    const SKP_int               q[ MAX_FRAME_LENGTH ]               /* I    Pulse signal                */\r
-)\r
-{\r
-    SKP_int   i, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, sigtype, LTP_scale_Q14;\r
-    SKP_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ];\r
-    SKP_int16 sLTP[ MAX_FRAME_LENGTH ];\r
-    SKP_int32 LTP_pred_Q14, Gain_Q16, inv_gain_Q16, inv_gain_Q32, gain_adj_Q16, rand_seed, offset_Q10, dither;\r
-    SKP_int32 *pred_lag_ptr, *pexc_Q10, *pres_Q10;\r
-    SKP_int32 vec_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ];\r
-    SKP_int32 FiltState[ MAX_LPC_ORDER ];\r
-\r
-    SKP_assert( psDec->prev_inv_gain_Q16 != 0 );\r
-    \r
-    offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psDecCtrl->sigtype ][ psDecCtrl->QuantOffsetType ];\r
-\r
-    if( psDecCtrl->NLSFInterpCoef_Q2 < ( 1 << 2 ) ) {\r
-        NLSF_interpolation_flag = 1;\r
-    } else {\r
-        NLSF_interpolation_flag = 0;\r
-    }\r
-\r
-\r
-    /* Decode excitation */\r
-    rand_seed = psDecCtrl->Seed;\r
-    for( i = 0; i < psDec->frame_length; i++ ) {\r
-        rand_seed = SKP_RAND( rand_seed );\r
-        /* dither = rand_seed < 0 ? 0xFFFFFFFF : 0; */\r
-        dither = SKP_RSHIFT( rand_seed, 31 );\r
-\r
-        psDec->exc_Q10[ i ] = SKP_LSHIFT( ( SKP_int32 )q[ i ], 10 ) + offset_Q10;\r
-        psDec->exc_Q10[ i ] = ( psDec->exc_Q10[ i ] ^ dither ) - dither;\r
-\r
-        rand_seed += q[ i ];\r
-    }\r
-\r
-\r
-    pexc_Q10 = psDec->exc_Q10;\r
-    pres_Q10 = psDec->res_Q10;\r
-    pxq      = &psDec->outBuf[ psDec->frame_length ];\r
-    sLTP_buf_idx = psDec->frame_length;\r
-    /* Loop over subframes */\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        A_Q12 = psDecCtrl->PredCoef_Q12[ k >> 1 ];\r
-\r
-        /* Preload LPC coeficients to array on stack. Gives small performance gain */        \r
-        SKP_memcpy( A_Q12_tmp, A_Q12, psDec->LPC_order * sizeof( SKP_int16 ) ); \r
-        B_Q14         = &psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER ];\r
-        Gain_Q16      = psDecCtrl->Gains_Q16[ k ];\r
-        LTP_scale_Q14 = psDecCtrl->LTP_scale_Q14;\r
-        sigtype       = psDecCtrl->sigtype;\r
-\r
-        inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gain_Q16, 1 ), 32 );\r
-        inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );\r
-\r
-        /* Calculate Gain adjustment factor */\r
-        gain_adj_Q16 = ( SKP_int32 )1 << 16;\r
-        if( inv_gain_Q16 != psDec->prev_inv_gain_Q16 ) {\r
-            gain_adj_Q16 =  SKP_DIV32_varQ( inv_gain_Q16, psDec->prev_inv_gain_Q16, 16 );\r
-        }\r
-\r
-        /* Avoid abrupt transition from voiced PLC to unvoiced normal decoding */\r
-        if( psDec->lossCnt && psDec->prev_sigtype == SIG_TYPE_VOICED &&\r
-            psDecCtrl->sigtype == SIG_TYPE_UNVOICED && k < ( NB_SUBFR >> 1 ) ) {\r
-            \r
-            SKP_memset( B_Q14, 0, LTP_ORDER * sizeof( SKP_int16 ) );\r
-            B_Q14[ LTP_ORDER/2 ] = ( SKP_int16 )1 << 12; /* 0.25 */\r
-        \r
-            sigtype = SIG_TYPE_VOICED;\r
-            psDecCtrl->pitchL[ k ] = psDec->lagPrev;\r
-            LTP_scale_Q14 = ( SKP_int )1 << 14;\r
-        }\r
-\r
-        if( sigtype == SIG_TYPE_VOICED ) {\r
-            /* Voiced */\r
-            \r
-            lag = psDecCtrl->pitchL[ k ];\r
-            /* Re-whitening */\r
-            if( ( k & ( 3 - SKP_LSHIFT( NLSF_interpolation_flag, 1 ) ) ) == 0 ) {\r
-                /* Rewhiten with new A coefs */\r
-                start_idx = psDec->frame_length - lag - psDec->LPC_order - LTP_ORDER / 2;\r
-                SKP_assert( start_idx >= 0 );\r
-                SKP_assert( start_idx <= psDec->frame_length - psDec->LPC_order );\r
-\r
-                SKP_memset( FiltState, 0, psDec->LPC_order * sizeof( SKP_int32 ) ); /* Not really necessary, but Valgrind and Coverity will complain otherwise */\r
-                SKP_Silk_MA_Prediction( &psDec->outBuf[ start_idx + k * ( psDec->frame_length >> 2 ) ], \r
-                    A_Q12, FiltState, sLTP + start_idx, psDec->frame_length - start_idx, psDec->LPC_order );\r
-\r
-                /* After rewhitening the LTP state is unscaled */\r
-                inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 );\r
-                if( k == 0 ) {\r
-                    /* Do LTP downscaling */\r
-                    inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, psDecCtrl->LTP_scale_Q14 ), 2 );\r
-                }\r
-                for( i = 0; i < (lag + LTP_ORDER/2); i++ ) {\r
-                    psDec->sLTP_Q16[ sLTP_buf_idx - i - 1 ] = SKP_SMULWB( inv_gain_Q32, sLTP[ psDec->frame_length - i - 1 ] );\r
-                }\r
-            } else {\r
-                /* Update LTP state when Gain changes */\r
-                if( gain_adj_Q16 != ( SKP_int32 )1 << 16 ) {\r
-                    for( i = 0; i < ( lag + LTP_ORDER / 2 ); i++ ) {\r
-                        psDec->sLTP_Q16[ sLTP_buf_idx - i - 1 ] = SKP_SMULWW( gain_adj_Q16, psDec->sLTP_Q16[ sLTP_buf_idx - i - 1 ] );\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        \r
-        /* Scale short term state */\r
-        for( i = 0; i < MAX_LPC_ORDER; i++ ) {\r
-            psDec->sLPC_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, psDec->sLPC_Q14[ i ] );\r
-        }\r
-\r
-        /* Save inv_gain */\r
-        SKP_assert( inv_gain_Q16 != 0 );\r
-        psDec->prev_inv_gain_Q16 = inv_gain_Q16;\r
-\r
-        /* Long-term prediction */\r
-        if( sigtype == SIG_TYPE_VOICED ) {\r
-            /* Setup pointer */\r
-            pred_lag_ptr = &psDec->sLTP_Q16[ sLTP_buf_idx - lag + LTP_ORDER / 2 ];\r
-            for( i = 0; i < psDec->subfr_length; i++ ) {\r
-                /* Unrolled loop */\r
-                LTP_pred_Q14 = SKP_SMULWB(               pred_lag_ptr[  0 ], B_Q14[ 0 ] );\r
-                LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], B_Q14[ 1 ] );\r
-                LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], B_Q14[ 2 ] );\r
-                LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], B_Q14[ 3 ] );\r
-                LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], B_Q14[ 4 ] );\r
-                pred_lag_ptr++;\r
-            \r
-                /* Generate LPC residual */ \r
-                pres_Q10[ i ] = SKP_ADD32( pexc_Q10[ i ], SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) );\r
-            \r
-                /* Update states */\r
-                psDec->sLTP_Q16[ sLTP_buf_idx ] = SKP_LSHIFT( pres_Q10[ i ], 6 );\r
-                sLTP_buf_idx++;\r
-            }\r
-        } else {\r
-            SKP_memcpy( pres_Q10, pexc_Q10, psDec->subfr_length * sizeof( SKP_int32 ) );\r
-        }\r
-\r
-       SKP_Silk_decode_short_term_prediction(vec_Q10, pres_Q10, psDec->sLPC_Q14,A_Q12_tmp,psDec->LPC_order,psDec->subfr_length);\r
-\r
-        /* Scale with Gain */\r
-        for( i = 0; i < psDec->subfr_length; i++ ) {\r
-            pxq[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( vec_Q10[ i ], Gain_Q16 ), 10 ) );\r
-        }\r
-\r
-        /* Update LPC filter state */\r
-        SKP_memcpy( psDec->sLPC_Q14, &psDec->sLPC_Q14[ psDec->subfr_length ], MAX_LPC_ORDER * sizeof( SKP_int32 ) );\r
-        pexc_Q10 += psDec->subfr_length;\r
-        pres_Q10 += psDec->subfr_length;\r
-        pxq      += psDec->subfr_length;\r
-    }\r
-    \r
-    /* Copy to output */\r
-    SKP_memcpy( xq, &psDec->outBuf[ psDec->frame_length ], psDec->frame_length * sizeof( SKP_int16 ) );\r
-\r
-}\r
-\r
-void SKP_Silk_decode_short_term_prediction(\r
-SKP_int32      *vec_Q10,\r
-SKP_int32      *pres_Q10,\r
-SKP_int32      *sLPC_Q14,\r
-SKP_int16      *A_Q12_tmp, \r
-SKP_int                LPC_order,\r
-SKP_int                subfr_length\r
-)\r
-{\r
-  SKP_int      i;\r
-  SKP_int32    LPC_pred_Q10;\r
-    SKP_int j;\r
-        for( i = 0; i < subfr_length; i++ ) {\r
-            /* Partially unrolled */\r
-            LPC_pred_Q10 = SKP_SMULWB(               sLPC_Q14[ MAX_LPC_ORDER + i -  1 ], A_Q12_tmp[ 0 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  2 ], A_Q12_tmp[ 1 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  3 ], A_Q12_tmp[ 2 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  4 ], A_Q12_tmp[ 3 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  5 ], A_Q12_tmp[ 4 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  6 ], A_Q12_tmp[ 5 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  7 ], A_Q12_tmp[ 6 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  8 ], A_Q12_tmp[ 7 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  9 ], A_Q12_tmp[ 8 ] );\r
-            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp[ 9 ] );\r
-\r
-            for( j = 10; j < LPC_order; j ++ ) {\r
-                LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - j - 1 ], A_Q12_tmp[ j ] );\r
-            }\r
-\r
-            /* Add prediction to LPC residual */\r
-            vec_Q10[ i ] = SKP_ADD32( pres_Q10[ i ], LPC_pred_Q10 );\r
-            \r
-            /* Update states */\r
-            sLPC_Q14[ MAX_LPC_ORDER + i ] = SKP_LSHIFT( vec_Q10[ i ], 4 );\r
-        }\r
-}\r
-\r
-\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+
+void SKP_Silk_decode_short_term_prediction(
+SKP_int32      *vec_Q10,
+SKP_int32      *pres_Q10,
+SKP_int32      *sLPC_Q14,
+SKP_int16      *A_Q12_tmp, 
+SKP_int                LPC_order,
+SKP_int                subfr_length
+);
+
+
+/**********************************************************/
+/* Core decoder. Performs inverse NSQ operation LTP + LPC */
+/**********************************************************/
+void SKP_Silk_decode_core(
+    SKP_Silk_decoder_state      *psDec,                             /* I/O  Decoder state               */
+    SKP_Silk_decoder_control    *psDecCtrl,                         /* I    Decoder control             */
+    SKP_int16                   xq[],                               /* O    Decoded speech              */
+    const SKP_int               q[ MAX_FRAME_LENGTH ]               /* I    Pulse signal                */
+)
+{
+    SKP_int   i, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, sigtype, LTP_scale_Q14;
+    SKP_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ];
+    SKP_int16 sLTP[ MAX_FRAME_LENGTH ];
+    SKP_int32 LTP_pred_Q14, Gain_Q16, inv_gain_Q16, inv_gain_Q32, gain_adj_Q16, rand_seed, offset_Q10, dither;
+    SKP_int32 *pred_lag_ptr, *pexc_Q10, *pres_Q10;
+    SKP_int32 vec_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ];
+    SKP_int32 FiltState[ MAX_LPC_ORDER ];
+
+    SKP_assert( psDec->prev_inv_gain_Q16 != 0 );
+    
+    offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psDecCtrl->sigtype ][ psDecCtrl->QuantOffsetType ];
+
+    if( psDecCtrl->NLSFInterpCoef_Q2 < ( 1 << 2 ) ) {
+        NLSF_interpolation_flag = 1;
+    } else {
+        NLSF_interpolation_flag = 0;
+    }
+
+
+    /* Decode excitation */
+    rand_seed = psDecCtrl->Seed;
+    for( i = 0; i < psDec->frame_length; i++ ) {
+        rand_seed = SKP_RAND( rand_seed );
+        /* dither = rand_seed < 0 ? 0xFFFFFFFF : 0; */
+        dither = SKP_RSHIFT( rand_seed, 31 );
+
+        psDec->exc_Q10[ i ] = SKP_LSHIFT( ( SKP_int32 )q[ i ], 10 ) + offset_Q10;
+        psDec->exc_Q10[ i ] = ( psDec->exc_Q10[ i ] ^ dither ) - dither;
+
+        rand_seed += q[ i ];
+    }
+
+
+    pexc_Q10 = psDec->exc_Q10;
+    pres_Q10 = psDec->res_Q10;
+    pxq      = &psDec->outBuf[ psDec->frame_length ];
+    sLTP_buf_idx = psDec->frame_length;
+    /* Loop over subframes */
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        A_Q12 = psDecCtrl->PredCoef_Q12[ k >> 1 ];
+
+        /* Preload LPC coeficients to array on stack. Gives small performance gain */        
+        SKP_memcpy( A_Q12_tmp, A_Q12, psDec->LPC_order * sizeof( SKP_int16 ) ); 
+        B_Q14         = &psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER ];
+        Gain_Q16      = psDecCtrl->Gains_Q16[ k ];
+        LTP_scale_Q14 = psDecCtrl->LTP_scale_Q14;
+        sigtype       = psDecCtrl->sigtype;
+
+        inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gain_Q16, 1 ), 32 );
+        inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );
+
+        /* Calculate Gain adjustment factor */
+        gain_adj_Q16 = ( SKP_int32 )1 << 16;
+        if( inv_gain_Q16 != psDec->prev_inv_gain_Q16 ) {
+            gain_adj_Q16 =  SKP_DIV32_varQ( inv_gain_Q16, psDec->prev_inv_gain_Q16, 16 );
+        }
+
+        /* Avoid abrupt transition from voiced PLC to unvoiced normal decoding */
+        if( psDec->lossCnt && psDec->prev_sigtype == SIG_TYPE_VOICED &&
+            psDecCtrl->sigtype == SIG_TYPE_UNVOICED && k < ( NB_SUBFR >> 1 ) ) {
+            
+            SKP_memset( B_Q14, 0, LTP_ORDER * sizeof( SKP_int16 ) );
+            B_Q14[ LTP_ORDER/2 ] = ( SKP_int16 )1 << 12; /* 0.25 */
+        
+            sigtype = SIG_TYPE_VOICED;
+            psDecCtrl->pitchL[ k ] = psDec->lagPrev;
+            LTP_scale_Q14 = ( SKP_int )1 << 14;
+        }
+
+        if( sigtype == SIG_TYPE_VOICED ) {
+            /* Voiced */
+            
+            lag = psDecCtrl->pitchL[ k ];
+            /* Re-whitening */
+            if( ( k & ( 3 - SKP_LSHIFT( NLSF_interpolation_flag, 1 ) ) ) == 0 ) {
+                /* Rewhiten with new A coefs */
+                start_idx = psDec->frame_length - lag - psDec->LPC_order - LTP_ORDER / 2;
+                SKP_assert( start_idx >= 0 );
+                SKP_assert( start_idx <= psDec->frame_length - psDec->LPC_order );
+
+                SKP_memset( FiltState, 0, psDec->LPC_order * sizeof( SKP_int32 ) ); /* Not really necessary, but Valgrind and Coverity will complain otherwise */
+                SKP_Silk_MA_Prediction( &psDec->outBuf[ start_idx + k * ( psDec->frame_length >> 2 ) ], 
+                    A_Q12, FiltState, sLTP + start_idx, psDec->frame_length - start_idx, psDec->LPC_order );
+
+                /* After rewhitening the LTP state is unscaled */
+                inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 );
+                if( k == 0 ) {
+                    /* Do LTP downscaling */
+                    inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, psDecCtrl->LTP_scale_Q14 ), 2 );
+                }
+                for( i = 0; i < (lag + LTP_ORDER/2); i++ ) {
+                    psDec->sLTP_Q16[ sLTP_buf_idx - i - 1 ] = SKP_SMULWB( inv_gain_Q32, sLTP[ psDec->frame_length - i - 1 ] );
+                }
+            } else {
+                /* Update LTP state when Gain changes */
+                if( gain_adj_Q16 != ( SKP_int32 )1 << 16 ) {
+                    for( i = 0; i < ( lag + LTP_ORDER / 2 ); i++ ) {
+                        psDec->sLTP_Q16[ sLTP_buf_idx - i - 1 ] = SKP_SMULWW( gain_adj_Q16, psDec->sLTP_Q16[ sLTP_buf_idx - i - 1 ] );
+                    }
+                }
+            }
+        }
+        
+        /* Scale short term state */
+        for( i = 0; i < MAX_LPC_ORDER; i++ ) {
+            psDec->sLPC_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, psDec->sLPC_Q14[ i ] );
+        }
+
+        /* Save inv_gain */
+        SKP_assert( inv_gain_Q16 != 0 );
+        psDec->prev_inv_gain_Q16 = inv_gain_Q16;
+
+        /* Long-term prediction */
+        if( sigtype == SIG_TYPE_VOICED ) {
+            /* Setup pointer */
+            pred_lag_ptr = &psDec->sLTP_Q16[ sLTP_buf_idx - lag + LTP_ORDER / 2 ];
+            for( i = 0; i < psDec->subfr_length; i++ ) {
+                /* Unrolled loop */
+                LTP_pred_Q14 = SKP_SMULWB(               pred_lag_ptr[  0 ], B_Q14[ 0 ] );
+                LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], B_Q14[ 1 ] );
+                LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], B_Q14[ 2 ] );
+                LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], B_Q14[ 3 ] );
+                LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], B_Q14[ 4 ] );
+                pred_lag_ptr++;
+            
+                /* Generate LPC residual */ 
+                pres_Q10[ i ] = SKP_ADD32( pexc_Q10[ i ], SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) );
+            
+                /* Update states */
+                psDec->sLTP_Q16[ sLTP_buf_idx ] = SKP_LSHIFT( pres_Q10[ i ], 6 );
+                sLTP_buf_idx++;
+            }
+        } else {
+            SKP_memcpy( pres_Q10, pexc_Q10, psDec->subfr_length * sizeof( SKP_int32 ) );
+        }
+
+       SKP_Silk_decode_short_term_prediction(vec_Q10, pres_Q10, psDec->sLPC_Q14,A_Q12_tmp,psDec->LPC_order,psDec->subfr_length);
+
+        /* Scale with Gain */
+        for( i = 0; i < psDec->subfr_length; i++ ) {
+            pxq[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SMULWW( vec_Q10[ i ], Gain_Q16 ), 10 ) );
+        }
+
+        /* Update LPC filter state */
+        SKP_memcpy( psDec->sLPC_Q14, &psDec->sLPC_Q14[ psDec->subfr_length ], MAX_LPC_ORDER * sizeof( SKP_int32 ) );
+        pexc_Q10 += psDec->subfr_length;
+        pres_Q10 += psDec->subfr_length;
+        pxq      += psDec->subfr_length;
+    }
+    
+    /* Copy to output */
+    SKP_memcpy( xq, &psDec->outBuf[ psDec->frame_length ], psDec->frame_length * sizeof( SKP_int16 ) );
+
+}
+
+void SKP_Silk_decode_short_term_prediction(
+SKP_int32      *vec_Q10,
+SKP_int32      *pres_Q10,
+SKP_int32      *sLPC_Q14,
+SKP_int16      *A_Q12_tmp, 
+SKP_int                LPC_order,
+SKP_int                subfr_length
+)
+{
+  SKP_int      i;
+  SKP_int32    LPC_pred_Q10;
+    SKP_int j;
+        for( i = 0; i < subfr_length; i++ ) {
+            /* Partially unrolled */
+            LPC_pred_Q10 = SKP_SMULWB(               sLPC_Q14[ MAX_LPC_ORDER + i -  1 ], A_Q12_tmp[ 0 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  2 ], A_Q12_tmp[ 1 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  3 ], A_Q12_tmp[ 2 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  4 ], A_Q12_tmp[ 3 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  5 ], A_Q12_tmp[ 4 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  6 ], A_Q12_tmp[ 5 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  7 ], A_Q12_tmp[ 6 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  8 ], A_Q12_tmp[ 7 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i -  9 ], A_Q12_tmp[ 8 ] );
+            LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp[ 9 ] );
+
+            for( j = 10; j < LPC_order; j ++ ) {
+                LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - j - 1 ], A_Q12_tmp[ j ] );
+            }
+
+            /* Add prediction to LPC residual */
+            vec_Q10[ i ] = SKP_ADD32( pres_Q10[ i ], LPC_pred_Q10 );
+            
+            /* Update states */
+            sLPC_Q14[ MAX_LPC_ORDER + i ] = SKP_LSHIFT( vec_Q10[ i ], 4 );
+        }
+}
+
+
+
index 48382a5ee6ed7be95a7fc519110749dd86e8bd63..52a7a843e2f95b8d64ba51634482ad4be636049c 100644 (file)
-/***********************************************************************\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
-#include "SKP_Silk_main.h"\r
-#include "SKP_Silk_PLC.h"\r
-\r
-/****************/\r
-/* Decode frame */\r
-/****************/\r
-SKP_int SKP_Silk_decode_frame(\r
-    SKP_Silk_decoder_state          *psDec,             /* I/O  Pointer to Silk decoder state               */\r
-    SKP_int16                       pOut[],             /* O    Pointer to output speech frame              */\r
-    SKP_int16                       *pN,                /* O    Pointer to size of output frame             */\r
-    const SKP_uint8                 pCode[],            /* I    Pointer to payload                          */\r
-    const SKP_int                   nBytes,             /* I    Payload length                              */\r
-    SKP_int                         action,             /* I    Action from Jitter Buffer                   */\r
-    SKP_int                         *decBytes           /* O    Used bytes to decode this frame             */\r
-)\r
-{\r
-    SKP_Silk_decoder_control sDecCtrl;\r
-    SKP_int         L, fs_Khz_old, LPC_order_old, ret = 0;\r
-    SKP_int         Pulses[ MAX_FRAME_LENGTH ];\r
-\r
-\r
-    L = psDec->frame_length;\r
-    sDecCtrl.LTP_scale_Q14 = 0;\r
-    \r
-    /* Safety checks */\r
-    SKP_assert( L > 0 && L <= MAX_FRAME_LENGTH );\r
-\r
-    /********************************************/\r
-    /* Decode Frame if packet is not lost  */\r
-    /********************************************/\r
-    *decBytes = 0;\r
-    if( action == 0 ) {\r
-        /********************************************/\r
-        /* Initialize arithmetic coder              */\r
-        /********************************************/\r
-        fs_Khz_old    = psDec->fs_kHz;\r
-        LPC_order_old = psDec->LPC_order;\r
-        if( psDec->nFramesDecoded == 0 ) {\r
-            /* Initialize range decoder state */\r
-            SKP_Silk_range_dec_init( &psDec->sRC, pCode, nBytes );\r
-        }\r
-\r
-        /********************************************/\r
-        /* Decode parameters and pulse signal       */\r
-        /********************************************/\r
-        SKP_Silk_decode_parameters( psDec, &sDecCtrl, Pulses, 1 );\r
-\r
-\r
-        if( psDec->sRC.error ) {\r
-            psDec->nBytesLeft = 0;\r
-\r
-            action              = 1; /* PLC operation */\r
-            /* revert fs if changed in decode_parameters */\r
-            SKP_Silk_decoder_set_fs( psDec, fs_Khz_old );\r
-\r
-            /* Avoid crashing */\r
-            *decBytes = psDec->sRC.bufferLength;\r
-\r
-            if( psDec->sRC.error == RANGE_CODER_DEC_PAYLOAD_TOO_LONG ) {\r
-                ret = SKP_SILK_DEC_PAYLOAD_TOO_LARGE;\r
-            } else {\r
-                ret = SKP_SILK_DEC_PAYLOAD_ERROR;\r
-            }\r
-        } else {\r
-            *decBytes = psDec->sRC.bufferLength - psDec->nBytesLeft;\r
-            psDec->nFramesDecoded++;\r
-        \r
-            /* Update lengths. Sampling frequency could have changed */\r
-            L = psDec->frame_length;\r
-\r
-            /********************************************************/\r
-            /* Run inverse NSQ                                      */\r
-            /********************************************************/\r
-            SKP_Silk_decode_core( psDec, &sDecCtrl, pOut, Pulses );\r
-\r
-            /********************************************************/\r
-            /* Update PLC state                                     */\r
-            /********************************************************/\r
-            SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, action );\r
-\r
-            psDec->lossCnt = 0;\r
-            psDec->prev_sigtype = sDecCtrl.sigtype;\r
-\r
-            /* A frame has been decoded without errors */\r
-            psDec->first_frame_after_reset = 0;\r
-        }\r
-    }\r
-    /*************************************************************/\r
-    /* Generate Concealment frame if packet is lost, or corrupt  */\r
-    /*************************************************************/\r
-    if( action == 1 ) {\r
-        /* Handle packet loss by extrapolation */\r
-        SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, action );\r
-    }\r
-\r
-    /*************************/\r
-    /* Update output buffer. */\r
-    /*************************/\r
-    SKP_memcpy( psDec->outBuf, pOut, L * sizeof( SKP_int16 ) );\r
-\r
-    /****************************************************************/\r
-    /* Ensure smooth connection of extrapolated and good frames     */\r
-    /****************************************************************/\r
-    SKP_Silk_PLC_glue_frames( psDec, &sDecCtrl, pOut, L );\r
-\r
-    /************************************************/\r
-    /* Comfort noise generation / estimation        */\r
-    /************************************************/\r
-    SKP_Silk_CNG( psDec, &sDecCtrl, pOut , L );\r
-\r
-    /********************************************/\r
-    /* HP filter output                            */\r
-    /********************************************/\r
-    SKP_assert( ( ( psDec->fs_kHz == 12 ) && ( L % 3 ) == 0 ) || \r
-                ( ( psDec->fs_kHz != 12 ) && ( L % 2 ) == 0 ) );\r
-    SKP_Silk_biquad( pOut, psDec->HP_B, psDec->HP_A, psDec->HPState, pOut, L );\r
-\r
-    /********************************************/\r
-    /* set output frame length                    */\r
-    /********************************************/\r
-    *pN = ( SKP_int16 )L;\r
-\r
-    /* Update some decoder state variables */\r
-    psDec->lagPrev = sDecCtrl.pitchL[ NB_SUBFR - 1 ];\r
-\r
-\r
-    return ret;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+
+#include "SKP_Silk_main.h"
+#include "SKP_Silk_PLC.h"
+
+/****************/
+/* Decode frame */
+/****************/
+SKP_int SKP_Silk_decode_frame(
+    SKP_Silk_decoder_state          *psDec,             /* I/O  Pointer to Silk decoder state               */
+    SKP_int16                       pOut[],             /* O    Pointer to output speech frame              */
+    SKP_int16                       *pN,                /* O    Pointer to size of output frame             */
+    const SKP_uint8                 pCode[],            /* I    Pointer to payload                          */
+    const SKP_int                   nBytes,             /* I    Payload length                              */
+    SKP_int                         action,             /* I    Action from Jitter Buffer                   */
+    SKP_int                         *decBytes           /* O    Used bytes to decode this frame             */
+)
+{
+    SKP_Silk_decoder_control sDecCtrl;
+    SKP_int         L, fs_Khz_old, LPC_order_old, ret = 0;
+    SKP_int         Pulses[ MAX_FRAME_LENGTH ];
+
+
+    L = psDec->frame_length;
+    sDecCtrl.LTP_scale_Q14 = 0;
+    
+    /* Safety checks */
+    SKP_assert( L > 0 && L <= MAX_FRAME_LENGTH );
+
+    /********************************************/
+    /* Decode Frame if packet is not lost  */
+    /********************************************/
+    *decBytes = 0;
+    if( action == 0 ) {
+        /********************************************/
+        /* Initialize arithmetic coder              */
+        /********************************************/
+        fs_Khz_old    = psDec->fs_kHz;
+        LPC_order_old = psDec->LPC_order;
+        if( psDec->nFramesDecoded == 0 ) {
+            /* Initialize range decoder state */
+            SKP_Silk_range_dec_init( &psDec->sRC, pCode, nBytes );
+        }
+
+        /********************************************/
+        /* Decode parameters and pulse signal       */
+        /********************************************/
+        SKP_Silk_decode_parameters( psDec, &sDecCtrl, Pulses, 1 );
+
+
+        if( psDec->sRC.error ) {
+            psDec->nBytesLeft = 0;
+
+            action              = 1; /* PLC operation */
+            /* revert fs if changed in decode_parameters */
+            SKP_Silk_decoder_set_fs( psDec, fs_Khz_old );
+
+            /* Avoid crashing */
+            *decBytes = psDec->sRC.bufferLength;
+
+            if( psDec->sRC.error == RANGE_CODER_DEC_PAYLOAD_TOO_LONG ) {
+                ret = SKP_SILK_DEC_PAYLOAD_TOO_LARGE;
+            } else {
+                ret = SKP_SILK_DEC_PAYLOAD_ERROR;
+            }
+        } else {
+            *decBytes = psDec->sRC.bufferLength - psDec->nBytesLeft;
+            psDec->nFramesDecoded++;
+        
+            /* Update lengths. Sampling frequency could have changed */
+            L = psDec->frame_length;
+
+            /********************************************************/
+            /* Run inverse NSQ                                      */
+            /********************************************************/
+            SKP_Silk_decode_core( psDec, &sDecCtrl, pOut, Pulses );
+
+            /********************************************************/
+            /* Update PLC state                                     */
+            /********************************************************/
+            SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, action );
+
+            psDec->lossCnt = 0;
+            psDec->prev_sigtype = sDecCtrl.sigtype;
+
+            /* A frame has been decoded without errors */
+            psDec->first_frame_after_reset = 0;
+        }
+    }
+    /*************************************************************/
+    /* Generate Concealment frame if packet is lost, or corrupt  */
+    /*************************************************************/
+    if( action == 1 ) {
+        /* Handle packet loss by extrapolation */
+        SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, action );
+    }
+
+    /*************************/
+    /* Update output buffer. */
+    /*************************/
+    SKP_memcpy( psDec->outBuf, pOut, L * sizeof( SKP_int16 ) );
+
+    /****************************************************************/
+    /* Ensure smooth connection of extrapolated and good frames     */
+    /****************************************************************/
+    SKP_Silk_PLC_glue_frames( psDec, &sDecCtrl, pOut, L );
+
+    /************************************************/
+    /* Comfort noise generation / estimation        */
+    /************************************************/
+    SKP_Silk_CNG( psDec, &sDecCtrl, pOut , L );
+
+    /********************************************/
+    /* HP filter output                            */
+    /********************************************/
+    SKP_assert( ( ( psDec->fs_kHz == 12 ) && ( L % 3 ) == 0 ) || 
+                ( ( psDec->fs_kHz != 12 ) && ( L % 2 ) == 0 ) );
+    SKP_Silk_biquad( pOut, psDec->HP_B, psDec->HP_A, psDec->HPState, pOut, L );
+
+    /********************************************/
+    /* set output frame length                    */
+    /********************************************/
+    *pN = ( SKP_int16 )L;
+
+    /* Update some decoder state variables */
+    psDec->lagPrev = sDecCtrl.pitchL[ NB_SUBFR - 1 ];
+
+
+    return ret;
+}
index 3a3516427d7ef31dc450b2e33bfff6a6f2709be5..60690b4a93dc22d92d232b7be8a266e565957a98 100644 (file)
-/***********************************************************************\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
-/* Decode parameters from payload */\r
-void SKP_Silk_decode_parameters(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O  State                                       */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */\r
-    SKP_int                     q[],                /* O    Excitation signal                           */\r
-    const SKP_int               fullDecoding        /* I    Flag to tell if only arithmetic decoding    */\r
-)\r
-{\r
-    SKP_int   i, k, Ix, fs_kHz_dec, nBytesUsed;\r
-    SKP_int   Ixs[ NB_SUBFR ];\r
-    SKP_int   GainsIndices[ NB_SUBFR ];\r
-    SKP_int   NLSFIndices[ NLSF_MSVQ_MAX_CB_STAGES ];\r
-    SKP_int   pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ];\r
-    const SKP_int16 *cbk_ptr_Q14;\r
-    const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL;\r
-    SKP_Silk_range_coder_state  *psRC = &psDec->sRC;\r
-\r
-    /************************/\r
-    /* Decode sampling rate */\r
-    /************************/\r
-    /* only done for first frame of packet */\r
-    if( psDec->nFramesDecoded == 0 ) {\r
-        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_SamplingRates_CDF, SKP_Silk_SamplingRates_offset );\r
-\r
-        /* check that sampling rate is supported */\r
-        if( Ix < 0 || Ix > 3 ) {\r
-            psRC->error = RANGE_CODER_ILLEGAL_SAMPLING_RATE;\r
-            return;\r
-        }\r
-        fs_kHz_dec = SKP_Silk_SamplingRates_table[ Ix ];\r
-        SKP_Silk_decoder_set_fs( psDec, fs_kHz_dec );\r
-    }\r
-\r
-    /*******************************************/\r
-    /* Decode signal type and quantizer offset */\r
-    /*******************************************/\r
-    if( psDec->nFramesDecoded == 0 ) {\r
-        /* first frame in packet: independent coding */\r
-        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_CDF, SKP_Silk_type_offset_CDF_offset );\r
-    } else {\r
-        /* condidtional coding */\r
-        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_joint_CDF[ psDec->typeOffsetPrev ], \r
-                SKP_Silk_type_offset_CDF_offset );\r
-    }\r
-    psDecCtrl->sigtype         = SKP_RSHIFT( Ix, 1 );\r
-    psDecCtrl->QuantOffsetType = Ix & 1;\r
-    psDec->typeOffsetPrev      = Ix;\r
-\r
-    /****************/\r
-    /* Decode gains */\r
-    /****************/\r
-    /* first subframe */    \r
-    if( psDec->nFramesDecoded == 0 ) {\r
-        /* first frame in packet: independent coding */\r
-        SKP_Silk_range_decoder( &GainsIndices[ 0 ], psRC, SKP_Silk_gain_CDF[ psDecCtrl->sigtype ], SKP_Silk_gain_CDF_offset );\r
-    } else {\r
-        /* condidtional coding */\r
-        SKP_Silk_range_decoder( &GainsIndices[ 0 ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );\r
-    }\r
-\r
-    /* remaining subframes */\r
-    for( i = 1; i < NB_SUBFR; i++ ) {\r
-        SKP_Silk_range_decoder( &GainsIndices[ i ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );\r
-    }\r
-    \r
-    /* Dequant Gains */\r
-    SKP_Silk_gains_dequant( psDecCtrl->Gains_Q16, GainsIndices, &psDec->LastGainIndex, psDec->nFramesDecoded );\r
-    /****************/\r
-    /* Decode NLSFs */\r
-    /****************/\r
-    /* Set pointer to NLSF VQ CB for the current signal type */\r
-    psNLSF_CB = psDec->psNLSF_CB[ psDecCtrl->sigtype ];\r
-\r
-    /* Range decode NLSF path */\r
-    SKP_Silk_range_decoder_multi( NLSFIndices, psRC, psNLSF_CB->StartPtr, psNLSF_CB->MiddleIx, psNLSF_CB->nStages );\r
-\r
-    /* From the NLSF path, decode an NLSF vector */\r
-    SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, NLSFIndices, psDec->LPC_order );\r
-\r
-    /************************************/\r
-    /* Decode NLSF interpolation factor */\r
-    /************************************/\r
-    SKP_Silk_range_decoder( &psDecCtrl->NLSFInterpCoef_Q2, psRC, SKP_Silk_NLSF_interpolation_factor_CDF, \r
-        SKP_Silk_NLSF_interpolation_factor_offset );\r
-    \r
-    /* If just reset, e.g., because internal Fs changed, do not allow interpolation */\r
-    /* improves the case of packet loss in the first frame after a switch           */\r
-    if( psDec->first_frame_after_reset == 1 ) {\r
-        psDecCtrl->NLSFInterpCoef_Q2 = 4;\r
-    }\r
-\r
-    if( fullDecoding ) {\r
-        /* Convert NLSF parameters to AR prediction filter coefficients */\r
-        SKP_Silk_NLSF2A_stable( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order );\r
-\r
-        if( psDecCtrl->NLSFInterpCoef_Q2 < 4 ) {\r
-            /* Calculation of the interpolated NLSF0 vector from the interpolation factor, */ \r
-            /* the previous NLSF1, and the current NLSF1                                   */\r
-            for( i = 0; i < psDec->LPC_order; i++ ) {\r
-                pNLSF0_Q15[ i ] = psDec->prevNLSF_Q15[ i ] + SKP_RSHIFT( SKP_MUL( psDecCtrl->NLSFInterpCoef_Q2, \r
-                    ( pNLSF_Q15[ i ] - psDec->prevNLSF_Q15[ i ] ) ), 2 );\r
-            }\r
-\r
-            /* Convert NLSF parameters to AR prediction filter coefficients */\r
-            SKP_Silk_NLSF2A_stable( psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order );\r
-        } else {\r
-            /* Copy LPC coefficients for first half from second half */\r
-            SKP_memcpy( psDecCtrl->PredCoef_Q12[ 0 ], psDecCtrl->PredCoef_Q12[ 1 ], \r
-                psDec->LPC_order * sizeof( SKP_int16 ) );\r
-        }\r
-    }\r
-\r
-    SKP_memcpy( psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof( SKP_int ) );\r
-\r
-    /* After a packet loss do BWE of LPC coefs */\r
-    if( psDec->lossCnt ) {\r
-        SKP_Silk_bwexpander( psDecCtrl->PredCoef_Q12[ 0 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 );\r
-        SKP_Silk_bwexpander( psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 );\r
-    }\r
-\r
-    if( psDecCtrl->sigtype == SIG_TYPE_VOICED ) {\r
-        /*********************/\r
-        /* Decode pitch lags */\r
-        /*********************/\r
-        /* Get lag index */\r
-        if( psDec->fs_kHz == 8 ) {\r
-            SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_NB_CDF,  SKP_Silk_pitch_lag_NB_CDF_offset );\r
-        } else if( psDec->fs_kHz == 12 ) {\r
-            SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_MB_CDF,  SKP_Silk_pitch_lag_MB_CDF_offset );\r
-        } else if( psDec->fs_kHz == 16 ) {\r
-            SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_WB_CDF,  SKP_Silk_pitch_lag_WB_CDF_offset );\r
-        } else {\r
-            SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_SWB_CDF, SKP_Silk_pitch_lag_SWB_CDF_offset );\r
-        }\r
-        \r
-        /* Get countour index */\r
-        if( psDec->fs_kHz == 8 ) {\r
-            /* Less codevectors used in 8 khz mode */\r
-            SKP_Silk_range_decoder( &Ixs[ 1 ], psRC, SKP_Silk_pitch_contour_NB_CDF, SKP_Silk_pitch_contour_NB_CDF_offset );\r
-        } else {\r
-            /* Joint for 12, 16, and 24 khz */\r
-            SKP_Silk_range_decoder( &Ixs[ 1 ], psRC, SKP_Silk_pitch_contour_CDF, SKP_Silk_pitch_contour_CDF_offset );\r
-        }\r
-        \r
-        /* Decode pitch values */\r
-        SKP_Silk_decode_pitch( Ixs[ 0 ], Ixs[ 1 ], psDecCtrl->pitchL, psDec->fs_kHz );\r
-\r
-        /********************/\r
-        /* Decode LTP gains */\r
-        /********************/\r
-        /* Decode PERIndex value */\r
-        SKP_Silk_range_decoder( &psDecCtrl->PERIndex, psRC, SKP_Silk_LTP_per_index_CDF, \r
-                SKP_Silk_LTP_per_index_CDF_offset );\r
-\r
-        /* Decode Codebook Index */\r
-        cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ psDecCtrl->PERIndex ]; /* set pointer to start of codebook */\r
-\r
-        for( k = 0; k < NB_SUBFR; k++ ) {\r
-            SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_LTP_gain_CDF_ptrs[ psDecCtrl->PERIndex ], \r
-                SKP_Silk_LTP_gain_CDF_offsets[ psDecCtrl->PERIndex ] );\r
-\r
-            for( i = 0; i < LTP_ORDER; i++ ) {\r
-                psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER + i ] = cbk_ptr_Q14[ Ix * LTP_ORDER + i ];\r
-            }\r
-        }\r
-\r
-        /**********************/\r
-        /* Decode LTP scaling */\r
-        /**********************/\r
-        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_LTPscale_CDF, SKP_Silk_LTPscale_offset );\r
-        psDecCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ Ix ];\r
-    } else {\r
-        SKP_assert( psDecCtrl->sigtype == SIG_TYPE_UNVOICED );\r
-        SKP_memset( psDecCtrl->pitchL,      0,             NB_SUBFR * sizeof( SKP_int   ) );\r
-        SKP_memset( psDecCtrl->LTPCoef_Q14, 0, LTP_ORDER * NB_SUBFR * sizeof( SKP_int16 ) );\r
-        psDecCtrl->PERIndex      = 0;\r
-        psDecCtrl->LTP_scale_Q14 = 0;\r
-    }\r
-\r
-    /***************/\r
-    /* Decode seed */\r
-    /***************/\r
-    SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_Seed_CDF, SKP_Silk_Seed_offset );\r
-    psDecCtrl->Seed = ( SKP_int32 )Ix;\r
-    /*********************************************/\r
-    /* Decode quantization indices of excitation */\r
-    /*********************************************/\r
-    SKP_Silk_decode_pulses( psRC, psDecCtrl, q, psDec->frame_length );\r
-\r
-    /*********************************************/\r
-    /* Decode VAD flag                           */\r
-    /*********************************************/\r
-    SKP_Silk_range_decoder( &psDec->vadFlag, psRC, SKP_Silk_vadflag_CDF, SKP_Silk_vadflag_offset );\r
-\r
-    /**************************************/\r
-    /* Decode Frame termination indicator */\r
-    /**************************************/\r
-    SKP_Silk_range_decoder( &psDec->FrameTermination, psRC, SKP_Silk_FrameTermination_CDF, SKP_Silk_FrameTermination_offset );\r
-\r
-    /****************************************/\r
-    /* get number of bytes used so far      */\r
-    /****************************************/\r
-    SKP_Silk_range_coder_get_length( psRC, &nBytesUsed );\r
-    psDec->nBytesLeft = psRC->bufferLength - nBytesUsed;\r
-    if( psDec->nBytesLeft < 0 ) {\r
-        psRC->error = RANGE_CODER_READ_BEYOND_BUFFER;\r
-    }\r
-\r
-    /****************************************/\r
-    /* check remaining bits in last byte    */\r
-    /****************************************/\r
-    if( psDec->nBytesLeft == 0 ) {\r
-        SKP_Silk_range_coder_check_after_decoding( psRC );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Decode parameters from payload */
+void SKP_Silk_decode_parameters(
+    SKP_Silk_decoder_state      *psDec,             /* I/O  State                                       */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */
+    SKP_int                     q[],                /* O    Excitation signal                           */
+    const SKP_int               fullDecoding        /* I    Flag to tell if only arithmetic decoding    */
+)
+{
+    SKP_int   i, k, Ix, fs_kHz_dec, nBytesUsed;
+    SKP_int   Ixs[ NB_SUBFR ];
+    SKP_int   GainsIndices[ NB_SUBFR ];
+    SKP_int   NLSFIndices[ NLSF_MSVQ_MAX_CB_STAGES ];
+    SKP_int   pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ];
+    const SKP_int16 *cbk_ptr_Q14;
+    const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL;
+    SKP_Silk_range_coder_state  *psRC = &psDec->sRC;
+
+    /************************/
+    /* Decode sampling rate */
+    /************************/
+    /* only done for first frame of packet */
+    if( psDec->nFramesDecoded == 0 ) {
+        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_SamplingRates_CDF, SKP_Silk_SamplingRates_offset );
+
+        /* check that sampling rate is supported */
+        if( Ix < 0 || Ix > 3 ) {
+            psRC->error = RANGE_CODER_ILLEGAL_SAMPLING_RATE;
+            return;
+        }
+        fs_kHz_dec = SKP_Silk_SamplingRates_table[ Ix ];
+        SKP_Silk_decoder_set_fs( psDec, fs_kHz_dec );
+    }
+
+    /*******************************************/
+    /* Decode signal type and quantizer offset */
+    /*******************************************/
+    if( psDec->nFramesDecoded == 0 ) {
+        /* first frame in packet: independent coding */
+        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_CDF, SKP_Silk_type_offset_CDF_offset );
+    } else {
+        /* condidtional coding */
+        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_joint_CDF[ psDec->typeOffsetPrev ], 
+                SKP_Silk_type_offset_CDF_offset );
+    }
+    psDecCtrl->sigtype         = SKP_RSHIFT( Ix, 1 );
+    psDecCtrl->QuantOffsetType = Ix & 1;
+    psDec->typeOffsetPrev      = Ix;
+
+    /****************/
+    /* Decode gains */
+    /****************/
+    /* first subframe */    
+    if( psDec->nFramesDecoded == 0 ) {
+        /* first frame in packet: independent coding */
+        SKP_Silk_range_decoder( &GainsIndices[ 0 ], psRC, SKP_Silk_gain_CDF[ psDecCtrl->sigtype ], SKP_Silk_gain_CDF_offset );
+    } else {
+        /* condidtional coding */
+        SKP_Silk_range_decoder( &GainsIndices[ 0 ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );
+    }
+
+    /* remaining subframes */
+    for( i = 1; i < NB_SUBFR; i++ ) {
+        SKP_Silk_range_decoder( &GainsIndices[ i ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );
+    }
+    
+    /* Dequant Gains */
+    SKP_Silk_gains_dequant( psDecCtrl->Gains_Q16, GainsIndices, &psDec->LastGainIndex, psDec->nFramesDecoded );
+    /****************/
+    /* Decode NLSFs */
+    /****************/
+    /* Set pointer to NLSF VQ CB for the current signal type */
+    psNLSF_CB = psDec->psNLSF_CB[ psDecCtrl->sigtype ];
+
+    /* Range decode NLSF path */
+    SKP_Silk_range_decoder_multi( NLSFIndices, psRC, psNLSF_CB->StartPtr, psNLSF_CB->MiddleIx, psNLSF_CB->nStages );
+
+    /* From the NLSF path, decode an NLSF vector */
+    SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, NLSFIndices, psDec->LPC_order );
+
+    /************************************/
+    /* Decode NLSF interpolation factor */
+    /************************************/
+    SKP_Silk_range_decoder( &psDecCtrl->NLSFInterpCoef_Q2, psRC, SKP_Silk_NLSF_interpolation_factor_CDF, 
+        SKP_Silk_NLSF_interpolation_factor_offset );
+    
+    /* If just reset, e.g., because internal Fs changed, do not allow interpolation */
+    /* improves the case of packet loss in the first frame after a switch           */
+    if( psDec->first_frame_after_reset == 1 ) {
+        psDecCtrl->NLSFInterpCoef_Q2 = 4;
+    }
+
+    if( fullDecoding ) {
+        /* Convert NLSF parameters to AR prediction filter coefficients */
+        SKP_Silk_NLSF2A_stable( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order );
+
+        if( psDecCtrl->NLSFInterpCoef_Q2 < 4 ) {
+            /* Calculation of the interpolated NLSF0 vector from the interpolation factor, */ 
+            /* the previous NLSF1, and the current NLSF1                                   */
+            for( i = 0; i < psDec->LPC_order; i++ ) {
+                pNLSF0_Q15[ i ] = psDec->prevNLSF_Q15[ i ] + SKP_RSHIFT( SKP_MUL( psDecCtrl->NLSFInterpCoef_Q2, 
+                    ( pNLSF_Q15[ i ] - psDec->prevNLSF_Q15[ i ] ) ), 2 );
+            }
+
+            /* Convert NLSF parameters to AR prediction filter coefficients */
+            SKP_Silk_NLSF2A_stable( psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order );
+        } else {
+            /* Copy LPC coefficients for first half from second half */
+            SKP_memcpy( psDecCtrl->PredCoef_Q12[ 0 ], psDecCtrl->PredCoef_Q12[ 1 ], 
+                psDec->LPC_order * sizeof( SKP_int16 ) );
+        }
+    }
+
+    SKP_memcpy( psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof( SKP_int ) );
+
+    /* After a packet loss do BWE of LPC coefs */
+    if( psDec->lossCnt ) {
+        SKP_Silk_bwexpander( psDecCtrl->PredCoef_Q12[ 0 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 );
+        SKP_Silk_bwexpander( psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 );
+    }
+
+    if( psDecCtrl->sigtype == SIG_TYPE_VOICED ) {
+        /*********************/
+        /* Decode pitch lags */
+        /*********************/
+        /* Get lag index */
+        if( psDec->fs_kHz == 8 ) {
+            SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_NB_CDF,  SKP_Silk_pitch_lag_NB_CDF_offset );
+        } else if( psDec->fs_kHz == 12 ) {
+            SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_MB_CDF,  SKP_Silk_pitch_lag_MB_CDF_offset );
+        } else if( psDec->fs_kHz == 16 ) {
+            SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_WB_CDF,  SKP_Silk_pitch_lag_WB_CDF_offset );
+        } else {
+            SKP_Silk_range_decoder( &Ixs[ 0 ], psRC, SKP_Silk_pitch_lag_SWB_CDF, SKP_Silk_pitch_lag_SWB_CDF_offset );
+        }
+        
+        /* Get countour index */
+        if( psDec->fs_kHz == 8 ) {
+            /* Less codevectors used in 8 khz mode */
+            SKP_Silk_range_decoder( &Ixs[ 1 ], psRC, SKP_Silk_pitch_contour_NB_CDF, SKP_Silk_pitch_contour_NB_CDF_offset );
+        } else {
+            /* Joint for 12, 16, and 24 khz */
+            SKP_Silk_range_decoder( &Ixs[ 1 ], psRC, SKP_Silk_pitch_contour_CDF, SKP_Silk_pitch_contour_CDF_offset );
+        }
+        
+        /* Decode pitch values */
+        SKP_Silk_decode_pitch( Ixs[ 0 ], Ixs[ 1 ], psDecCtrl->pitchL, psDec->fs_kHz );
+
+        /********************/
+        /* Decode LTP gains */
+        /********************/
+        /* Decode PERIndex value */
+        SKP_Silk_range_decoder( &psDecCtrl->PERIndex, psRC, SKP_Silk_LTP_per_index_CDF, 
+                SKP_Silk_LTP_per_index_CDF_offset );
+
+        /* Decode Codebook Index */
+        cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ psDecCtrl->PERIndex ]; /* set pointer to start of codebook */
+
+        for( k = 0; k < NB_SUBFR; k++ ) {
+            SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_LTP_gain_CDF_ptrs[ psDecCtrl->PERIndex ], 
+                SKP_Silk_LTP_gain_CDF_offsets[ psDecCtrl->PERIndex ] );
+
+            for( i = 0; i < LTP_ORDER; i++ ) {
+                psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER + i ] = cbk_ptr_Q14[ Ix * LTP_ORDER + i ];
+            }
+        }
+
+        /**********************/
+        /* Decode LTP scaling */
+        /**********************/
+        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_LTPscale_CDF, SKP_Silk_LTPscale_offset );
+        psDecCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ Ix ];
+    } else {
+        SKP_assert( psDecCtrl->sigtype == SIG_TYPE_UNVOICED );
+        SKP_memset( psDecCtrl->pitchL,      0,             NB_SUBFR * sizeof( SKP_int   ) );
+        SKP_memset( psDecCtrl->LTPCoef_Q14, 0, LTP_ORDER * NB_SUBFR * sizeof( SKP_int16 ) );
+        psDecCtrl->PERIndex      = 0;
+        psDecCtrl->LTP_scale_Q14 = 0;
+    }
+
+    /***************/
+    /* Decode seed */
+    /***************/
+    SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_Seed_CDF, SKP_Silk_Seed_offset );
+    psDecCtrl->Seed = ( SKP_int32 )Ix;
+    /*********************************************/
+    /* Decode quantization indices of excitation */
+    /*********************************************/
+    SKP_Silk_decode_pulses( psRC, psDecCtrl, q, psDec->frame_length );
+
+    /*********************************************/
+    /* Decode VAD flag                           */
+    /*********************************************/
+    SKP_Silk_range_decoder( &psDec->vadFlag, psRC, SKP_Silk_vadflag_CDF, SKP_Silk_vadflag_offset );
+
+    /**************************************/
+    /* Decode Frame termination indicator */
+    /**************************************/
+    SKP_Silk_range_decoder( &psDec->FrameTermination, psRC, SKP_Silk_FrameTermination_CDF, SKP_Silk_FrameTermination_offset );
+
+    /****************************************/
+    /* get number of bytes used so far      */
+    /****************************************/
+    SKP_Silk_range_coder_get_length( psRC, &nBytesUsed );
+    psDec->nBytesLeft = psRC->bufferLength - nBytesUsed;
+    if( psDec->nBytesLeft < 0 ) {
+        psRC->error = RANGE_CODER_READ_BEYOND_BUFFER;
+    }
+
+    /****************************************/
+    /* check remaining bits in last byte    */
+    /****************************************/
+    if( psDec->nBytesLeft == 0 ) {
+        SKP_Silk_range_coder_check_after_decoding( psRC );
+    }
+}
index d625996c14f7a0a460bb5b2d7a65914951173441..f95266457b485fd67941f717362c322327580d99 100644 (file)
@@ -1,57 +1,57 @@
-/***********************************************************************\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
-* Pitch analyser function\r
-********************************************************** */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_common_pitch_est_defines.h"\r
-\r
-void SKP_Silk_decode_pitch(\r
-    SKP_int          lagIndex,                        /* I                             */\r
-    SKP_int          contourIndex,                    /* O                             */\r
-    SKP_int          pitch_lags[],                    /* O 4 pitch values              */\r
-    SKP_int          Fs_kHz                           /* I sampling frequency (kHz)    */\r
-)\r
-{\r
-    SKP_int lag, i, min_lag;\r
-\r
-    min_lag = SKP_SMULBB( PITCH_EST_MIN_LAG_MS, Fs_kHz );\r
-\r
-    /* Only for 24 / 16 kHz version for now */\r
-    lag = min_lag + lagIndex;\r
-    if( Fs_kHz == 8 ) {\r
-        /* Only a small codebook for 8 khz */\r
-        for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) {\r
-            pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage2[ i ][ contourIndex ];\r
-        }\r
-    } else {\r
-        for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) {\r
-            pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage3[ i ][ contourIndex ];\r
-        }\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/***********************************************************
+* Pitch analyser function
+********************************************************** */
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_common_pitch_est_defines.h"
+
+void SKP_Silk_decode_pitch(
+    SKP_int          lagIndex,                        /* I                             */
+    SKP_int          contourIndex,                    /* O                             */
+    SKP_int          pitch_lags[],                    /* O 4 pitch values              */
+    SKP_int          Fs_kHz                           /* I sampling frequency (kHz)    */
+)
+{
+    SKP_int lag, i, min_lag;
+
+    min_lag = SKP_SMULBB( PITCH_EST_MIN_LAG_MS, Fs_kHz );
+
+    /* Only for 24 / 16 kHz version for now */
+    lag = min_lag + lagIndex;
+    if( Fs_kHz == 8 ) {
+        /* Only a small codebook for 8 khz */
+        for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) {
+            pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage2[ i ][ contourIndex ];
+        }
+    } else {
+        for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) {
+            pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage3[ i ][ contourIndex ];
+        }
+    }
+}
index 5b092169bf1659d67cf727212cbf73176e9e9e02..ce2927f76304b0c3be7a72989f5785dc5c39739b 100644 (file)
-/***********************************************************************\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
-/* Decode quantization indices of excitation */\r
-/*********************************************/\r
-void SKP_Silk_decode_pulses(\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  Range coder state                           */\r
-    SKP_Silk_decoder_control        *psDecCtrl,         /* I/O  Decoder control                             */\r
-    SKP_int                         q[],                /* O    Excitation signal                           */\r
-    const SKP_int                   frame_length        /* I    Frame length (preliminary)                  */\r
-)\r
-{\r
-    SKP_int   i, j, k, iter, abs_q, nLS, bit;\r
-    SKP_int   sum_pulses[ MAX_NB_SHELL_BLOCKS ], nLshifts[ MAX_NB_SHELL_BLOCKS ];\r
-    SKP_int   *pulses_ptr;\r
-    const SKP_uint16 *cdf_ptr;\r
-    \r
-    /*********************/\r
-    /* Decode rate level */\r
-    /*********************/\r
-    SKP_Silk_range_decoder( &psDecCtrl->RateLevelIndex, psRC, \r
-            SKP_Silk_rate_levels_CDF[ psDecCtrl->sigtype ], SKP_Silk_rate_levels_CDF_offset );\r
-\r
-    /* Calculate number of shell blocks */\r
-    iter = frame_length / SHELL_CODEC_FRAME_LENGTH;\r
-    \r
-    /***************************************************/\r
-    /* Sum-Weighted-Pulses Decoding                    */\r
-    /***************************************************/\r
-    cdf_ptr = SKP_Silk_pulses_per_block_CDF[ psDecCtrl->RateLevelIndex ];\r
-    for( i = 0; i < iter; i++ ) {\r
-        nLshifts[ i ] = 0;\r
-        SKP_Silk_range_decoder( &sum_pulses[ i ], psRC, cdf_ptr, SKP_Silk_pulses_per_block_CDF_offset );\r
-\r
-        /* LSB indication */\r
-        while( sum_pulses[ i ] == ( MAX_PULSES + 1 ) ) {\r
-            nLshifts[ i ]++;\r
-            SKP_Silk_range_decoder( &sum_pulses[ i ], psRC, \r
-                    SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ], SKP_Silk_pulses_per_block_CDF_offset );\r
-        }\r
-    }\r
-    \r
-    /***************************************************/\r
-    /* Shell decoding                                  */\r
-    /***************************************************/\r
-    for( i = 0; i < iter; i++ ) {\r
-        if( sum_pulses[ i ] > 0 ) {\r
-            SKP_Silk_shell_decoder( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRC, sum_pulses[ i ] );\r
-        } else {\r
-            SKP_memset( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( SKP_int ) );\r
-        }\r
-    }\r
-\r
-    /***************************************************/\r
-    /* LSB Decoding                                    */\r
-    /***************************************************/\r
-    for( i = 0; i < iter; i++ ) {\r
-        if( nLshifts[ i ] > 0 ) {\r
-            nLS = nLshifts[ i ];\r
-            pulses_ptr = &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ];\r
-            for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) {\r
-                abs_q = pulses_ptr[ k ];\r
-                for( j = 0; j < nLS; j++ ) {\r
-                    abs_q = SKP_LSHIFT( abs_q, 1 ); \r
-                    SKP_Silk_range_decoder( &bit, psRC, SKP_Silk_lsb_CDF, 1 );\r
-                    abs_q += bit;\r
-                }\r
-                pulses_ptr[ k ] = abs_q;\r
-            }\r
-        }\r
-    }\r
-\r
-    /****************************************/\r
-    /* Decode and add signs to pulse signal */\r
-    /****************************************/\r
-    SKP_Silk_decode_signs( psRC, q, frame_length, psDecCtrl->sigtype, \r
-        psDecCtrl->QuantOffsetType, psDecCtrl->RateLevelIndex);\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/*********************************************/
+/* Decode quantization indices of excitation */
+/*********************************************/
+void SKP_Silk_decode_pulses(
+    SKP_Silk_range_coder_state      *psRC,              /* I/O  Range coder state                           */
+    SKP_Silk_decoder_control        *psDecCtrl,         /* I/O  Decoder control                             */
+    SKP_int                         q[],                /* O    Excitation signal                           */
+    const SKP_int                   frame_length        /* I    Frame length (preliminary)                  */
+)
+{
+    SKP_int   i, j, k, iter, abs_q, nLS, bit;
+    SKP_int   sum_pulses[ MAX_NB_SHELL_BLOCKS ], nLshifts[ MAX_NB_SHELL_BLOCKS ];
+    SKP_int   *pulses_ptr;
+    const SKP_uint16 *cdf_ptr;
+    
+    /*********************/
+    /* Decode rate level */
+    /*********************/
+    SKP_Silk_range_decoder( &psDecCtrl->RateLevelIndex, psRC, 
+            SKP_Silk_rate_levels_CDF[ psDecCtrl->sigtype ], SKP_Silk_rate_levels_CDF_offset );
+
+    /* Calculate number of shell blocks */
+    iter = frame_length / SHELL_CODEC_FRAME_LENGTH;
+    
+    /***************************************************/
+    /* Sum-Weighted-Pulses Decoding                    */
+    /***************************************************/
+    cdf_ptr = SKP_Silk_pulses_per_block_CDF[ psDecCtrl->RateLevelIndex ];
+    for( i = 0; i < iter; i++ ) {
+        nLshifts[ i ] = 0;
+        SKP_Silk_range_decoder( &sum_pulses[ i ], psRC, cdf_ptr, SKP_Silk_pulses_per_block_CDF_offset );
+
+        /* LSB indication */
+        while( sum_pulses[ i ] == ( MAX_PULSES + 1 ) ) {
+            nLshifts[ i ]++;
+            SKP_Silk_range_decoder( &sum_pulses[ i ], psRC, 
+                    SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ], SKP_Silk_pulses_per_block_CDF_offset );
+        }
+    }
+    
+    /***************************************************/
+    /* Shell decoding                                  */
+    /***************************************************/
+    for( i = 0; i < iter; i++ ) {
+        if( sum_pulses[ i ] > 0 ) {
+            SKP_Silk_shell_decoder( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRC, sum_pulses[ i ] );
+        } else {
+            SKP_memset( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( SKP_int ) );
+        }
+    }
+
+    /***************************************************/
+    /* LSB Decoding                                    */
+    /***************************************************/
+    for( i = 0; i < iter; i++ ) {
+        if( nLshifts[ i ] > 0 ) {
+            nLS = nLshifts[ i ];
+            pulses_ptr = &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ];
+            for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) {
+                abs_q = pulses_ptr[ k ];
+                for( j = 0; j < nLS; j++ ) {
+                    abs_q = SKP_LSHIFT( abs_q, 1 ); 
+                    SKP_Silk_range_decoder( &bit, psRC, SKP_Silk_lsb_CDF, 1 );
+                    abs_q += bit;
+                }
+                pulses_ptr[ k ] = abs_q;
+            }
+        }
+    }
+
+    /****************************************/
+    /* Decode and add signs to pulse signal */
+    /****************************************/
+    SKP_Silk_decode_signs( psRC, q, frame_length, psDecCtrl->sigtype, 
+        psDecCtrl->QuantOffsetType, psDecCtrl->RateLevelIndex);
+}
index c093d9aa3809adf982f8a336bee808c9f6e1fad5..0afeed3904d2bab74ee58aed196b669ea875bf23 100644 (file)
@@ -1,80 +1,80 @@
-/***********************************************************************\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
-/* Set decoder sampling rate */\r
-void SKP_Silk_decoder_set_fs(\r
-    SKP_Silk_decoder_state          *psDec,             /* I/O  Decoder state pointer                       */\r
-    SKP_int                         fs_kHz              /* I    Sampling frequency (kHz)                    */\r
-)\r
-{\r
-    if( psDec->fs_kHz != fs_kHz ) {\r
-        psDec->fs_kHz  = fs_kHz;\r
-        psDec->frame_length = SKP_SMULBB( FRAME_LENGTH_MS, fs_kHz );\r
-        psDec->subfr_length = SKP_SMULBB( FRAME_LENGTH_MS / NB_SUBFR, fs_kHz );\r
-        if( psDec->fs_kHz == 8 ) {\r
-            psDec->LPC_order = MIN_LPC_ORDER;\r
-            psDec->psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10;\r
-            psDec->psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_10;\r
-        } else {\r
-            psDec->LPC_order = MAX_LPC_ORDER;\r
-            psDec->psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_16;\r
-            psDec->psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16;\r
-        }\r
-        /* Reset part of the decoder state */\r
-        SKP_memset( psDec->sLPC_Q14,     0, MAX_LPC_ORDER    * sizeof( SKP_int32 ) );\r
-        SKP_memset( psDec->outBuf,       0, MAX_FRAME_LENGTH * sizeof( SKP_int16 ) );\r
-        SKP_memset( psDec->prevNLSF_Q15, 0, MAX_LPC_ORDER    * sizeof( SKP_int )   );\r
-\r
-        psDec->lagPrev                 = 100;\r
-        psDec->LastGainIndex           = 1;\r
-        psDec->prev_sigtype            = 0;\r
-        psDec->first_frame_after_reset = 1;\r
-\r
-        if( fs_kHz == 24 ) {\r
-            psDec->HP_A = SKP_Silk_Dec_A_HP_24;\r
-            psDec->HP_B = SKP_Silk_Dec_B_HP_24;\r
-        } else 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
-        } 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
-        } 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
-        } else {\r
-            /* unsupported sampling rate */\r
-            SKP_assert( 0 );\r
-        }\r
-    } \r
-\r
-    /* Check that settings are valid */\r
-    SKP_assert( psDec->frame_length > 0 && psDec->frame_length <= MAX_FRAME_LENGTH );\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Set decoder sampling rate */
+void SKP_Silk_decoder_set_fs(
+    SKP_Silk_decoder_state          *psDec,             /* I/O  Decoder state pointer                       */
+    SKP_int                         fs_kHz              /* I    Sampling frequency (kHz)                    */
+)
+{
+    if( psDec->fs_kHz != fs_kHz ) {
+        psDec->fs_kHz  = fs_kHz;
+        psDec->frame_length = SKP_SMULBB( FRAME_LENGTH_MS, fs_kHz );
+        psDec->subfr_length = SKP_SMULBB( FRAME_LENGTH_MS / NB_SUBFR, fs_kHz );
+        if( psDec->fs_kHz == 8 ) {
+            psDec->LPC_order = MIN_LPC_ORDER;
+            psDec->psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10;
+            psDec->psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_10;
+        } else {
+            psDec->LPC_order = MAX_LPC_ORDER;
+            psDec->psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_16;
+            psDec->psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16;
+        }
+        /* Reset part of the decoder state */
+        SKP_memset( psDec->sLPC_Q14,     0, MAX_LPC_ORDER    * sizeof( SKP_int32 ) );
+        SKP_memset( psDec->outBuf,       0, MAX_FRAME_LENGTH * sizeof( SKP_int16 ) );
+        SKP_memset( psDec->prevNLSF_Q15, 0, MAX_LPC_ORDER    * sizeof( SKP_int )   );
+
+        psDec->lagPrev                 = 100;
+        psDec->LastGainIndex           = 1;
+        psDec->prev_sigtype            = 0;
+        psDec->first_frame_after_reset = 1;
+
+        if( fs_kHz == 24 ) {
+            psDec->HP_A = SKP_Silk_Dec_A_HP_24;
+            psDec->HP_B = SKP_Silk_Dec_B_HP_24;
+        } else if( fs_kHz == 16 ) {
+            psDec->HP_A = SKP_Silk_Dec_A_HP_16;
+            psDec->HP_B = SKP_Silk_Dec_B_HP_16;
+        } else if( fs_kHz == 12 ) {
+            psDec->HP_A = SKP_Silk_Dec_A_HP_12;
+            psDec->HP_B = SKP_Silk_Dec_B_HP_12;
+        } else if( fs_kHz == 8 ) {
+            psDec->HP_A = SKP_Silk_Dec_A_HP_8;
+            psDec->HP_B = SKP_Silk_Dec_B_HP_8;
+        } else {
+            /* unsupported sampling rate */
+            SKP_assert( 0 );
+        }
+    } 
+
+    /* Check that settings are valid */
+    SKP_assert( psDec->frame_length > 0 && psDec->frame_length <= MAX_FRAME_LENGTH );
+}
+
index d7ed59295388e17db874d08981e563aebeae22bc..84cb98000a4ac6d2d98cb68bea8603e2e5c85655 100644 (file)
-/***********************************************************************\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
-#ifndef SKP_SILK_DEFINE_H\r
-#define SKP_SILK_DEFINE_H\r
-\r
-#include "SKP_Silk_errors.h"\r
-#include "SKP_Silk_typedef.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-\r
-#define MAX_FRAMES_PER_PACKET                   5\r
-\r
-\r
-\r
-/* Limits on bitrate */\r
-#define MIN_TARGET_RATE_BPS                     5000\r
-#define MAX_TARGET_RATE_BPS                     100000\r
-\r
-/* Transition bitrates between modes */\r
-#define SWB2WB_BITRATE_BPS                      25000\r
-#define WB2SWB_BITRATE_BPS                      30000\r
-#define WB2MB_BITRATE_BPS                       14000\r
-#define MB2WB_BITRATE_BPS                       18000\r
-#define MB2NB_BITRATE_BPS                       10000\r
-#define NB2MB_BITRATE_BPS                       14000\r
-\r
-/* Integration/hysteresis threshold for lowering internal sample frequency */\r
-/* 30000000 -> 6 sec if bitrate is 5000 bps below limit; 3 sec if bitrate is 10000 bps below limit */\r
-#define ACCUM_BITS_DIFF_THRESHOLD               30000000 \r
-#define TARGET_RATE_TAB_SZ                      8\r
-\r
-/* DTX settings                                 */\r
-#define NO_SPEECH_FRAMES_BEFORE_DTX             5       /* eq 100 ms */\r
-#define MAX_CONSECUTIVE_DTX                     20      /* eq 400 ms */\r
-\r
-#define USE_LBRR                                1\r
-\r
-/* Amount of concecutive no FEC packets before telling JB */\r
-#define NO_LBRR_THRES                           10\r
-\r
-/* Maximum delay between real packet and LBRR packet */\r
-#define MAX_LBRR_DELAY                          2\r
-#define LBRR_IDX_MASK                           1\r
-\r
-#define INBAND_FEC_MIN_RATE_BPS                 18000  /* Dont use inband FEC below this total target rate  */\r
-#define LBRR_LOSS_THRES                         1   /* Start adding LBRR at this loss rate                  */\r
-\r
-/* LBRR usage defines */\r
-#define SKP_SILK_NO_LBRR                        0   /* No LBRR information for this packet                  */\r
-#define SKP_SILK_ADD_LBRR_TO_PLUS1              1   /* Add LBRR for this packet to packet n + 1             */\r
-#define SKP_SILK_ADD_LBRR_TO_PLUS2              2   /* Add LBRR for this packet to packet n + 2             */\r
-\r
-/* Frame termination indicator defines */\r
-#define SKP_SILK_LAST_FRAME                     0   /* Last frames in packet                                */\r
-#define SKP_SILK_MORE_FRAMES                    1   /* More frames to follow this one                       */\r
-#define SKP_SILK_LBRR_VER1                      2   /* LBRR information from packet n - 1                   */\r
-#define SKP_SILK_LBRR_VER2                      3   /* LBRR information from packet n - 2                   */\r
-#define SKP_SILK_EXT_LAYER                      4   /* Extension layers added                               */\r
-\r
-/* Number of Second order Sections for SWB detection HP filter */\r
-#define NB_SOS                                  3\r
-#define HP_8_KHZ_THRES                          10          /* average energy per sample, above 8 kHz       */\r
-#define CONCEC_SWB_SMPLS_THRES                  480 * 15    /* 300 ms                                       */\r
-#define WB_DETECT_ACTIVE_SPEECH_MS_THRES        15000       /* ms of active speech needed for WB detection  */\r
-\r
-/* Low complexity setting */\r
-#define LOW_COMPLEXITY_ONLY                     0\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 some embedded platforms */\r
-#define MAX_FS_KHZ                              24 \r
-#define MAX_API_FS_KHZ                          48\r
-\r
-/* Signal Types used by silk */\r
-#define SIG_TYPE_VOICED                         0\r
-#define SIG_TYPE_UNVOICED                       1\r
-\r
-/* VAD Types used by silk */\r
-#define NO_VOICE_ACTIVITY                       0\r
-#define VOICE_ACTIVITY                          1\r
-\r
-/* Number of samples per frame */ \r
-#define FRAME_LENGTH_MS                         20\r
-#define MAX_FRAME_LENGTH                        ( FRAME_LENGTH_MS * MAX_FS_KHZ )\r
-\r
-/* Milliseconds of lookahead for pitch analysis */\r
-#define LA_PITCH_MS                             2\r
-#define LA_PITCH_MAX                            ( LA_PITCH_MS * MAX_FS_KHZ )\r
-\r
-/* Length of LPC window used in find pitch */\r
-#define FIND_PITCH_LPC_WIN_MS                   ( 20 + (LA_PITCH_MS << 1) )\r
-#define FIND_PITCH_LPC_WIN_MAX                  ( FIND_PITCH_LPC_WIN_MS * MAX_FS_KHZ )\r
-\r
-/* Order of LPC used in find pitch */\r
-#define MAX_FIND_PITCH_LPC_ORDER                16\r
-\r
-#define PITCH_EST_COMPLEXITY_HC_MODE            SKP_Silk_PITCH_EST_MAX_COMPLEX\r
-#define PITCH_EST_COMPLEXITY_MC_MODE            SKP_Silk_PITCH_EST_MID_COMPLEX\r
-#define PITCH_EST_COMPLEXITY_LC_MODE            SKP_Silk_PITCH_EST_MIN_COMPLEX\r
-\r
-/* Milliseconds of lookahead for noise shape analysis */\r
-#define LA_SHAPE_MS                             5\r
-#define LA_SHAPE_MAX                            ( LA_SHAPE_MS * MAX_FS_KHZ )\r
-\r
-/* Max length of LPC window used in noise shape analysis */\r
-#define SHAPE_LPC_WIN_MAX                       ( 15 * MAX_FS_KHZ )\r
-\r
-/* Max number of bytes in payload output buffer (may contain multiple frames) */\r
-#define MAX_ARITHM_BYTES                        1024\r
-\r
-#define RANGE_CODER_WRITE_BEYOND_BUFFER         -1\r
-#define RANGE_CODER_CDF_OUT_OF_RANGE            -2\r
-#define RANGE_CODER_NORMALIZATION_FAILED        -3\r
-#define RANGE_CODER_ZERO_INTERVAL_WIDTH         -4\r
-#define RANGE_CODER_DECODER_CHECK_FAILED        -5\r
-#define RANGE_CODER_READ_BEYOND_BUFFER          -6\r
-#define RANGE_CODER_ILLEGAL_SAMPLING_RATE       -7\r
-#define RANGE_CODER_DEC_PAYLOAD_TOO_LONG        -8\r
-\r
-/* dB level of lowest gain quantization level */\r
-#define MIN_QGAIN_DB                            6\r
-/* dB level of highest gain quantization level */\r
-#define MAX_QGAIN_DB                            86\r
-/* Number of gain quantization levels */\r
-#define N_LEVELS_QGAIN                          64\r
-/* Max increase in gain quantization index */\r
-#define MAX_DELTA_GAIN_QUANT                    40\r
-/* Max decrease in gain quantization index */\r
-#define MIN_DELTA_GAIN_QUANT                    -4\r
-\r
-/* Quantization offsets (multiples of 4) */\r
-#define OFFSET_VL_Q10                           32\r
-#define OFFSET_VH_Q10                           100\r
-#define OFFSET_UVL_Q10                          100\r
-#define OFFSET_UVH_Q10                          256\r
-\r
-/* Maximum numbers of iterations used to stabilize a LPC vector */\r
-#define MAX_LPC_STABILIZE_ITERATIONS            20\r
-\r
-#define MAX_LPC_ORDER                           16\r
-#define MIN_LPC_ORDER                           10\r
-\r
-/* Find Pred Coef defines */\r
-#define LTP_ORDER                               5\r
-\r
-/* LTP quantization settings */\r
-#define NB_LTP_CBKS                             3\r
-\r
-/* Number of subframes */\r
-#define NB_SUBFR                                4\r
-\r
-/* Flag to use harmonic noise shaping */\r
-#define USE_HARM_SHAPING                        1\r
-\r
-/* Max LPC order of noise shaping filters */\r
-#define MAX_SHAPE_LPC_ORDER                     16\r
-\r
-#define HARM_SHAPE_FIR_TAPS                     3\r
-\r
-/* Maximum number of delayed decision states */\r
-#define MAX_DEL_DEC_STATES                      4\r
-\r
-#define LTP_BUF_LENGTH                          512\r
-#define LTP_MASK                                (LTP_BUF_LENGTH - 1)\r
-\r
-#define DECISION_DELAY                          32\r
-#define DECISION_DELAY_MASK                     (DECISION_DELAY - 1)\r
-\r
-/* number of subframes for excitation entropy coding */\r
-#define SHELL_CODEC_FRAME_LENGTH                16\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
-#define N_RATE_LEVELS                           10\r
-\r
-/* maximum sum of pulses per shell coding frame */\r
-#define MAX_PULSES                              18\r
-\r
-#define MAX_MATRIX_SIZE                         MAX_LPC_ORDER /* Max of LPC Order and LTP order */\r
-\r
-#if( MAX_LPC_ORDER > DECISION_DELAY )\r
-# define NSQ_LPC_BUF_LENGTH                     MAX_LPC_ORDER\r
-#else\r
-# define NSQ_LPC_BUF_LENGTH                     DECISION_DELAY\r
-#endif\r
-\r
-/***********************/\r
-/* High pass filtering */\r
-/***********************/\r
-#define HIGH_PASS_INPUT                         1\r
-\r
-/***************************/\r
-/* Voice activity detector */\r
-/***************************/\r
-#define VAD_N_BANDS                             4\r
-\r
-#define VAD_INTERNAL_SUBFRAMES_LOG2             2\r
-#define VAD_INTERNAL_SUBFRAMES                  (1 << VAD_INTERNAL_SUBFRAMES_LOG2)\r
-    \r
-#define VAD_NOISE_LEVEL_SMOOTH_COEF_Q16         1024    /* Must be < 4096                                   */\r
-#define VAD_NOISE_LEVELS_BIAS                   50 \r
-\r
-/* Sigmoid settings */\r
-#define VAD_NEGATIVE_OFFSET_Q5                  128     /* sigmoid is 0 at -128                             */\r
-#define VAD_SNR_FACTOR_Q16                      45000 \r
-\r
-/* smoothing for SNR measurement */\r
-#define VAD_SNR_SMOOTH_COEF_Q18                 4096\r
-\r
-/******************/\r
-/* NLSF quantizer */\r
-/******************/\r
-#   define NLSF_MSVQ_MAX_CB_STAGES                      10  /* Update manually when changing codebooks      */\r
-#   define NLSF_MSVQ_MAX_VECTORS_IN_STAGE               128 /* Update manually when changing codebooks      */\r
-#   define NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END    16  /* Update manually when changing codebooks      */\r
-\r
-#define NLSF_MSVQ_FLUCTUATION_REDUCTION         1\r
-#define MAX_NLSF_MSVQ_SURVIVORS                 16\r
-#define MAX_NLSF_MSVQ_SURVIVORS_LC_MODE         2\r
-#define MAX_NLSF_MSVQ_SURVIVORS_MC_MODE         4\r
-\r
-/* Based on above defines, calculate how much memory is necessary to allocate */\r
-#if( NLSF_MSVQ_MAX_VECTORS_IN_STAGE > ( MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END ) )\r
-#   define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED_LC_MODE  NLSF_MSVQ_MAX_VECTORS_IN_STAGE\r
-#else\r
-#   define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED_LC_MODE  MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END\r
-#endif\r
-\r
-#if( NLSF_MSVQ_MAX_VECTORS_IN_STAGE > ( MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END ) )\r
-#   define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED  NLSF_MSVQ_MAX_VECTORS_IN_STAGE\r
-#else\r
-#   define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED  MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END\r
-#endif\r
-\r
-#define NLSF_MSVQ_SURV_MAX_REL_RD               0.1f    /* Must be < 0.5                                    */\r
-\r
-/* Transition filtering for mode switching */\r
-#if SWITCH_TRANSITION_FILTERING\r
-#  define TRANSITION_TIME_UP_MS                 5120 // 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4)\r
-#  define TRANSITION_TIME_DOWN_MS               2560 // 2560 = 32 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 32*(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_UP                  ( TRANSITION_TIME_UP_MS   / FRAME_LENGTH_MS )\r
-#  define TRANSITION_FRAMES_DOWN                ( TRANSITION_TIME_DOWN_MS / FRAME_LENGTH_MS )\r
-#  define TRANSITION_INT_STEPS_UP               ( TRANSITION_FRAMES_UP    / ( TRANSITION_INT_NUM - 1 )  )\r
-#  define TRANSITION_INT_STEPS_DOWN             ( TRANSITION_FRAMES_DOWN  / ( TRANSITION_INT_NUM - 1 )  )\r
-#endif\r
-\r
-/* Row based */\r
-#define matrix_ptr(Matrix_base_adr, row, column, N)         *(Matrix_base_adr + ((row)*(N)+(column)))\r
-#define matrix_adr(Matrix_base_adr, row, column, N)          (Matrix_base_adr + ((row)*(N)+(column)))\r
-\r
-/* Column based */\r
-#ifndef matrix_c_ptr\r
-#   define matrix_c_ptr(Matrix_base_adr, row, column, M)    *(Matrix_base_adr + ((row)+(M)*(column)))\r
-#endif\r
-#define matrix_c_adr(Matrix_base_adr, row, column, M)        (Matrix_base_adr + ((row)+(M)*(column)))\r
-\r
-/* BWE factors to apply after packet loss */\r
-#define BWE_AFTER_LOSS_Q16                      63570\r
-\r
-/* Defines for CN generation */\r
-#define CNG_BUF_MASK_MAX                        255             /* 2^floor(log2(MAX_FRAME_LENGTH))-1    */\r
-#define CNG_GAIN_SMTH_Q16                       4634            /* 0.25^(1/4)                           */\r
-#define CNG_NLSF_SMTH_Q16                       16348           /* 0.25                                 */\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_DEFINE_H
+#define SKP_SILK_DEFINE_H
+
+#include "SKP_Silk_errors.h"
+#include "SKP_Silk_typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#define MAX_FRAMES_PER_PACKET                   5
+
+
+
+/* Limits on bitrate */
+#define MIN_TARGET_RATE_BPS                     5000
+#define MAX_TARGET_RATE_BPS                     100000
+
+/* Transition bitrates between modes */
+#define SWB2WB_BITRATE_BPS                      25000
+#define WB2SWB_BITRATE_BPS                      30000
+#define WB2MB_BITRATE_BPS                       14000
+#define MB2WB_BITRATE_BPS                       18000
+#define MB2NB_BITRATE_BPS                       10000
+#define NB2MB_BITRATE_BPS                       14000
+
+/* Integration/hysteresis threshold for lowering internal sample frequency */
+/* 30000000 -> 6 sec if bitrate is 5000 bps below limit; 3 sec if bitrate is 10000 bps below limit */
+#define ACCUM_BITS_DIFF_THRESHOLD               30000000 
+#define TARGET_RATE_TAB_SZ                      8
+
+/* DTX settings                                 */
+#define NO_SPEECH_FRAMES_BEFORE_DTX             5       /* eq 100 ms */
+#define MAX_CONSECUTIVE_DTX                     20      /* eq 400 ms */
+
+#define USE_LBRR                                1
+
+/* Amount of concecutive no FEC packets before telling JB */
+#define NO_LBRR_THRES                           10
+
+/* Maximum delay between real packet and LBRR packet */
+#define MAX_LBRR_DELAY                          2
+#define LBRR_IDX_MASK                           1
+
+#define INBAND_FEC_MIN_RATE_BPS                 18000  /* Dont use inband FEC below this total target rate  */
+#define LBRR_LOSS_THRES                         1   /* Start adding LBRR at this loss rate                  */
+
+/* LBRR usage defines */
+#define SKP_SILK_NO_LBRR                        0   /* No LBRR information for this packet                  */
+#define SKP_SILK_ADD_LBRR_TO_PLUS1              1   /* Add LBRR for this packet to packet n + 1             */
+#define SKP_SILK_ADD_LBRR_TO_PLUS2              2   /* Add LBRR for this packet to packet n + 2             */
+
+/* Frame termination indicator defines */
+#define SKP_SILK_LAST_FRAME                     0   /* Last frames in packet                                */
+#define SKP_SILK_MORE_FRAMES                    1   /* More frames to follow this one                       */
+#define SKP_SILK_LBRR_VER1                      2   /* LBRR information from packet n - 1                   */
+#define SKP_SILK_LBRR_VER2                      3   /* LBRR information from packet n - 2                   */
+#define SKP_SILK_EXT_LAYER                      4   /* Extension layers added                               */
+
+/* Number of Second order Sections for SWB detection HP filter */
+#define NB_SOS                                  3
+#define HP_8_KHZ_THRES                          10          /* average energy per sample, above 8 kHz       */
+#define CONCEC_SWB_SMPLS_THRES                  480 * 15    /* 300 ms                                       */
+#define WB_DETECT_ACTIVE_SPEECH_MS_THRES        15000       /* ms of active speech needed for WB detection  */
+
+/* Low complexity setting */
+#define LOW_COMPLEXITY_ONLY                     0
+
+/* Activate bandwidth transition filtering for mode switching */
+#define SWITCH_TRANSITION_FILTERING             1
+
+/* Decoder Parameters */
+#define DEC_HP_ORDER                            2
+
+/* Maximum sampling frequency, should be 16 for some embedded platforms */
+#define MAX_FS_KHZ                              24 
+#define MAX_API_FS_KHZ                          48
+
+/* Signal Types used by silk */
+#define SIG_TYPE_VOICED                         0
+#define SIG_TYPE_UNVOICED                       1
+
+/* VAD Types used by silk */
+#define NO_VOICE_ACTIVITY                       0
+#define VOICE_ACTIVITY                          1
+
+/* Number of samples per frame */ 
+#define FRAME_LENGTH_MS                         20
+#define MAX_FRAME_LENGTH                        ( FRAME_LENGTH_MS * MAX_FS_KHZ )
+
+/* Milliseconds of lookahead for pitch analysis */
+#define LA_PITCH_MS                             2
+#define LA_PITCH_MAX                            ( LA_PITCH_MS * MAX_FS_KHZ )
+
+/* Length of LPC window used in find pitch */
+#define FIND_PITCH_LPC_WIN_MS                   ( 20 + (LA_PITCH_MS << 1) )
+#define FIND_PITCH_LPC_WIN_MAX                  ( FIND_PITCH_LPC_WIN_MS * MAX_FS_KHZ )
+
+/* Order of LPC used in find pitch */
+#define MAX_FIND_PITCH_LPC_ORDER                16
+
+#define PITCH_EST_COMPLEXITY_HC_MODE            SKP_Silk_PITCH_EST_MAX_COMPLEX
+#define PITCH_EST_COMPLEXITY_MC_MODE            SKP_Silk_PITCH_EST_MID_COMPLEX
+#define PITCH_EST_COMPLEXITY_LC_MODE            SKP_Silk_PITCH_EST_MIN_COMPLEX
+
+/* Milliseconds of lookahead for noise shape analysis */
+#define LA_SHAPE_MS                             5
+#define LA_SHAPE_MAX                            ( LA_SHAPE_MS * MAX_FS_KHZ )
+
+/* Max length of LPC window used in noise shape analysis */
+#define SHAPE_LPC_WIN_MAX                       ( 15 * MAX_FS_KHZ )
+
+/* Max number of bytes in payload output buffer (may contain multiple frames) */
+#define MAX_ARITHM_BYTES                        1024
+
+#define RANGE_CODER_WRITE_BEYOND_BUFFER         -1
+#define RANGE_CODER_CDF_OUT_OF_RANGE            -2
+#define RANGE_CODER_NORMALIZATION_FAILED        -3
+#define RANGE_CODER_ZERO_INTERVAL_WIDTH         -4
+#define RANGE_CODER_DECODER_CHECK_FAILED        -5
+#define RANGE_CODER_READ_BEYOND_BUFFER          -6
+#define RANGE_CODER_ILLEGAL_SAMPLING_RATE       -7
+#define RANGE_CODER_DEC_PAYLOAD_TOO_LONG        -8
+
+/* dB level of lowest gain quantization level */
+#define MIN_QGAIN_DB                            6
+/* dB level of highest gain quantization level */
+#define MAX_QGAIN_DB                            86
+/* Number of gain quantization levels */
+#define N_LEVELS_QGAIN                          64
+/* Max increase in gain quantization index */
+#define MAX_DELTA_GAIN_QUANT                    40
+/* Max decrease in gain quantization index */
+#define MIN_DELTA_GAIN_QUANT                    -4
+
+/* Quantization offsets (multiples of 4) */
+#define OFFSET_VL_Q10                           32
+#define OFFSET_VH_Q10                           100
+#define OFFSET_UVL_Q10                          100
+#define OFFSET_UVH_Q10                          256
+
+/* Maximum numbers of iterations used to stabilize a LPC vector */
+#define MAX_LPC_STABILIZE_ITERATIONS            20
+
+#define MAX_LPC_ORDER                           16
+#define MIN_LPC_ORDER                           10
+
+/* Find Pred Coef defines */
+#define LTP_ORDER                               5
+
+/* LTP quantization settings */
+#define NB_LTP_CBKS                             3
+
+/* Number of subframes */
+#define NB_SUBFR                                4
+
+/* Flag to use harmonic noise shaping */
+#define USE_HARM_SHAPING                        1
+
+/* Max LPC order of noise shaping filters */
+#define MAX_SHAPE_LPC_ORDER                     16
+
+#define HARM_SHAPE_FIR_TAPS                     3
+
+/* Maximum number of delayed decision states */
+#define MAX_DEL_DEC_STATES                      4
+
+#define LTP_BUF_LENGTH                          512
+#define LTP_MASK                                (LTP_BUF_LENGTH - 1)
+
+#define DECISION_DELAY                          32
+#define DECISION_DELAY_MASK                     (DECISION_DELAY - 1)
+
+/* number of subframes for excitation entropy coding */
+#define SHELL_CODEC_FRAME_LENGTH                16
+#define MAX_NB_SHELL_BLOCKS                     (MAX_FRAME_LENGTH / SHELL_CODEC_FRAME_LENGTH)
+
+/* number of rate levels, for entropy coding of excitation */
+#define N_RATE_LEVELS                           10
+
+/* maximum sum of pulses per shell coding frame */
+#define MAX_PULSES                              18
+
+#define MAX_MATRIX_SIZE                         MAX_LPC_ORDER /* Max of LPC Order and LTP order */
+
+#if( MAX_LPC_ORDER > DECISION_DELAY )
+# define NSQ_LPC_BUF_LENGTH                     MAX_LPC_ORDER
+#else
+# define NSQ_LPC_BUF_LENGTH                     DECISION_DELAY
+#endif
+
+/***********************/
+/* High pass filtering */
+/***********************/
+#define HIGH_PASS_INPUT                         1
+
+/***************************/
+/* Voice activity detector */
+/***************************/
+#define VAD_N_BANDS                             4
+
+#define VAD_INTERNAL_SUBFRAMES_LOG2             2
+#define VAD_INTERNAL_SUBFRAMES                  (1 << VAD_INTERNAL_SUBFRAMES_LOG2)
+    
+#define VAD_NOISE_LEVEL_SMOOTH_COEF_Q16         1024    /* Must be < 4096                                   */
+#define VAD_NOISE_LEVELS_BIAS                   50 
+
+/* Sigmoid settings */
+#define VAD_NEGATIVE_OFFSET_Q5                  128     /* sigmoid is 0 at -128                             */
+#define VAD_SNR_FACTOR_Q16                      45000 
+
+/* smoothing for SNR measurement */
+#define VAD_SNR_SMOOTH_COEF_Q18                 4096
+
+/******************/
+/* NLSF quantizer */
+/******************/
+#   define NLSF_MSVQ_MAX_CB_STAGES                      10  /* Update manually when changing codebooks      */
+#   define NLSF_MSVQ_MAX_VECTORS_IN_STAGE               128 /* Update manually when changing codebooks      */
+#   define NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END    16  /* Update manually when changing codebooks      */
+
+#define NLSF_MSVQ_FLUCTUATION_REDUCTION         1
+#define MAX_NLSF_MSVQ_SURVIVORS                 16
+#define MAX_NLSF_MSVQ_SURVIVORS_LC_MODE         2
+#define MAX_NLSF_MSVQ_SURVIVORS_MC_MODE         4
+
+/* Based on above defines, calculate how much memory is necessary to allocate */
+#if( NLSF_MSVQ_MAX_VECTORS_IN_STAGE > ( MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END ) )
+#   define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED_LC_MODE  NLSF_MSVQ_MAX_VECTORS_IN_STAGE
+#else
+#   define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED_LC_MODE  MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END
+#endif
+
+#if( NLSF_MSVQ_MAX_VECTORS_IN_STAGE > ( MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END ) )
+#   define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED  NLSF_MSVQ_MAX_VECTORS_IN_STAGE
+#else
+#   define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED  MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END
+#endif
+
+#define NLSF_MSVQ_SURV_MAX_REL_RD               0.1f    /* Must be < 0.5                                    */
+
+/* Transition filtering for mode switching */
+#if SWITCH_TRANSITION_FILTERING
+#  define TRANSITION_TIME_UP_MS                 5120 // 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4)
+#  define TRANSITION_TIME_DOWN_MS               2560 // 2560 = 32 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 32*(20*4)
+#  define TRANSITION_NB                         3 /* Hardcoded in tables */
+#  define TRANSITION_NA                         2 /* Hardcoded in tables */
+#  define TRANSITION_INT_NUM                    5 /* Hardcoded in tables */
+#  define TRANSITION_FRAMES_UP                  ( TRANSITION_TIME_UP_MS   / FRAME_LENGTH_MS )
+#  define TRANSITION_FRAMES_DOWN                ( TRANSITION_TIME_DOWN_MS / FRAME_LENGTH_MS )
+#  define TRANSITION_INT_STEPS_UP               ( TRANSITION_FRAMES_UP    / ( TRANSITION_INT_NUM - 1 )  )
+#  define TRANSITION_INT_STEPS_DOWN             ( TRANSITION_FRAMES_DOWN  / ( TRANSITION_INT_NUM - 1 )  )
+#endif
+
+/* Row based */
+#define matrix_ptr(Matrix_base_adr, row, column, N)         *(Matrix_base_adr + ((row)*(N)+(column)))
+#define matrix_adr(Matrix_base_adr, row, column, N)          (Matrix_base_adr + ((row)*(N)+(column)))
+
+/* Column based */
+#ifndef matrix_c_ptr
+#   define matrix_c_ptr(Matrix_base_adr, row, column, M)    *(Matrix_base_adr + ((row)+(M)*(column)))
+#endif
+#define matrix_c_adr(Matrix_base_adr, row, column, M)        (Matrix_base_adr + ((row)+(M)*(column)))
+
+/* BWE factors to apply after packet loss */
+#define BWE_AFTER_LOSS_Q16                      63570
+
+/* Defines for CN generation */
+#define CNG_BUF_MASK_MAX                        255             /* 2^floor(log2(MAX_FRAME_LENGTH))-1    */
+#define CNG_GAIN_SMTH_Q16                       4634            /* 0.25^(1/4)                           */
+#define CNG_NLSF_SMTH_Q16                       16348           /* 0.25                                 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index bab84509e2c73cfcf7599c94fba6d13f2fa4cb63..71b69eb85ae44f9918cf16a0684fbee1c2a0b01c 100644 (file)
@@ -1,76 +1,76 @@
-/***********************************************************************\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
- * Detect SWB input by measuring energy above 8 kHz.\r
- */\r
-\r
-#include "SKP_Silk_main.h"\r
-\r
-void SKP_Silk_detect_SWB_input(\r
-    SKP_Silk_detect_SWB_state   *psSWBdetect,   /* (I/O) encoder state  */\r
-    const SKP_int16             samplesIn[],    /* (I) input to encoder */\r
-    SKP_int                     nSamplesIn      /* (I) length of input */\r
-)\r
-{\r
-    SKP_int     HP_8_kHz_len, i, shift;\r
-    SKP_int16   in_HP_8_kHz[ MAX_FRAME_LENGTH ];\r
-    SKP_int32   energy_32;\r
-    \r
-    /* High pass filter with cutoff at 8 khz */\r
-    HP_8_kHz_len = SKP_min_int( nSamplesIn, MAX_FRAME_LENGTH );\r
-    HP_8_kHz_len = SKP_max_int( HP_8_kHz_len, 0 );\r
-\r
-    /* Cutoff around 9 khz */\r
-    /* A = conv(conv([8192,14613, 6868], [8192,12883, 7337]), [8192,11586, 7911]); */\r
-    /* B = conv(conv([575, -948, 575], [575, -221, 575]), [575, 104, 575]); */\r
-    SKP_Silk_biquad( samplesIn, SKP_Silk_SWB_detect_B_HP_Q13[ 0 ], SKP_Silk_SWB_detect_A_HP_Q13[ 0 ], \r
-        psSWBdetect->S_HP_8_kHz[ 0 ], in_HP_8_kHz, HP_8_kHz_len );\r
-    for( i = 1; i < NB_SOS; i++ ) {\r
-        SKP_Silk_biquad( in_HP_8_kHz, SKP_Silk_SWB_detect_B_HP_Q13[ i ], SKP_Silk_SWB_detect_A_HP_Q13[ i ], \r
-            psSWBdetect->S_HP_8_kHz[ i ], in_HP_8_kHz, HP_8_kHz_len );\r
-    }\r
-\r
-    /* Calculate energy in HP signal */\r
-    SKP_Silk_sum_sqr_shift( &energy_32, &shift, in_HP_8_kHz, HP_8_kHz_len );\r
-\r
-    /* Count concecutive samples above threshold, after adjusting threshold for number of input samples and shift */\r
-    if( energy_32 > SKP_RSHIFT( SKP_SMULBB( HP_8_KHZ_THRES, HP_8_kHz_len ), shift ) ) {\r
-        psSWBdetect->ConsecSmplsAboveThres += nSamplesIn;\r
-        if( psSWBdetect->ConsecSmplsAboveThres > CONCEC_SWB_SMPLS_THRES ) {\r
-            psSWBdetect->SWB_detected = 1;\r
-        }\r
-    } else {\r
-        psSWBdetect->ConsecSmplsAboveThres -= nSamplesIn;\r
-        psSWBdetect->ConsecSmplsAboveThres = SKP_max( psSWBdetect->ConsecSmplsAboveThres, 0 );\r
-    }\r
-\r
-    /* If sufficient speech activity and no SWB detected, we detect the signal as being WB */\r
-    if( ( psSWBdetect->ActiveSpeech_ms > WB_DETECT_ACTIVE_SPEECH_MS_THRES ) && ( psSWBdetect->SWB_detected == 0 ) ) {\r
-        psSWBdetect->WB_detected = 1;\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*
+ * Detect SWB input by measuring energy above 8 kHz.
+ */
+
+#include "SKP_Silk_main.h"
+
+void SKP_Silk_detect_SWB_input(
+    SKP_Silk_detect_SWB_state   *psSWBdetect,   /* (I/O) encoder state  */
+    const SKP_int16             samplesIn[],    /* (I) input to encoder */
+    SKP_int                     nSamplesIn      /* (I) length of input */
+)
+{
+    SKP_int     HP_8_kHz_len, i, shift;
+    SKP_int16   in_HP_8_kHz[ MAX_FRAME_LENGTH ];
+    SKP_int32   energy_32;
+    
+    /* High pass filter with cutoff at 8 khz */
+    HP_8_kHz_len = SKP_min_int( nSamplesIn, MAX_FRAME_LENGTH );
+    HP_8_kHz_len = SKP_max_int( HP_8_kHz_len, 0 );
+
+    /* Cutoff around 9 khz */
+    /* A = conv(conv([8192,14613, 6868], [8192,12883, 7337]), [8192,11586, 7911]); */
+    /* B = conv(conv([575, -948, 575], [575, -221, 575]), [575, 104, 575]); */
+    SKP_Silk_biquad( samplesIn, SKP_Silk_SWB_detect_B_HP_Q13[ 0 ], SKP_Silk_SWB_detect_A_HP_Q13[ 0 ], 
+        psSWBdetect->S_HP_8_kHz[ 0 ], in_HP_8_kHz, HP_8_kHz_len );
+    for( i = 1; i < NB_SOS; i++ ) {
+        SKP_Silk_biquad( in_HP_8_kHz, SKP_Silk_SWB_detect_B_HP_Q13[ i ], SKP_Silk_SWB_detect_A_HP_Q13[ i ], 
+            psSWBdetect->S_HP_8_kHz[ i ], in_HP_8_kHz, HP_8_kHz_len );
+    }
+
+    /* Calculate energy in HP signal */
+    SKP_Silk_sum_sqr_shift( &energy_32, &shift, in_HP_8_kHz, HP_8_kHz_len );
+
+    /* Count concecutive samples above threshold, after adjusting threshold for number of input samples and shift */
+    if( energy_32 > SKP_RSHIFT( SKP_SMULBB( HP_8_KHZ_THRES, HP_8_kHz_len ), shift ) ) {
+        psSWBdetect->ConsecSmplsAboveThres += nSamplesIn;
+        if( psSWBdetect->ConsecSmplsAboveThres > CONCEC_SWB_SMPLS_THRES ) {
+            psSWBdetect->SWB_detected = 1;
+        }
+    } else {
+        psSWBdetect->ConsecSmplsAboveThres -= nSamplesIn;
+        psSWBdetect->ConsecSmplsAboveThres = SKP_max( psSWBdetect->ConsecSmplsAboveThres, 0 );
+    }
+
+    /* If sufficient speech activity and no SWB detected, we detect the signal as being WB */
+    if( ( psSWBdetect->ActiveSpeech_ms > WB_DETECT_ACTIVE_SPEECH_MS_THRES ) && ( psSWBdetect->SWB_detected == 0 ) ) {
+        psSWBdetect->WB_detected = 1;
+    }
+}
index 232e31aa5ff88c90f18ce5cbda5a27e22ef25f76..32b86f68151a2bfe9dea3e703c4ec6545f315f6c 100644 (file)
-/***********************************************************************\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
-#include "SKP_Silk_define.h"\r
-#include "SKP_Silk_main_FIX.h"\r
-#include "SKP_Silk_SDK_API.h"\r
-#include "SKP_Silk_control.h"\r
-#include "SKP_Silk_typedef.h"\r
-#include "SKP_Silk_structs.h"\r
-#define SKP_Silk_EncodeControlStruct SKP_SILK_SDK_EncControlStruct\r
-\r
-/****************************************/\r
-/* Encoder functions                    */\r
-/****************************************/\r
-\r
-SKP_int SKP_Silk_SDK_Get_Encoder_Size( SKP_int32 *encSizeBytes )\r
-{\r
-    SKP_int ret = 0;\r
-    \r
-    *encSizeBytes = sizeof( SKP_Silk_encoder_state_FIX );\r
-    \r
-    return ret;\r
-}\r
-\r
-\r
-/***************************************/\r
-/* Read control structure from encoder */\r
-/***************************************/\r
-SKP_int SKP_Silk_SDK_QueryEncoder(\r
-    const void *encState,                       /* I:   State Vector                                    */\r
-    SKP_Silk_EncodeControlStruct *encStatus     /* O:   Control Structure                               */\r
-)\r
-{\r
-    SKP_Silk_encoder_state_FIX *psEnc;\r
-    SKP_int ret = 0;\r
-\r
-    psEnc = ( SKP_Silk_encoder_state_FIX* )encState;\r
-\r
-    encStatus->API_sampleRate        = psEnc->sCmn.API_fs_Hz;\r
-    encStatus->maxInternalSampleRate = SKP_SMULBB( psEnc->sCmn.maxInternal_fs_kHz, 1000 );\r
-    encStatus->packetSize            = ( SKP_int )SKP_DIV32_16( psEnc->sCmn.API_fs_Hz * psEnc->sCmn.PacketSize_ms, 1000 );  /* convert samples -> 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
-    return ret;\r
-}\r
-\r
-/*************************/\r
-/* Init or Reset encoder */\r
-/*************************/\r
-SKP_int SKP_Silk_SDK_InitEncoder(\r
-    void                            *encState,          /* I/O: State                                           */\r
-    SKP_Silk_EncodeControlStruct    *encStatus          /* O:   Control structure                               */\r
-)\r
-{\r
-    SKP_Silk_encoder_state_FIX *psEnc;\r
-    SKP_int ret = 0;\r
-\r
-        \r
-    psEnc = ( SKP_Silk_encoder_state_FIX* )encState;\r
-\r
-    /* Reset Encoder */\r
-    if( ret += SKP_Silk_init_encoder_FIX( psEnc ) ) {\r
-        SKP_assert( 0 );\r
-    }\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
-/**************************/\r
-/* Encode frame with Silk */\r
-/**************************/\r
-SKP_int SKP_Silk_SDK_Encode( \r
-    void                                *encState,      /* I/O: State                                           */\r
-    const SKP_Silk_EncodeControlStruct  *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
-    SKP_uint8                           *outData,       /* O:   Encoded output vector                           */\r
-    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in outData (input: Max bytes)   */\r
-)\r
-{\r
-    SKP_int   max_internal_fs_kHz, PacketSize_ms, PacketLoss_perc, UseInBandFEC, UseDTX, ret = 0;\r
-    SKP_int   nSamplesToBuffer, Complexity, input_10ms, nSamplesFromInput = 0;\r
-    SKP_int32 TargetRate_bps, API_fs_Hz;\r
-    SKP_int16 MaxBytesOut;\r
-    SKP_Silk_encoder_state_FIX *psEnc = ( SKP_Silk_encoder_state_FIX* )encState;\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->maxInternalSampleRate != 24000 ) ) ) {\r
-        ret = SKP_SILK_ENC_FS_NOT_SUPPORTED;\r
-        SKP_assert( 0 );\r
-        return( ret );\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
-    PacketSize_ms       = SKP_DIV32( 1000 * (SKP_int)encControl->packetSize, API_fs_Hz );\r
-    TargetRate_bps      =                            encControl->bitRate;\r
-    PacketLoss_perc     =                            encControl->packetLossPercentage;\r
-    UseInBandFEC        =                            encControl->useInBandFEC;\r
-    Complexity          =                            encControl->complexity;\r
-    UseDTX              =                            encControl->useDTX;\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.useInBandFEC       = UseInBandFEC;\r
-\r
-    /* Only accept input lengths that are a multiple of 10 ms */\r
-    input_10ms = SKP_DIV32( 100 * nSamplesIn, API_fs_Hz );\r
-    if( input_10ms * API_fs_Hz != 100 * nSamplesIn || nSamplesIn < 0 ) {\r
-        ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;\r
-        SKP_assert( 0 );\r
-        return( ret );\r
-    }\r
-\r
-    TargetRate_bps = SKP_LIMIT( TargetRate_bps, MIN_TARGET_RATE_BPS, MAX_TARGET_RATE_BPS );\r
-    if( ( ret = SKP_Silk_control_encoder_FIX( psEnc, PacketSize_ms, TargetRate_bps, \r
-                        PacketLoss_perc, UseDTX, Complexity) ) != 0 ) {\r
-        SKP_assert( 0 );\r
-        return( ret );\r
-    }\r
-\r
-    /* Make sure no more than one packet can be produced */\r
-    if( 1000 * (SKP_int32)nSamplesIn > psEnc->sCmn.PacketSize_ms * API_fs_Hz ) {\r
-        ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;\r
-        SKP_assert( 0 );\r
-        return( ret );\r
-    }\r
-\r
-#if MAX_FS_KHZ > 16\r
-    /* Detect energy above 8 kHz */\r
-    if( SKP_min( API_fs_Hz, 1000 * max_internal_fs_kHz ) == 24000 && \r
-            psEnc->sCmn.sSWBdetect.SWB_detected == 0 && \r
-            psEnc->sCmn.sSWBdetect.WB_detected == 0 ) {\r
-        SKP_Silk_detect_SWB_input( &psEnc->sCmn.sSWBdetect, samplesIn, ( SKP_int )nSamplesIn );\r
-    }\r
-#endif\r
-\r
-    /* Input buffering/resampling and encoding */\r
-    MaxBytesOut = 0;                    /* return 0 output bytes if no encoder called */\r
-    while( 1 ) {\r
-        nSamplesToBuffer = psEnc->sCmn.frame_length - psEnc->sCmn.inputBufIx;\r
-        if( 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 * input_10ms * psEnc->sCmn.fs_kHz );\r
-            nSamplesFromInput = SKP_DIV32_16( nSamplesToBuffer * API_fs_Hz, psEnc->sCmn.fs_kHz * 1000 );\r
-            /* Resample and write to buffer */\r
-            ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, \r
-                &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, nSamplesFromInput );\r
-        } \r
-        samplesIn              += nSamplesFromInput;\r
-        nSamplesIn             -= nSamplesFromInput;\r
-        psEnc->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
-\r
-            /* Enough data in input buffer, so encode */\r
-            if( MaxBytesOut == 0 ) {\r
-                /* No payload obtained so far */\r
-                MaxBytesOut = *nBytesOut;\r
-                if( ( ret = SKP_Silk_encode_frame_FIX( psEnc, outData, &MaxBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) {\r
-                    SKP_assert( 0 );\r
-                }\r
-            } else {\r
-                /* outData already contains a payload */\r
-                if( ( ret = SKP_Silk_encode_frame_FIX( psEnc, outData, nBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) {\r
-                    SKP_assert( 0 );\r
-                }\r
-                /* Check that no second payload was created */\r
-                SKP_assert( *nBytesOut == 0 );\r
-            }\r
-            psEnc->sCmn.inputBufIx = 0;\r
-            psEnc->sCmn.controlled_since_last_payload = 0;\r
-\r
-            if( nSamplesIn == 0 ) {\r
-                break;\r
-            }\r
-        } else {\r
-            break;\r
-        }\r
-    }\r
-\r
-    *nBytesOut = MaxBytesOut;\r
-    if( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) {\r
-        /* DTX simulation */\r
-        *nBytesOut = 0;\r
-    }\r
-\r
-\r
-    return ret;\r
-}\r
-\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+
+#include "SKP_Silk_define.h"
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_SDK_API.h"
+#include "SKP_Silk_control.h"
+#include "SKP_Silk_typedef.h"
+#include "SKP_Silk_structs.h"
+#define SKP_Silk_EncodeControlStruct SKP_SILK_SDK_EncControlStruct
+
+/****************************************/
+/* Encoder functions                    */
+/****************************************/
+
+SKP_int SKP_Silk_SDK_Get_Encoder_Size( SKP_int32 *encSizeBytes )
+{
+    SKP_int ret = 0;
+    
+    *encSizeBytes = sizeof( SKP_Silk_encoder_state_FIX );
+    
+    return ret;
+}
+
+
+/***************************************/
+/* Read control structure from encoder */
+/***************************************/
+SKP_int SKP_Silk_SDK_QueryEncoder(
+    const void *encState,                       /* I:   State Vector                                    */
+    SKP_Silk_EncodeControlStruct *encStatus     /* O:   Control Structure                               */
+)
+{
+    SKP_Silk_encoder_state_FIX *psEnc;
+    SKP_int ret = 0;
+
+    psEnc = ( SKP_Silk_encoder_state_FIX* )encState;
+
+    encStatus->API_sampleRate        = psEnc->sCmn.API_fs_Hz;
+    encStatus->maxInternalSampleRate = SKP_SMULBB( psEnc->sCmn.maxInternal_fs_kHz, 1000 );
+    encStatus->packetSize            = ( SKP_int )SKP_DIV32_16( psEnc->sCmn.API_fs_Hz * psEnc->sCmn.PacketSize_ms, 1000 );  /* convert samples -> ms */
+    encStatus->bitRate               = psEnc->sCmn.TargetRate_bps;
+    encStatus->packetLossPercentage  = psEnc->sCmn.PacketLoss_perc;
+    encStatus->complexity            = psEnc->sCmn.Complexity;
+    encStatus->useInBandFEC          = psEnc->sCmn.useInBandFEC;
+    encStatus->useDTX                = psEnc->sCmn.useDTX;
+    return ret;
+}
+
+/*************************/
+/* Init or Reset encoder */
+/*************************/
+SKP_int SKP_Silk_SDK_InitEncoder(
+    void                            *encState,          /* I/O: State                                           */
+    SKP_Silk_EncodeControlStruct    *encStatus          /* O:   Control structure                               */
+)
+{
+    SKP_Silk_encoder_state_FIX *psEnc;
+    SKP_int ret = 0;
+
+        
+    psEnc = ( SKP_Silk_encoder_state_FIX* )encState;
+
+    /* Reset Encoder */
+    if( ret += SKP_Silk_init_encoder_FIX( psEnc ) ) {
+        SKP_assert( 0 );
+    }
+
+    /* Read control structure */
+    if( ret += SKP_Silk_SDK_QueryEncoder( encState, encStatus ) ) {
+        SKP_assert( 0 );
+    }
+
+
+    return ret;
+}
+
+/**************************/
+/* Encode frame with Silk */
+/**************************/
+SKP_int SKP_Silk_SDK_Encode( 
+    void                                *encState,      /* I/O: State                                           */
+    const SKP_Silk_EncodeControlStruct  *encControl,    /* I:   Control structure                               */
+    const SKP_int16                     *samplesIn,     /* I:   Speech sample input vector                      */
+    SKP_int                             nSamplesIn,     /* I:   Number of samples in input vector               */
+    SKP_uint8                           *outData,       /* O:   Encoded output vector                           */
+    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in outData (input: Max bytes)   */
+)
+{
+    SKP_int   max_internal_fs_kHz, PacketSize_ms, PacketLoss_perc, UseInBandFEC, UseDTX, ret = 0;
+    SKP_int   nSamplesToBuffer, Complexity, input_10ms, nSamplesFromInput = 0;
+    SKP_int32 TargetRate_bps, API_fs_Hz;
+    SKP_int16 MaxBytesOut;
+    SKP_Silk_encoder_state_FIX *psEnc = ( SKP_Silk_encoder_state_FIX* )encState;
+
+    SKP_assert( encControl != NULL );
+
+    /* Check sampling frequency first, to avoid divide by zero later */
+    if( ( ( encControl->API_sampleRate        !=  8000 ) &&
+          ( encControl->API_sampleRate        != 12000 ) &&
+          ( encControl->API_sampleRate        != 16000 ) &&
+          ( encControl->API_sampleRate        != 24000 ) && 
+          ( encControl->API_sampleRate        != 32000 ) &&
+          ( encControl->API_sampleRate        != 44100 ) &&
+          ( encControl->API_sampleRate        != 48000 ) ) ||
+        ( ( encControl->maxInternalSampleRate !=  8000 ) &&
+          ( encControl->maxInternalSampleRate != 12000 ) &&
+          ( encControl->maxInternalSampleRate != 16000 ) &&
+          ( encControl->maxInternalSampleRate != 24000 ) ) ) {
+        ret = SKP_SILK_ENC_FS_NOT_SUPPORTED;
+        SKP_assert( 0 );
+        return( ret );
+    }
+
+    /* Set encoder parameters from control structure */
+    API_fs_Hz           =                            encControl->API_sampleRate;
+    max_internal_fs_kHz =                 (SKP_int)( encControl->maxInternalSampleRate >> 10 ) + 1;   /* convert Hz -> kHz */
+    PacketSize_ms       = SKP_DIV32( 1000 * (SKP_int)encControl->packetSize, API_fs_Hz );
+    TargetRate_bps      =                            encControl->bitRate;
+    PacketLoss_perc     =                            encControl->packetLossPercentage;
+    UseInBandFEC        =                            encControl->useInBandFEC;
+    Complexity          =                            encControl->complexity;
+    UseDTX              =                            encControl->useDTX;
+
+    /* Save values in state */
+    psEnc->sCmn.API_fs_Hz          = API_fs_Hz;
+    psEnc->sCmn.maxInternal_fs_kHz = max_internal_fs_kHz;
+    psEnc->sCmn.useInBandFEC       = UseInBandFEC;
+
+    /* Only accept input lengths that are a multiple of 10 ms */
+    input_10ms = SKP_DIV32( 100 * nSamplesIn, API_fs_Hz );
+    if( input_10ms * API_fs_Hz != 100 * nSamplesIn || nSamplesIn < 0 ) {
+        ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;
+        SKP_assert( 0 );
+        return( ret );
+    }
+
+    TargetRate_bps = SKP_LIMIT( TargetRate_bps, MIN_TARGET_RATE_BPS, MAX_TARGET_RATE_BPS );
+    if( ( ret = SKP_Silk_control_encoder_FIX( psEnc, PacketSize_ms, TargetRate_bps, 
+                        PacketLoss_perc, UseDTX, Complexity) ) != 0 ) {
+        SKP_assert( 0 );
+        return( ret );
+    }
+
+    /* Make sure no more than one packet can be produced */
+    if( 1000 * (SKP_int32)nSamplesIn > psEnc->sCmn.PacketSize_ms * API_fs_Hz ) {
+        ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;
+        SKP_assert( 0 );
+        return( ret );
+    }
+
+#if MAX_FS_KHZ > 16
+    /* Detect energy above 8 kHz */
+    if( SKP_min( API_fs_Hz, 1000 * max_internal_fs_kHz ) == 24000 && 
+            psEnc->sCmn.sSWBdetect.SWB_detected == 0 && 
+            psEnc->sCmn.sSWBdetect.WB_detected == 0 ) {
+        SKP_Silk_detect_SWB_input( &psEnc->sCmn.sSWBdetect, samplesIn, ( SKP_int )nSamplesIn );
+    }
+#endif
+
+    /* Input buffering/resampling and encoding */
+    MaxBytesOut = 0;                    /* return 0 output bytes if no encoder called */
+    while( 1 ) {
+        nSamplesToBuffer = psEnc->sCmn.frame_length - psEnc->sCmn.inputBufIx;
+        if( API_fs_Hz == SKP_SMULBB( 1000, psEnc->sCmn.fs_kHz ) ) { 
+            nSamplesToBuffer  = SKP_min_int( nSamplesToBuffer, nSamplesIn );
+            nSamplesFromInput = nSamplesToBuffer;
+            /* Copy to buffer */
+            SKP_memcpy( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, nSamplesFromInput * sizeof( SKP_int16 ) );
+        } else {  
+            nSamplesToBuffer  = SKP_min( nSamplesToBuffer, 10 * input_10ms * psEnc->sCmn.fs_kHz );
+            nSamplesFromInput = SKP_DIV32_16( nSamplesToBuffer * API_fs_Hz, psEnc->sCmn.fs_kHz * 1000 );
+            /* Resample and write to buffer */
+            ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, 
+                &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, nSamplesFromInput );
+        } 
+        samplesIn              += nSamplesFromInput;
+        nSamplesIn             -= nSamplesFromInput;
+        psEnc->sCmn.inputBufIx += nSamplesToBuffer;
+
+        /* Silk encoder */
+        if( psEnc->sCmn.inputBufIx >= psEnc->sCmn.frame_length ) {
+            SKP_assert( psEnc->sCmn.inputBufIx == psEnc->sCmn.frame_length );
+
+            /* Enough data in input buffer, so encode */
+            if( MaxBytesOut == 0 ) {
+                /* No payload obtained so far */
+                MaxBytesOut = *nBytesOut;
+                if( ( ret = SKP_Silk_encode_frame_FIX( psEnc, outData, &MaxBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) {
+                    SKP_assert( 0 );
+                }
+            } else {
+                /* outData already contains a payload */
+                if( ( ret = SKP_Silk_encode_frame_FIX( psEnc, outData, nBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) {
+                    SKP_assert( 0 );
+                }
+                /* Check that no second payload was created */
+                SKP_assert( *nBytesOut == 0 );
+            }
+            psEnc->sCmn.inputBufIx = 0;
+            psEnc->sCmn.controlled_since_last_payload = 0;
+
+            if( nSamplesIn == 0 ) {
+                break;
+            }
+        } else {
+            break;
+        }
+    }
+
+    *nBytesOut = MaxBytesOut;
+    if( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) {
+        /* DTX simulation */
+        *nBytesOut = 0;
+    }
+
+
+    return ret;
+}
+
+
index 44d2a8646da72876d9fb36d4aac9e53b84f3c004..e6706ac392e0f3f25406b1f5f7d9ff1853410455 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-#include "SKP_Silk_tuning_parameters.h"\r
-\r
-/****************/\r
-/* Encode frame */\r
-/****************/\r
-SKP_int SKP_Silk_encode_frame_FIX( \r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk FIX encoder state           */\r
-    SKP_uint8                       *pCode,             /* O    Pointer to payload                          */\r
-    SKP_int16                       *pnBytesOut,        /* I/O  Pointer to number of payload bytes          */\r
-                                                        /*      input: max length; output: used             */\r
-    const SKP_int16                 *pIn                /* I    Pointer to input speech frame               */\r
-)\r
-{\r
-    SKP_Silk_encoder_control_FIX sEncCtrl;\r
-    SKP_int     nBytes, ret = 0;\r
-    SKP_int16   *x_frame, *res_pitch_frame;\r
-    SKP_int16   xfw[ MAX_FRAME_LENGTH ];\r
-    SKP_int16   pIn_HP[ MAX_FRAME_LENGTH ];\r
-    SKP_int16   res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ];\r
-    SKP_int     LBRR_idx, frame_terminator, SNR_dB_Q7;\r
-    const SKP_uint16 *FrameTermination_CDF;\r
-    /* Low bitrate redundancy parameters */\r
-    SKP_uint8   LBRRpayload[ MAX_ARITHM_BYTES ];\r
-    SKP_int16   nBytesLBRR;\r
-\r
-\r
-    sEncCtrl.sCmn.Seed = psEnc->sCmn.frameCounter++ & 3;\r
-    /**************************************************************/\r
-    /* Setup Input Pointers, and insert frame in input buffer    */\r
-    /*************************************************************/\r
-    x_frame         = psEnc->x_buf + psEnc->sCmn.frame_length; /* start of frame to encode */\r
-    res_pitch_frame = res_pitch    + psEnc->sCmn.frame_length; /* start of pitch LPC residual frame */\r
-\r
-    /****************************/\r
-    /* Voice Activity Detection */\r
-    /****************************/\r
-    ret = SKP_Silk_VAD_GetSA_Q8( &psEnc->sCmn.sVAD, &psEnc->speech_activity_Q8, &SNR_dB_Q7, \r
-                                 sEncCtrl.input_quality_bands_Q15, &sEncCtrl.input_tilt_Q15,\r
-                                 pIn,psEnc->sCmn.frame_length );\r
-\r
-    /*******************************************/\r
-    /* High-pass filtering of the input signal */\r
-    /*******************************************/\r
-#if HIGH_PASS_INPUT\r
-    /* Variable high-pass filter */\r
-    SKP_Silk_HP_variable_cutoff_FIX( psEnc, &sEncCtrl, pIn_HP, pIn );\r
-#else\r
-    SKP_memcpy( pIn_HP, pIn, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );\r
-#endif\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, pIn_HP, psEnc->sCmn.frame_length );\r
-#else\r
-    SKP_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, pIn_HP,psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );\r
-#endif\r
-    \r
-    /*****************************************/\r
-    /* Find pitch lags, initial LPC analysis */\r
-    /*****************************************/\r
-    SKP_Silk_find_pitch_lags_FIX( psEnc, &sEncCtrl, res_pitch, x_frame );\r
-\r
-    /************************/\r
-    /* Noise shape analysis */\r
-    /************************/\r
-    SKP_Silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_frame );\r
-\r
-    /*****************************************/\r
-    /* Prefiltering for noise shaper         */\r
-    /*****************************************/\r
-    SKP_Silk_prefilter_FIX( psEnc, &sEncCtrl, xfw, x_frame );\r
-\r
-    /***************************************************/\r
-    /* Find linear prediction coefficients (LPC + LTP) */\r
-    /***************************************************/\r
-    SKP_Silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch );\r
-\r
-    /****************************************/\r
-    /* Process gains                        */\r
-    /****************************************/\r
-    SKP_Silk_process_gains_FIX( psEnc, &sEncCtrl );\r
-    \r
-    \r
-    /****************************************/\r
-    /* Low Bitrate Redundant Encoding       */\r
-    /****************************************/\r
-    nBytesLBRR = MAX_ARITHM_BYTES;\r
-    SKP_Silk_LBRR_encode_FIX( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw );\r
-\r
-    /*****************************************/\r
-    /* Noise shaping quantization            */\r
-    /*****************************************/\r
-    if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {\r
-        SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw,\r
-            psEnc->sCmn.q, sEncCtrl.sCmn.NLSFInterpCoef_Q2, \r
-            sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14, \r
-            sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.Lambda_Q10, \r
-            sEncCtrl.LTP_scale_Q14 );\r
-    } else {\r
-        SKP_Silk_NSQ( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw, \r
-            psEnc->sCmn.q, sEncCtrl.sCmn.NLSFInterpCoef_Q2, \r
-            sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14, \r
-            sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.Lambda_Q10, \r
-            sEncCtrl.LTP_scale_Q14 );\r
-    }\r
-\r
-    /**************************************************/\r
-    /* Convert speech activity into VAD and DTX flags */\r
-    /**************************************************/\r
-    if( psEnc->speech_activity_Q8 < SKP_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) {\r
-        psEnc->sCmn.vadFlag = 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
-            psEnc->sCmn.inDTX           = 0;\r
-        }\r
-    } else {\r
-        psEnc->sCmn.noSpeechCounter = 0;\r
-        psEnc->sCmn.inDTX           = 0;\r
-        psEnc->sCmn.vadFlag         = VOICE_ACTIVITY;\r
-    }\r
-\r
-    /****************************************/\r
-    /* Initialize range coder               */\r
-    /****************************************/\r
-    if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {\r
-        SKP_Silk_range_enc_init( &psEnc->sCmn.sRC );\r
-        psEnc->sCmn.nBytesInPayloadBuf = 0;\r
-    }\r
-\r
-    /****************************************/\r
-    /* Encode Parameters                    */\r
-    /****************************************/\r
-    SKP_Silk_encode_parameters( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC, psEnc->sCmn.q );\r
-    FrameTermination_CDF = SKP_Silk_FrameTermination_CDF;\r
-\r
-    /****************************************/\r
-    /* Update Buffers and State             */\r
-    /****************************************/\r
-    /* Update input buffer */\r
-    SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ], \r
-        ( psEnc->sCmn.frame_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( SKP_int16 ) );\r
-    \r
-    /* Parameters needed for next frame */\r
-    psEnc->sCmn.prev_sigtype            = sEncCtrl.sCmn.sigtype;\r
-    psEnc->sCmn.prevLag                 = sEncCtrl.sCmn.pitchL[ NB_SUBFR - 1];\r
-    psEnc->sCmn.first_frame_after_reset = 0;\r
-\r
-    if( psEnc->sCmn.sRC.error ) {\r
-        /* Encoder returned error: clear payload buffer */\r
-        psEnc->sCmn.nFramesInPayloadBuf = 0;\r
-    } else {\r
-        psEnc->sCmn.nFramesInPayloadBuf++;\r
-    }\r
-\r
-    /****************************************/\r
-    /* Finalize payload and copy to output  */\r
-    /****************************************/\r
-    if( psEnc->sCmn.nFramesInPayloadBuf * FRAME_LENGTH_MS >= psEnc->sCmn.PacketSize_ms ) {\r
-\r
-        LBRR_idx = ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK;\r
-\r
-        /* Check if FEC information should be added */\r
-        frame_terminator = SKP_SILK_LAST_FRAME;\r
-        if( psEnc->sCmn.LBRR_buffer[ LBRR_idx ].usage == SKP_SILK_ADD_LBRR_TO_PLUS1 ) {\r
-            frame_terminator = SKP_SILK_LBRR_VER1;\r
-        }\r
-        if( psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].usage == SKP_SILK_ADD_LBRR_TO_PLUS2 ) {\r
-            frame_terminator = SKP_SILK_LBRR_VER2;\r
-            LBRR_idx = psEnc->sCmn.oldest_LBRR_idx;\r
-        }\r
-\r
-        /* Add the frame termination info to stream */\r
-        SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF );\r
-\r
-        /* Payload length so far */\r
-        SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC, &nBytes );\r
-\r
-        /* Check that there is enough space in external output buffer, and move data */\r
-        if( *pnBytesOut >= nBytes ) {\r
-            SKP_Silk_range_enc_wrap_up( &psEnc->sCmn.sRC );\r
-            SKP_memcpy( pCode, psEnc->sCmn.sRC.buffer, nBytes * sizeof( SKP_uint8 ) );\r
-            \r
-            if( frame_terminator > SKP_SILK_MORE_FRAMES && \r
-                    *pnBytesOut >= nBytes + psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes ) {\r
-                /* Get old packet and add to payload. */\r
-                SKP_memcpy( &pCode[ nBytes ],\r
-                    psEnc->sCmn.LBRR_buffer[ LBRR_idx ].payload,\r
-                    psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes * sizeof( SKP_uint8 ) );\r
-                nBytes += psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes;\r
-            }\r
-\r
-            *pnBytesOut = nBytes;\r
-\r
-            /* Update FEC buffer */\r
-            SKP_memcpy( psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].payload, LBRRpayload, \r
-                nBytesLBRR * sizeof( SKP_uint8 ) );\r
-            psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].nBytes = nBytesLBRR;\r
-            /* The line below describes how FEC should be used */\r
-            psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].usage = sEncCtrl.sCmn.LBRR_usage;\r
-            psEnc->sCmn.oldest_LBRR_idx = ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK;\r
-\r
-        } else {\r
-            /* Not enough space: Payload will be discarded */\r
-            *pnBytesOut = 0;\r
-            nBytes      = 0;\r
-            ret = SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT;\r
-        }\r
-\r
-        /* Reset the number of frames in payload buffer */\r
-        psEnc->sCmn.nFramesInPayloadBuf = 0;\r
-    } else {\r
-        /* No payload this time */\r
-        *pnBytesOut = 0;\r
-\r
-        /* Encode that more frames follows */\r
-        frame_terminator = SKP_SILK_MORE_FRAMES;\r
-        SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF );\r
-\r
-        /* Payload length so far */\r
-        SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC, &nBytes );\r
-        \r
-    }\r
-\r
-    /* Check for arithmetic coder errors */\r
-    if( psEnc->sCmn.sRC.error ) {\r
-        ret = SKP_SILK_ENC_INTERNAL_ERROR;\r
-    }\r
-\r
-    /* Simulate number of ms buffered in channel because of exceeding TargetRate */\r
-    SKP_assert(  ( 8 * 1000 * ( (SKP_int64)nBytes - (SKP_int64)psEnc->sCmn.nBytesInPayloadBuf ) ) == \r
-        SKP_SAT32( 8 * 1000 * ( (SKP_int64)nBytes - (SKP_int64)psEnc->sCmn.nBytesInPayloadBuf ) ) );\r
-    SKP_assert( psEnc->sCmn.TargetRate_bps > 0 );\r
-    psEnc->BufferedInChannel_ms   += SKP_DIV32( 8 * 1000 * ( nBytes - psEnc->sCmn.nBytesInPayloadBuf ), psEnc->sCmn.TargetRate_bps );\r
-    psEnc->BufferedInChannel_ms   -= FRAME_LENGTH_MS;\r
-    psEnc->BufferedInChannel_ms    = SKP_LIMIT_int( psEnc->BufferedInChannel_ms, 0, 100 );\r
-    psEnc->sCmn.nBytesInPayloadBuf = nBytes;\r
-\r
-    if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES, 8 ) ) {\r
-        psEnc->sCmn.sSWBdetect.ActiveSpeech_ms = SKP_ADD_POS_SAT32( psEnc->sCmn.sSWBdetect.ActiveSpeech_ms, FRAME_LENGTH_MS ); \r
-    }\r
-\r
-\r
-    return( ret );\r
-}\r
-\r
-/* Low BitRate Redundancy encoding functionality. Reuse all parameters but encode residual with lower bitrate */\r
-void SKP_Silk_LBRR_encode_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Pointer to Silk encoder state           */\r
-    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  Pointer to Silk encoder control struct  */\r
-    SKP_uint8                       *pCode,         /* O    Pointer to payload                      */\r
-    SKP_int16                       *pnBytesOut,    /* I/O  Pointer to number of payload bytes      */\r
-    SKP_int16                       xfw[]           /* I    Input signal                            */\r
-)\r
-{\r
-    SKP_int     TempGainsIndices[ NB_SUBFR ], frame_terminator;\r
-    SKP_int     nBytes, nFramesInPayloadBuf;\r
-    SKP_int32   TempGains_Q16[ NB_SUBFR ];\r
-    SKP_int     typeOffset, LTP_scaleIndex, Rate_only_parameters = 0;\r
-    /*******************************************/\r
-    /* Control use of inband LBRR              */\r
-    /*******************************************/\r
-    SKP_Silk_LBRR_ctrl_FIX( psEnc, &psEncCtrl->sCmn );\r
-\r
-    if( psEnc->sCmn.LBRR_enabled ) {\r
-        /* Save original gains */\r
-        SKP_memcpy( TempGainsIndices, psEncCtrl->sCmn.GainsIndices, NB_SUBFR * sizeof( SKP_int   ) );\r
-        SKP_memcpy( TempGains_Q16,    psEncCtrl->Gains_Q16,         NB_SUBFR * sizeof( SKP_int32 ) );\r
-\r
-        typeOffset     = psEnc->sCmn.typeOffsetPrev; // Temp save as cannot be overwritten\r
-        LTP_scaleIndex = psEncCtrl->sCmn.LTP_scaleIndex;\r
-\r
-        /* Set max rate where quant signal is encoded */\r
-        if( psEnc->sCmn.fs_kHz == 8 ) {\r
-            Rate_only_parameters = 13500;\r
-        } else if( psEnc->sCmn.fs_kHz == 12 ) {\r
-            Rate_only_parameters = 15500;\r
-        } else if( psEnc->sCmn.fs_kHz == 16 ) {\r
-            Rate_only_parameters = 17500;\r
-        } else if( psEnc->sCmn.fs_kHz == 24 ) {\r
-            Rate_only_parameters = 19500;\r
-        } else {\r
-            SKP_assert( 0 );\r
-        }\r
-\r
-        if( psEnc->sCmn.Complexity > 0 && psEnc->sCmn.TargetRate_bps > Rate_only_parameters ) {\r
-            if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {\r
-                /* First frame in packet; copy everything */\r
-                SKP_memcpy( &psEnc->sNSQ_LBRR, &psEnc->sNSQ, sizeof( SKP_Silk_nsq_state ) );\r
-\r
-                psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex;\r
-                /* Increase Gains to get target LBRR rate */\r
-                psEncCtrl->sCmn.GainsIndices[ 0 ] = psEncCtrl->sCmn.GainsIndices[ 0 ] + psEnc->sCmn.LBRR_GainIncreases;\r
-                psEncCtrl->sCmn.GainsIndices[ 0 ] = SKP_LIMIT_int( psEncCtrl->sCmn.GainsIndices[ 0 ], 0, N_LEVELS_QGAIN - 1 );\r
-            }\r
-            /* Decode to get gains in sync with decoder         */\r
-            /* Overwrite unquantized gains with quantized gains */\r
-            SKP_Silk_gains_dequant( psEncCtrl->Gains_Q16, psEncCtrl->sCmn.GainsIndices, \r
-                &psEnc->sCmn.LBRRprevLastGainIndex, psEnc->sCmn.nFramesInPayloadBuf );\r
-\r
-            /*****************************************/\r
-            /* Noise shaping quantization            */\r
-            /*****************************************/\r
-            if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {\r
-                SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ_LBRR, xfw, psEnc->sCmn.q_LBRR, \r
-                    psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, \r
-                    psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, \r
-                    psEncCtrl->Gains_Q16, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 );\r
-            } else {\r
-                SKP_Silk_NSQ( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ_LBRR, xfw, psEnc->sCmn.q_LBRR, \r
-                    psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, \r
-                    psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, \r
-                    psEncCtrl->Gains_Q16, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 );\r
-            }\r
-        } else {\r
-            SKP_memset( psEnc->sCmn.q_LBRR, 0, psEnc->sCmn.frame_length * sizeof( SKP_int8 ) );\r
-            psEncCtrl->sCmn.LTP_scaleIndex = 0;\r
-        }\r
-        /****************************************/\r
-        /* Initialize arithmetic coder          */\r
-        /****************************************/\r
-        if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {\r
-            SKP_Silk_range_enc_init( &psEnc->sCmn.sRC_LBRR );\r
-            psEnc->sCmn.nBytesInPayloadBuf = 0;\r
-        }\r
-\r
-        /****************************************/\r
-        /* Encode Parameters                    */\r
-        /****************************************/\r
-        SKP_Silk_encode_parameters( &psEnc->sCmn, &psEncCtrl->sCmn, \r
-            &psEnc->sCmn.sRC_LBRR, psEnc->sCmn.q_LBRR );\r
-\r
-        if( psEnc->sCmn.sRC_LBRR.error ) {\r
-            /* Encoder returned error: clear payload buffer */\r
-            nFramesInPayloadBuf = 0;\r
-        } else {\r
-            nFramesInPayloadBuf = psEnc->sCmn.nFramesInPayloadBuf + 1;\r
-        }\r
-\r
-        /****************************************/\r
-        /* Finalize payload and copy to output  */\r
-        /****************************************/\r
-        if( SKP_SMULBB( nFramesInPayloadBuf, FRAME_LENGTH_MS ) >= psEnc->sCmn.PacketSize_ms ) {\r
-\r
-            /* Check if FEC information should be added */\r
-            frame_terminator = SKP_SILK_LAST_FRAME;\r
-\r
-            /* Add the frame termination info to stream */\r
-            SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_CDF );\r
-\r
-            /* Payload length so far */\r
-            SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC_LBRR, &nBytes );\r
-\r
-            /* Check that there is enough space in external output buffer and move data */\r
-            if( *pnBytesOut >= nBytes ) {\r
-                SKP_Silk_range_enc_wrap_up( &psEnc->sCmn.sRC_LBRR );\r
-                SKP_memcpy( pCode, psEnc->sCmn.sRC_LBRR.buffer, nBytes * sizeof( SKP_uint8 ) );\r
-\r
-                *pnBytesOut = nBytes;\r
-            } else {\r
-                /* Not enough space: payload will be discarded */\r
-                *pnBytesOut = 0;\r
-                SKP_assert( 0 );\r
-            }\r
-        } else {\r
-            /* No payload this time */\r
-            *pnBytesOut = 0;\r
-\r
-            /* Encode that more frames follows */\r
-            frame_terminator = SKP_SILK_MORE_FRAMES;\r
-            SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_CDF );\r
-        }\r
-\r
-        /* Restore original Gains */\r
-        SKP_memcpy( psEncCtrl->sCmn.GainsIndices, TempGainsIndices, NB_SUBFR * sizeof( SKP_int   ) );\r
-        SKP_memcpy( psEncCtrl->Gains_Q16,         TempGains_Q16,    NB_SUBFR * sizeof( SKP_int32 ) );\r
-    \r
-        /* Restore LTP scale index and typeoffset */\r
-        psEncCtrl->sCmn.LTP_scaleIndex = LTP_scaleIndex;\r
-        psEnc->sCmn.typeOffsetPrev = typeOffset;\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_tuning_parameters.h"
+
+/****************/
+/* Encode frame */
+/****************/
+SKP_int SKP_Silk_encode_frame_FIX( 
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk FIX encoder state           */
+    SKP_uint8                       *pCode,             /* O    Pointer to payload                          */
+    SKP_int16                       *pnBytesOut,        /* I/O  Pointer to number of payload bytes          */
+                                                        /*      input: max length; output: used             */
+    const SKP_int16                 *pIn                /* I    Pointer to input speech frame               */
+)
+{
+    SKP_Silk_encoder_control_FIX sEncCtrl;
+    SKP_int     nBytes, ret = 0;
+    SKP_int16   *x_frame, *res_pitch_frame;
+    SKP_int16   xfw[ MAX_FRAME_LENGTH ];
+    SKP_int16   pIn_HP[ MAX_FRAME_LENGTH ];
+    SKP_int16   res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ];
+    SKP_int     LBRR_idx, frame_terminator, SNR_dB_Q7;
+    const SKP_uint16 *FrameTermination_CDF;
+    /* Low bitrate redundancy parameters */
+    SKP_uint8   LBRRpayload[ MAX_ARITHM_BYTES ];
+    SKP_int16   nBytesLBRR;
+
+
+    sEncCtrl.sCmn.Seed = psEnc->sCmn.frameCounter++ & 3;
+    /**************************************************************/
+    /* Setup Input Pointers, and insert frame in input buffer    */
+    /*************************************************************/
+    x_frame         = psEnc->x_buf + psEnc->sCmn.frame_length; /* start of frame to encode */
+    res_pitch_frame = res_pitch    + psEnc->sCmn.frame_length; /* start of pitch LPC residual frame */
+
+    /****************************/
+    /* Voice Activity Detection */
+    /****************************/
+    ret = SKP_Silk_VAD_GetSA_Q8( &psEnc->sCmn.sVAD, &psEnc->speech_activity_Q8, &SNR_dB_Q7, 
+                                 sEncCtrl.input_quality_bands_Q15, &sEncCtrl.input_tilt_Q15,
+                                 pIn,psEnc->sCmn.frame_length );
+
+    /*******************************************/
+    /* High-pass filtering of the input signal */
+    /*******************************************/
+#if HIGH_PASS_INPUT
+    /* Variable high-pass filter */
+    SKP_Silk_HP_variable_cutoff_FIX( psEnc, &sEncCtrl, pIn_HP, pIn );
+#else
+    SKP_memcpy( pIn_HP, pIn, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );
+#endif
+
+#if SWITCH_TRANSITION_FILTERING
+    /* Ensure smooth bandwidth transitions */
+    SKP_Silk_LP_variable_cutoff( &psEnc->sCmn.sLP, x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, pIn_HP, psEnc->sCmn.frame_length );
+#else
+    SKP_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, pIn_HP,psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );
+#endif
+    
+    /*****************************************/
+    /* Find pitch lags, initial LPC analysis */
+    /*****************************************/
+    SKP_Silk_find_pitch_lags_FIX( psEnc, &sEncCtrl, res_pitch, x_frame );
+
+    /************************/
+    /* Noise shape analysis */
+    /************************/
+    SKP_Silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_frame );
+
+    /*****************************************/
+    /* Prefiltering for noise shaper         */
+    /*****************************************/
+    SKP_Silk_prefilter_FIX( psEnc, &sEncCtrl, xfw, x_frame );
+
+    /***************************************************/
+    /* Find linear prediction coefficients (LPC + LTP) */
+    /***************************************************/
+    SKP_Silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch );
+
+    /****************************************/
+    /* Process gains                        */
+    /****************************************/
+    SKP_Silk_process_gains_FIX( psEnc, &sEncCtrl );
+    
+    
+    /****************************************/
+    /* Low Bitrate Redundant Encoding       */
+    /****************************************/
+    nBytesLBRR = MAX_ARITHM_BYTES;
+    SKP_Silk_LBRR_encode_FIX( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw );
+
+    /*****************************************/
+    /* Noise shaping quantization            */
+    /*****************************************/
+    if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
+        SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw,
+            psEnc->sCmn.q, sEncCtrl.sCmn.NLSFInterpCoef_Q2, 
+            sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14, 
+            sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.Lambda_Q10, 
+            sEncCtrl.LTP_scale_Q14 );
+    } else {
+        SKP_Silk_NSQ( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw, 
+            psEnc->sCmn.q, sEncCtrl.sCmn.NLSFInterpCoef_Q2, 
+            sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14, 
+            sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.Lambda_Q10, 
+            sEncCtrl.LTP_scale_Q14 );
+    }
+
+    /**************************************************/
+    /* Convert speech activity into VAD and DTX flags */
+    /**************************************************/
+    if( psEnc->speech_activity_Q8 < SKP_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) {
+        psEnc->sCmn.vadFlag = NO_VOICE_ACTIVITY;
+        psEnc->sCmn.noSpeechCounter++;
+        if( psEnc->sCmn.noSpeechCounter > NO_SPEECH_FRAMES_BEFORE_DTX ) {
+            psEnc->sCmn.inDTX = 1;
+        }
+        if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX ) {
+            psEnc->sCmn.noSpeechCounter = 0;
+            psEnc->sCmn.inDTX           = 0;
+        }
+    } else {
+        psEnc->sCmn.noSpeechCounter = 0;
+        psEnc->sCmn.inDTX           = 0;
+        psEnc->sCmn.vadFlag         = VOICE_ACTIVITY;
+    }
+
+    /****************************************/
+    /* Initialize range coder               */
+    /****************************************/
+    if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
+        SKP_Silk_range_enc_init( &psEnc->sCmn.sRC );
+        psEnc->sCmn.nBytesInPayloadBuf = 0;
+    }
+
+    /****************************************/
+    /* Encode Parameters                    */
+    /****************************************/
+    SKP_Silk_encode_parameters( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC, psEnc->sCmn.q );
+    FrameTermination_CDF = SKP_Silk_FrameTermination_CDF;
+
+    /****************************************/
+    /* Update Buffers and State             */
+    /****************************************/
+    /* Update input buffer */
+    SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ], 
+        ( psEnc->sCmn.frame_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( SKP_int16 ) );
+    
+    /* Parameters needed for next frame */
+    psEnc->sCmn.prev_sigtype            = sEncCtrl.sCmn.sigtype;
+    psEnc->sCmn.prevLag                 = sEncCtrl.sCmn.pitchL[ NB_SUBFR - 1];
+    psEnc->sCmn.first_frame_after_reset = 0;
+
+    if( psEnc->sCmn.sRC.error ) {
+        /* Encoder returned error: clear payload buffer */
+        psEnc->sCmn.nFramesInPayloadBuf = 0;
+    } else {
+        psEnc->sCmn.nFramesInPayloadBuf++;
+    }
+
+    /****************************************/
+    /* Finalize payload and copy to output  */
+    /****************************************/
+    if( psEnc->sCmn.nFramesInPayloadBuf * FRAME_LENGTH_MS >= psEnc->sCmn.PacketSize_ms ) {
+
+        LBRR_idx = ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK;
+
+        /* Check if FEC information should be added */
+        frame_terminator = SKP_SILK_LAST_FRAME;
+        if( psEnc->sCmn.LBRR_buffer[ LBRR_idx ].usage == SKP_SILK_ADD_LBRR_TO_PLUS1 ) {
+            frame_terminator = SKP_SILK_LBRR_VER1;
+        }
+        if( psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].usage == SKP_SILK_ADD_LBRR_TO_PLUS2 ) {
+            frame_terminator = SKP_SILK_LBRR_VER2;
+            LBRR_idx = psEnc->sCmn.oldest_LBRR_idx;
+        }
+
+        /* Add the frame termination info to stream */
+        SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF );
+
+        /* Payload length so far */
+        SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC, &nBytes );
+
+        /* Check that there is enough space in external output buffer, and move data */
+        if( *pnBytesOut >= nBytes ) {
+            SKP_Silk_range_enc_wrap_up( &psEnc->sCmn.sRC );
+            SKP_memcpy( pCode, psEnc->sCmn.sRC.buffer, nBytes * sizeof( SKP_uint8 ) );
+            
+            if( frame_terminator > SKP_SILK_MORE_FRAMES && 
+                    *pnBytesOut >= nBytes + psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes ) {
+                /* Get old packet and add to payload. */
+                SKP_memcpy( &pCode[ nBytes ],
+                    psEnc->sCmn.LBRR_buffer[ LBRR_idx ].payload,
+                    psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes * sizeof( SKP_uint8 ) );
+                nBytes += psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes;
+            }
+
+            *pnBytesOut = nBytes;
+
+            /* Update FEC buffer */
+            SKP_memcpy( psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].payload, LBRRpayload, 
+                nBytesLBRR * sizeof( SKP_uint8 ) );
+            psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].nBytes = nBytesLBRR;
+            /* The line below describes how FEC should be used */
+            psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].usage = sEncCtrl.sCmn.LBRR_usage;
+            psEnc->sCmn.oldest_LBRR_idx = ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK;
+
+        } else {
+            /* Not enough space: Payload will be discarded */
+            *pnBytesOut = 0;
+            nBytes      = 0;
+            ret = SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT;
+        }
+
+        /* Reset the number of frames in payload buffer */
+        psEnc->sCmn.nFramesInPayloadBuf = 0;
+    } else {
+        /* No payload this time */
+        *pnBytesOut = 0;
+
+        /* Encode that more frames follows */
+        frame_terminator = SKP_SILK_MORE_FRAMES;
+        SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF );
+
+        /* Payload length so far */
+        SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC, &nBytes );
+        
+    }
+
+    /* Check for arithmetic coder errors */
+    if( psEnc->sCmn.sRC.error ) {
+        ret = SKP_SILK_ENC_INTERNAL_ERROR;
+    }
+
+    /* Simulate number of ms buffered in channel because of exceeding TargetRate */
+    SKP_assert(  ( 8 * 1000 * ( (SKP_int64)nBytes - (SKP_int64)psEnc->sCmn.nBytesInPayloadBuf ) ) == 
+        SKP_SAT32( 8 * 1000 * ( (SKP_int64)nBytes - (SKP_int64)psEnc->sCmn.nBytesInPayloadBuf ) ) );
+    SKP_assert( psEnc->sCmn.TargetRate_bps > 0 );
+    psEnc->BufferedInChannel_ms   += SKP_DIV32( 8 * 1000 * ( nBytes - psEnc->sCmn.nBytesInPayloadBuf ), psEnc->sCmn.TargetRate_bps );
+    psEnc->BufferedInChannel_ms   -= FRAME_LENGTH_MS;
+    psEnc->BufferedInChannel_ms    = SKP_LIMIT_int( psEnc->BufferedInChannel_ms, 0, 100 );
+    psEnc->sCmn.nBytesInPayloadBuf = nBytes;
+
+    if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES, 8 ) ) {
+        psEnc->sCmn.sSWBdetect.ActiveSpeech_ms = SKP_ADD_POS_SAT32( psEnc->sCmn.sSWBdetect.ActiveSpeech_ms, FRAME_LENGTH_MS ); 
+    }
+
+
+    return( ret );
+}
+
+/* Low BitRate Redundancy encoding functionality. Reuse all parameters but encode residual with lower bitrate */
+void SKP_Silk_LBRR_encode_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Pointer to Silk encoder state           */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  Pointer to Silk encoder control struct  */
+    SKP_uint8                       *pCode,         /* O    Pointer to payload                      */
+    SKP_int16                       *pnBytesOut,    /* I/O  Pointer to number of payload bytes      */
+    SKP_int16                       xfw[]           /* I    Input signal                            */
+)
+{
+    SKP_int     TempGainsIndices[ NB_SUBFR ], frame_terminator;
+    SKP_int     nBytes, nFramesInPayloadBuf;
+    SKP_int32   TempGains_Q16[ NB_SUBFR ];
+    SKP_int     typeOffset, LTP_scaleIndex, Rate_only_parameters = 0;
+    /*******************************************/
+    /* Control use of inband LBRR              */
+    /*******************************************/
+    SKP_Silk_LBRR_ctrl_FIX( psEnc, &psEncCtrl->sCmn );
+
+    if( psEnc->sCmn.LBRR_enabled ) {
+        /* Save original gains */
+        SKP_memcpy( TempGainsIndices, psEncCtrl->sCmn.GainsIndices, NB_SUBFR * sizeof( SKP_int   ) );
+        SKP_memcpy( TempGains_Q16,    psEncCtrl->Gains_Q16,         NB_SUBFR * sizeof( SKP_int32 ) );
+
+        typeOffset     = psEnc->sCmn.typeOffsetPrev; // Temp save as cannot be overwritten
+        LTP_scaleIndex = psEncCtrl->sCmn.LTP_scaleIndex;
+
+        /* Set max rate where quant signal is encoded */
+        if( psEnc->sCmn.fs_kHz == 8 ) {
+            Rate_only_parameters = 13500;
+        } else if( psEnc->sCmn.fs_kHz == 12 ) {
+            Rate_only_parameters = 15500;
+        } else if( psEnc->sCmn.fs_kHz == 16 ) {
+            Rate_only_parameters = 17500;
+        } else if( psEnc->sCmn.fs_kHz == 24 ) {
+            Rate_only_parameters = 19500;
+        } else {
+            SKP_assert( 0 );
+        }
+
+        if( psEnc->sCmn.Complexity > 0 && psEnc->sCmn.TargetRate_bps > Rate_only_parameters ) {
+            if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
+                /* First frame in packet; copy everything */
+                SKP_memcpy( &psEnc->sNSQ_LBRR, &psEnc->sNSQ, sizeof( SKP_Silk_nsq_state ) );
+
+                psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex;
+                /* Increase Gains to get target LBRR rate */
+                psEncCtrl->sCmn.GainsIndices[ 0 ] = psEncCtrl->sCmn.GainsIndices[ 0 ] + psEnc->sCmn.LBRR_GainIncreases;
+                psEncCtrl->sCmn.GainsIndices[ 0 ] = SKP_LIMIT_int( psEncCtrl->sCmn.GainsIndices[ 0 ], 0, N_LEVELS_QGAIN - 1 );
+            }
+            /* Decode to get gains in sync with decoder         */
+            /* Overwrite unquantized gains with quantized gains */
+            SKP_Silk_gains_dequant( psEncCtrl->Gains_Q16, psEncCtrl->sCmn.GainsIndices, 
+                &psEnc->sCmn.LBRRprevLastGainIndex, psEnc->sCmn.nFramesInPayloadBuf );
+
+            /*****************************************/
+            /* Noise shaping quantization            */
+            /*****************************************/
+            if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
+                SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ_LBRR, xfw, psEnc->sCmn.q_LBRR, 
+                    psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, 
+                    psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, 
+                    psEncCtrl->Gains_Q16, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 );
+            } else {
+                SKP_Silk_NSQ( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ_LBRR, xfw, psEnc->sCmn.q_LBRR, 
+                    psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, 
+                    psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, 
+                    psEncCtrl->Gains_Q16, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 );
+            }
+        } else {
+            SKP_memset( psEnc->sCmn.q_LBRR, 0, psEnc->sCmn.frame_length * sizeof( SKP_int8 ) );
+            psEncCtrl->sCmn.LTP_scaleIndex = 0;
+        }
+        /****************************************/
+        /* Initialize arithmetic coder          */
+        /****************************************/
+        if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
+            SKP_Silk_range_enc_init( &psEnc->sCmn.sRC_LBRR );
+            psEnc->sCmn.nBytesInPayloadBuf = 0;
+        }
+
+        /****************************************/
+        /* Encode Parameters                    */
+        /****************************************/
+        SKP_Silk_encode_parameters( &psEnc->sCmn, &psEncCtrl->sCmn, 
+            &psEnc->sCmn.sRC_LBRR, psEnc->sCmn.q_LBRR );
+
+        if( psEnc->sCmn.sRC_LBRR.error ) {
+            /* Encoder returned error: clear payload buffer */
+            nFramesInPayloadBuf = 0;
+        } else {
+            nFramesInPayloadBuf = psEnc->sCmn.nFramesInPayloadBuf + 1;
+        }
+
+        /****************************************/
+        /* Finalize payload and copy to output  */
+        /****************************************/
+        if( SKP_SMULBB( nFramesInPayloadBuf, FRAME_LENGTH_MS ) >= psEnc->sCmn.PacketSize_ms ) {
+
+            /* Check if FEC information should be added */
+            frame_terminator = SKP_SILK_LAST_FRAME;
+
+            /* Add the frame termination info to stream */
+            SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_CDF );
+
+            /* Payload length so far */
+            SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC_LBRR, &nBytes );
+
+            /* Check that there is enough space in external output buffer and move data */
+            if( *pnBytesOut >= nBytes ) {
+                SKP_Silk_range_enc_wrap_up( &psEnc->sCmn.sRC_LBRR );
+                SKP_memcpy( pCode, psEnc->sCmn.sRC_LBRR.buffer, nBytes * sizeof( SKP_uint8 ) );
+
+                *pnBytesOut = nBytes;
+            } else {
+                /* Not enough space: payload will be discarded */
+                *pnBytesOut = 0;
+                SKP_assert( 0 );
+            }
+        } else {
+            /* No payload this time */
+            *pnBytesOut = 0;
+
+            /* Encode that more frames follows */
+            frame_terminator = SKP_SILK_MORE_FRAMES;
+            SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_CDF );
+        }
+
+        /* Restore original Gains */
+        SKP_memcpy( psEncCtrl->sCmn.GainsIndices, TempGainsIndices, NB_SUBFR * sizeof( SKP_int   ) );
+        SKP_memcpy( psEncCtrl->Gains_Q16,         TempGains_Q16,    NB_SUBFR * sizeof( SKP_int32 ) );
+    
+        /* Restore LTP scale index and typeoffset */
+        psEncCtrl->sCmn.LTP_scaleIndex = LTP_scaleIndex;
+        psEnc->sCmn.typeOffsetPrev = typeOffset;
+    }
+}
index d19d0c52cbfd4cab60cf493eab1c279be494275b..7ebc7332b32cd309b3941416b16243a0d24327b9 100644 (file)
-/***********************************************************************\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 parameters to create the payload */\r
-/*******************************************/\r
-void SKP_Silk_encode_parameters(\r
-    SKP_Silk_encoder_state          *psEncC,        /* I/O  Encoder state                   */\r
-    SKP_Silk_encoder_control        *psEncCtrlC,    /* I/O  Encoder control                 */\r
-    SKP_Silk_range_coder_state      *psRC,          /* I/O  Range encoder state             */\r
-    const SKP_int8                  *q              /* I    Quantization indices            */\r
-)\r
-{\r
-    SKP_int   i, k, typeOffset;\r
-    const SKP_Silk_NLSF_CB_struct *psNLSF_CB;\r
-\r
-\r
-    /************************/\r
-    /* Encode sampling rate */\r
-    /************************/\r
-    /* only done for first frame in packet */\r
-    if( psEncC->nFramesInPayloadBuf == 0 ) {\r
-        /* get sampling rate index */\r
-        for( i = 0; i < 3; i++ ) {\r
-            if( SKP_Silk_SamplingRates_table[ i ] == psEncC->fs_kHz ) {\r
-                break;\r
-            }\r
-        }\r
-        SKP_Silk_range_encoder( psRC, i, SKP_Silk_SamplingRates_CDF );\r
-    }\r
-\r
-    /*******************************************/\r
-    /* Encode signal type and quantizer offset */\r
-    /*******************************************/\r
-    typeOffset = 2 * psEncCtrlC->sigtype + psEncCtrlC->QuantOffsetType;\r
-    if( psEncC->nFramesInPayloadBuf == 0 ) {\r
-        /* first frame in packet: independent coding */\r
-        SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_CDF );\r
-    } else {\r
-        /* condidtional coding */\r
-        SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_joint_CDF[ psEncC->typeOffsetPrev ] );\r
-    }\r
-    psEncC->typeOffsetPrev = typeOffset;\r
-\r
-    /****************/\r
-    /* Encode gains */\r
-    /****************/\r
-    /* first subframe */\r
-    if( psEncC->nFramesInPayloadBuf == 0 ) {\r
-        /* first frame in packet: independent coding */\r
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_gain_CDF[ psEncCtrlC->sigtype ] );\r
-    } else {\r
-        /* condidtional coding */\r
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_delta_gain_CDF );\r
-    }\r
-\r
-    /* remaining subframes */\r
-    for( i = 1; i < NB_SUBFR; i++ ) {\r
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ i ], SKP_Silk_delta_gain_CDF );\r
-    }\r
-\r
-\r
-    /****************/\r
-    /* Encode NLSFs */\r
-    /****************/\r
-    /* Range encoding of the NLSF path */\r
-    psNLSF_CB = psEncC->psNLSF_CB[ psEncCtrlC->sigtype ];\r
-    SKP_Silk_range_encoder_multi( psRC, psEncCtrlC->NLSFIndices, psNLSF_CB->StartPtr, psNLSF_CB->nStages );\r
-\r
-    /* Encode NLSF interpolation factor */\r
-    SKP_assert( psEncC->useInterpolatedNLSFs == 1 || psEncCtrlC->NLSFInterpCoef_Q2 == ( 1 << 2 ) );\r
-    SKP_Silk_range_encoder( psRC, psEncCtrlC->NLSFInterpCoef_Q2, SKP_Silk_NLSF_interpolation_factor_CDF );\r
-\r
-\r
-    if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {\r
-        /*********************/\r
-        /* Encode pitch lags */\r
-        /*********************/\r
-\r
-\r
-        /* lag index */\r
-        if( psEncC->fs_kHz == 8 ) {\r
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_NB_CDF );\r
-        } else if( psEncC->fs_kHz == 12 ) {\r
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_MB_CDF );\r
-        } else if( psEncC->fs_kHz == 16 ) {\r
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_WB_CDF );\r
-        } else {\r
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_SWB_CDF );\r
-        }\r
-\r
-\r
-        /* countour index */\r
-        if( psEncC->fs_kHz == 8 ) {\r
-            /* Less codevectors used in 8 khz mode */\r
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_NB_CDF );\r
-        } else {\r
-            /* Joint for 12, 16, 24 khz */\r
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_CDF );\r
-        }\r
-\r
-        /********************/\r
-        /* Encode LTP gains */\r
-        /********************/\r
-\r
-        /* PERIndex value */\r
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->PERIndex, SKP_Silk_LTP_per_index_CDF );\r
-\r
-        /* Codebook Indices */\r
-        for( k = 0; k < NB_SUBFR; k++ ) {\r
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->LTPIndex[ k ], SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ] );\r
-        }\r
-\r
-        /**********************/\r
-        /* Encode LTP scaling */\r
-        /**********************/\r
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->LTP_scaleIndex, SKP_Silk_LTPscale_CDF );\r
-    }\r
-\r
-\r
-    /***************/\r
-    /* Encode seed */\r
-    /***************/\r
-    SKP_Silk_range_encoder( psRC, psEncCtrlC->Seed, SKP_Silk_Seed_CDF );\r
-\r
-    /*********************************************/\r
-    /* Encode quantization indices of excitation */\r
-    /*********************************************/\r
-    SKP_Silk_encode_pulses( psRC, psEncCtrlC->sigtype, psEncCtrlC->QuantOffsetType, q, psEncC->frame_length );\r
-\r
-\r
-    /*********************************************/\r
-    /* Encode VAD flag                           */\r
-    /*********************************************/\r
-    SKP_Silk_range_encoder( psRC, psEncC->vadFlag, SKP_Silk_vadflag_CDF );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/*******************************************/
+/* Encode parameters to create the payload */
+/*******************************************/
+void SKP_Silk_encode_parameters(
+    SKP_Silk_encoder_state          *psEncC,        /* I/O  Encoder state                   */
+    SKP_Silk_encoder_control        *psEncCtrlC,    /* I/O  Encoder control                 */
+    SKP_Silk_range_coder_state      *psRC,          /* I/O  Range encoder state             */
+    const SKP_int8                  *q              /* I    Quantization indices            */
+)
+{
+    SKP_int   i, k, typeOffset;
+    const SKP_Silk_NLSF_CB_struct *psNLSF_CB;
+
+
+    /************************/
+    /* Encode sampling rate */
+    /************************/
+    /* only done for first frame in packet */
+    if( psEncC->nFramesInPayloadBuf == 0 ) {
+        /* get sampling rate index */
+        for( i = 0; i < 3; i++ ) {
+            if( SKP_Silk_SamplingRates_table[ i ] == psEncC->fs_kHz ) {
+                break;
+            }
+        }
+        SKP_Silk_range_encoder( psRC, i, SKP_Silk_SamplingRates_CDF );
+    }
+
+    /*******************************************/
+    /* Encode signal type and quantizer offset */
+    /*******************************************/
+    typeOffset = 2 * psEncCtrlC->sigtype + psEncCtrlC->QuantOffsetType;
+    if( psEncC->nFramesInPayloadBuf == 0 ) {
+        /* first frame in packet: independent coding */
+        SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_CDF );
+    } else {
+        /* condidtional coding */
+        SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_joint_CDF[ psEncC->typeOffsetPrev ] );
+    }
+    psEncC->typeOffsetPrev = typeOffset;
+
+    /****************/
+    /* Encode gains */
+    /****************/
+    /* first subframe */
+    if( psEncC->nFramesInPayloadBuf == 0 ) {
+        /* first frame in packet: independent coding */
+        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_gain_CDF[ psEncCtrlC->sigtype ] );
+    } else {
+        /* condidtional coding */
+        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_delta_gain_CDF );
+    }
+
+    /* remaining subframes */
+    for( i = 1; i < NB_SUBFR; i++ ) {
+        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ i ], SKP_Silk_delta_gain_CDF );
+    }
+
+
+    /****************/
+    /* Encode NLSFs */
+    /****************/
+    /* Range encoding of the NLSF path */
+    psNLSF_CB = psEncC->psNLSF_CB[ psEncCtrlC->sigtype ];
+    SKP_Silk_range_encoder_multi( psRC, psEncCtrlC->NLSFIndices, psNLSF_CB->StartPtr, psNLSF_CB->nStages );
+
+    /* Encode NLSF interpolation factor */
+    SKP_assert( psEncC->useInterpolatedNLSFs == 1 || psEncCtrlC->NLSFInterpCoef_Q2 == ( 1 << 2 ) );
+    SKP_Silk_range_encoder( psRC, psEncCtrlC->NLSFInterpCoef_Q2, SKP_Silk_NLSF_interpolation_factor_CDF );
+
+
+    if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
+        /*********************/
+        /* Encode pitch lags */
+        /*********************/
+
+
+        /* lag index */
+        if( psEncC->fs_kHz == 8 ) {
+            SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_NB_CDF );
+        } else if( psEncC->fs_kHz == 12 ) {
+            SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_MB_CDF );
+        } else if( psEncC->fs_kHz == 16 ) {
+            SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_WB_CDF );
+        } else {
+            SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_SWB_CDF );
+        }
+
+
+        /* countour index */
+        if( psEncC->fs_kHz == 8 ) {
+            /* Less codevectors used in 8 khz mode */
+            SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_NB_CDF );
+        } else {
+            /* Joint for 12, 16, 24 khz */
+            SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_CDF );
+        }
+
+        /********************/
+        /* Encode LTP gains */
+        /********************/
+
+        /* PERIndex value */
+        SKP_Silk_range_encoder( psRC, psEncCtrlC->PERIndex, SKP_Silk_LTP_per_index_CDF );
+
+        /* Codebook Indices */
+        for( k = 0; k < NB_SUBFR; k++ ) {
+            SKP_Silk_range_encoder( psRC, psEncCtrlC->LTPIndex[ k ], SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ] );
+        }
+
+        /**********************/
+        /* Encode LTP scaling */
+        /**********************/
+        SKP_Silk_range_encoder( psRC, psEncCtrlC->LTP_scaleIndex, SKP_Silk_LTPscale_CDF );
+    }
+
+
+    /***************/
+    /* Encode seed */
+    /***************/
+    SKP_Silk_range_encoder( psRC, psEncCtrlC->Seed, SKP_Silk_Seed_CDF );
+
+    /*********************************************/
+    /* Encode quantization indices of excitation */
+    /*********************************************/
+    SKP_Silk_encode_pulses( psRC, psEncCtrlC->sigtype, psEncCtrlC->QuantOffsetType, q, psEncC->frame_length );
+
+
+    /*********************************************/
+    /* Encode VAD flag                           */
+    /*********************************************/
+    SKP_Silk_range_encoder( psRC, psEncC->vadFlag, SKP_Silk_vadflag_CDF );
+}
index f25ff76277541872ac077235e8c65f8aaea49a2a..3a61ee195e4a7eaaed4aac7fcc7d71aff7d695a8 100644 (file)
-/***********************************************************************\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 quantization indices of excitation */\r
-/*********************************************/\r
-\r
-SKP_INLINE SKP_int combine_and_check(       /* return ok */\r
-    SKP_int         *pulses_comb,           /* O */\r
-    const SKP_int   *pulses_in,             /* I */\r
-    SKP_int         max_pulses,             /* I    max value for sum of pulses */\r
-    SKP_int         len                     /* I    number of output values */\r
-) \r
-{\r
-    SKP_int k, sum;\r
-\r
-    for( k = 0; k < len; k++ ) {\r
-        sum = pulses_in[ 2 * k ] + pulses_in[ 2 * k + 1 ];\r
-        if( sum > max_pulses ) {\r
-            return 1;\r
-        }\r
-        pulses_comb[ k ] = sum;\r
-    }\r
-\r
-    return 0;\r
-}\r
-\r
-/* Encode quantization indices of excitation */\r
-void SKP_Silk_encode_pulses(\r
-    SKP_Silk_range_coder_state      *psRC,          /* I/O  Range coder state               */\r
-    const SKP_int                   sigtype,        /* I    Sigtype                         */\r
-    const SKP_int                   QuantOffsetType,/* I    QuantOffsetType                 */\r
-    const SKP_int8                  q[],            /* I    quantization indices            */\r
-    const SKP_int                   frame_length    /* I    Frame length                    */\r
-)\r
-{\r
-    SKP_int   i, k, j, iter, bit, nLS, scale_down, RateLevelIndex = 0;\r
-    SKP_int32 abs_q, minSumBits_Q6, sumBits_Q6;\r
-    SKP_int   abs_pulses[ MAX_FRAME_LENGTH ];\r
-    SKP_int   sum_pulses[ MAX_NB_SHELL_BLOCKS ];\r
-    SKP_int   nRshifts[   MAX_NB_SHELL_BLOCKS ];\r
-    SKP_int   pulses_comb[ 8 ];\r
-    SKP_int   *abs_pulses_ptr;\r
-    const SKP_int8 *pulses_ptr;\r
-    const SKP_uint16 *cdf_ptr;\r
-    const SKP_int16 *nBits_ptr;\r
-\r
-    SKP_memset( pulses_comb, 0, 8 * sizeof( SKP_int ) ); // Fixing Valgrind reported problem\r
-\r
-    /****************************/\r
-    /* Prepare for shell coding */\r
-    /****************************/\r
-    /* Calculate number of shell blocks */\r
-    iter = frame_length / SHELL_CODEC_FRAME_LENGTH;\r
-    \r
-    /* Take the absolute value of the pulses */\r
-    for( i = 0; i < frame_length; i+=4 ) {\r
-        abs_pulses[i+0] = ( SKP_int )SKP_abs( q[ i + 0 ] );\r
-        abs_pulses[i+1] = ( SKP_int )SKP_abs( q[ i + 1 ] );\r
-        abs_pulses[i+2] = ( SKP_int )SKP_abs( q[ i + 2 ] );\r
-        abs_pulses[i+3] = ( SKP_int )SKP_abs( q[ i + 3 ] );\r
-    }\r
-\r
-    /* Calc sum pulses per shell code frame */\r
-    abs_pulses_ptr = abs_pulses;\r
-    for( i = 0; i < iter; i++ ) {\r
-        nRshifts[ i ] = 0;\r
-\r
-        while( 1 ) {\r
-            /* 1+1 -> 2 */\r
-            scale_down = combine_and_check( pulses_comb, abs_pulses_ptr, SKP_Silk_max_pulses_table[ 0 ], 8 );\r
-\r
-            /* 2+2 -> 4 */\r
-            scale_down += combine_and_check( pulses_comb, pulses_comb, SKP_Silk_max_pulses_table[ 1 ], 4 );\r
-\r
-            /* 4+4 -> 8 */\r
-            scale_down += combine_and_check( pulses_comb, pulses_comb, SKP_Silk_max_pulses_table[ 2 ], 2 );\r
-\r
-            /* 8+8 -> 16 */\r
-            sum_pulses[ i ] = pulses_comb[ 0 ] + pulses_comb[ 1 ];\r
-            if( sum_pulses[ i ] > SKP_Silk_max_pulses_table[ 3 ] ) {\r
-                scale_down++;\r
-            }\r
-\r
-            if( scale_down ) {\r
-                /* We need to down scale the quantization signal */\r
-                nRshifts[ i ]++;                \r
-                for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) {\r
-                    abs_pulses_ptr[ k ] = SKP_RSHIFT( abs_pulses_ptr[ k ], 1 );\r
-                }\r
-            } else {\r
-                /* Jump out of while(1) loop and go to next shell coding frame */\r
-                break;\r
-            }\r
-        }\r
-        abs_pulses_ptr += SHELL_CODEC_FRAME_LENGTH;\r
-    }\r
-\r
-    /**************/\r
-    /* Rate level */\r
-    /**************/\r
-    /* find rate level that leads to fewest bits for coding of pulses per block info */\r
-    minSumBits_Q6 = SKP_int32_MAX;\r
-    for( k = 0; k < N_RATE_LEVELS - 1; k++ ) {\r
-        nBits_ptr  = SKP_Silk_pulses_per_block_BITS_Q6[ k ];\r
-        sumBits_Q6 = SKP_Silk_rate_levels_BITS_Q6[sigtype][ k ];\r
-        for( i = 0; i < iter; i++ ) {\r
-            if( nRshifts[ i ] > 0 ) {\r
-                sumBits_Q6 += nBits_ptr[ MAX_PULSES + 1 ];\r
-            } else {\r
-                sumBits_Q6 += nBits_ptr[ sum_pulses[ i ] ];\r
-            }\r
-        }\r
-        if( sumBits_Q6 < minSumBits_Q6 ) {\r
-            minSumBits_Q6 = sumBits_Q6;\r
-            RateLevelIndex = k;\r
-        }\r
-    }\r
-    SKP_Silk_range_encoder( psRC, RateLevelIndex, SKP_Silk_rate_levels_CDF[ sigtype ] );\r
-\r
-    /***************************************************/\r
-    /* Sum-Weighted-Pulses Encoding                    */\r
-    /***************************************************/\r
-    cdf_ptr = SKP_Silk_pulses_per_block_CDF[ RateLevelIndex ];\r
-    for( i = 0; i < iter; i++ ) {\r
-        if( nRshifts[ i ] == 0 ) {\r
-            SKP_Silk_range_encoder( psRC, sum_pulses[ i ], cdf_ptr );\r
-        } else {\r
-            SKP_Silk_range_encoder( psRC, MAX_PULSES + 1, cdf_ptr );\r
-            for( k = 0; k < nRshifts[ i ] - 1; k++ ) {\r
-                SKP_Silk_range_encoder( psRC, MAX_PULSES + 1, SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ] );\r
-            }\r
-            SKP_Silk_range_encoder( psRC, sum_pulses[ i ], SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ] );\r
-        }\r
-    }\r
-\r
-    /******************/\r
-    /* Shell Encoding */\r
-    /******************/\r
-    for( i = 0; i < iter; i++ ) {\r
-        if( sum_pulses[ i ] > 0 ) {\r
-            SKP_Silk_shell_encoder( psRC, &abs_pulses[ i * SHELL_CODEC_FRAME_LENGTH ] );\r
-        }\r
-    }\r
-\r
-    /****************/\r
-    /* LSB Encoding */\r
-    /****************/\r
-    for( i = 0; i < iter; i++ ) {\r
-        if( nRshifts[ i ] > 0 ) {\r
-            pulses_ptr = &q[ i * SHELL_CODEC_FRAME_LENGTH ];\r
-            nLS = nRshifts[ i ] - 1;\r
-            for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) {\r
-                abs_q = (SKP_int8)SKP_abs( pulses_ptr[ k ] );\r
-                for( j = nLS; j > 0; j-- ) {\r
-                    bit = SKP_RSHIFT( abs_q, j ) & 1;\r
-                    SKP_Silk_range_encoder( psRC, bit, SKP_Silk_lsb_CDF );\r
-                }\r
-                bit = abs_q & 1;\r
-                SKP_Silk_range_encoder( psRC, bit, SKP_Silk_lsb_CDF );\r
-            }\r
-        }\r
-    }\r
-\r
-    /****************/\r
-    /* Encode signs */\r
-    /****************/\r
-    SKP_Silk_encode_signs( psRC, q, frame_length, sigtype, QuantOffsetType, RateLevelIndex );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/*********************************************/
+/* Encode quantization indices of excitation */
+/*********************************************/
+
+SKP_INLINE SKP_int combine_and_check(       /* return ok */
+    SKP_int         *pulses_comb,           /* O */
+    const SKP_int   *pulses_in,             /* I */
+    SKP_int         max_pulses,             /* I    max value for sum of pulses */
+    SKP_int         len                     /* I    number of output values */
+) 
+{
+    SKP_int k, sum;
+
+    for( k = 0; k < len; k++ ) {
+        sum = pulses_in[ 2 * k ] + pulses_in[ 2 * k + 1 ];
+        if( sum > max_pulses ) {
+            return 1;
+        }
+        pulses_comb[ k ] = sum;
+    }
+
+    return 0;
+}
+
+/* Encode quantization indices of excitation */
+void SKP_Silk_encode_pulses(
+    SKP_Silk_range_coder_state      *psRC,          /* I/O  Range coder state               */
+    const SKP_int                   sigtype,        /* I    Sigtype                         */
+    const SKP_int                   QuantOffsetType,/* I    QuantOffsetType                 */
+    const SKP_int8                  q[],            /* I    quantization indices            */
+    const SKP_int                   frame_length    /* I    Frame length                    */
+)
+{
+    SKP_int   i, k, j, iter, bit, nLS, scale_down, RateLevelIndex = 0;
+    SKP_int32 abs_q, minSumBits_Q6, sumBits_Q6;
+    SKP_int   abs_pulses[ MAX_FRAME_LENGTH ];
+    SKP_int   sum_pulses[ MAX_NB_SHELL_BLOCKS ];
+    SKP_int   nRshifts[   MAX_NB_SHELL_BLOCKS ];
+    SKP_int   pulses_comb[ 8 ];
+    SKP_int   *abs_pulses_ptr;
+    const SKP_int8 *pulses_ptr;
+    const SKP_uint16 *cdf_ptr;
+    const SKP_int16 *nBits_ptr;
+
+    SKP_memset( pulses_comb, 0, 8 * sizeof( SKP_int ) ); // Fixing Valgrind reported problem
+
+    /****************************/
+    /* Prepare for shell coding */
+    /****************************/
+    /* Calculate number of shell blocks */
+    iter = frame_length / SHELL_CODEC_FRAME_LENGTH;
+    
+    /* Take the absolute value of the pulses */
+    for( i = 0; i < frame_length; i+=4 ) {
+        abs_pulses[i+0] = ( SKP_int )SKP_abs( q[ i + 0 ] );
+        abs_pulses[i+1] = ( SKP_int )SKP_abs( q[ i + 1 ] );
+        abs_pulses[i+2] = ( SKP_int )SKP_abs( q[ i + 2 ] );
+        abs_pulses[i+3] = ( SKP_int )SKP_abs( q[ i + 3 ] );
+    }
+
+    /* Calc sum pulses per shell code frame */
+    abs_pulses_ptr = abs_pulses;
+    for( i = 0; i < iter; i++ ) {
+        nRshifts[ i ] = 0;
+
+        while( 1 ) {
+            /* 1+1 -> 2 */
+            scale_down = combine_and_check( pulses_comb, abs_pulses_ptr, SKP_Silk_max_pulses_table[ 0 ], 8 );
+
+            /* 2+2 -> 4 */
+            scale_down += combine_and_check( pulses_comb, pulses_comb, SKP_Silk_max_pulses_table[ 1 ], 4 );
+
+            /* 4+4 -> 8 */
+            scale_down += combine_and_check( pulses_comb, pulses_comb, SKP_Silk_max_pulses_table[ 2 ], 2 );
+
+            /* 8+8 -> 16 */
+            sum_pulses[ i ] = pulses_comb[ 0 ] + pulses_comb[ 1 ];
+            if( sum_pulses[ i ] > SKP_Silk_max_pulses_table[ 3 ] ) {
+                scale_down++;
+            }
+
+            if( scale_down ) {
+                /* We need to down scale the quantization signal */
+                nRshifts[ i ]++;                
+                for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) {
+                    abs_pulses_ptr[ k ] = SKP_RSHIFT( abs_pulses_ptr[ k ], 1 );
+                }
+            } else {
+                /* Jump out of while(1) loop and go to next shell coding frame */
+                break;
+            }
+        }
+        abs_pulses_ptr += SHELL_CODEC_FRAME_LENGTH;
+    }
+
+    /**************/
+    /* Rate level */
+    /**************/
+    /* find rate level that leads to fewest bits for coding of pulses per block info */
+    minSumBits_Q6 = SKP_int32_MAX;
+    for( k = 0; k < N_RATE_LEVELS - 1; k++ ) {
+        nBits_ptr  = SKP_Silk_pulses_per_block_BITS_Q6[ k ];
+        sumBits_Q6 = SKP_Silk_rate_levels_BITS_Q6[sigtype][ k ];
+        for( i = 0; i < iter; i++ ) {
+            if( nRshifts[ i ] > 0 ) {
+                sumBits_Q6 += nBits_ptr[ MAX_PULSES + 1 ];
+            } else {
+                sumBits_Q6 += nBits_ptr[ sum_pulses[ i ] ];
+            }
+        }
+        if( sumBits_Q6 < minSumBits_Q6 ) {
+            minSumBits_Q6 = sumBits_Q6;
+            RateLevelIndex = k;
+        }
+    }
+    SKP_Silk_range_encoder( psRC, RateLevelIndex, SKP_Silk_rate_levels_CDF[ sigtype ] );
+
+    /***************************************************/
+    /* Sum-Weighted-Pulses Encoding                    */
+    /***************************************************/
+    cdf_ptr = SKP_Silk_pulses_per_block_CDF[ RateLevelIndex ];
+    for( i = 0; i < iter; i++ ) {
+        if( nRshifts[ i ] == 0 ) {
+            SKP_Silk_range_encoder( psRC, sum_pulses[ i ], cdf_ptr );
+        } else {
+            SKP_Silk_range_encoder( psRC, MAX_PULSES + 1, cdf_ptr );
+            for( k = 0; k < nRshifts[ i ] - 1; k++ ) {
+                SKP_Silk_range_encoder( psRC, MAX_PULSES + 1, SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ] );
+            }
+            SKP_Silk_range_encoder( psRC, sum_pulses[ i ], SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ] );
+        }
+    }
+
+    /******************/
+    /* Shell Encoding */
+    /******************/
+    for( i = 0; i < iter; i++ ) {
+        if( sum_pulses[ i ] > 0 ) {
+            SKP_Silk_shell_encoder( psRC, &abs_pulses[ i * SHELL_CODEC_FRAME_LENGTH ] );
+        }
+    }
+
+    /****************/
+    /* LSB Encoding */
+    /****************/
+    for( i = 0; i < iter; i++ ) {
+        if( nRshifts[ i ] > 0 ) {
+            pulses_ptr = &q[ i * SHELL_CODEC_FRAME_LENGTH ];
+            nLS = nRshifts[ i ] - 1;
+            for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) {
+                abs_q = (SKP_int8)SKP_abs( pulses_ptr[ k ] );
+                for( j = nLS; j > 0; j-- ) {
+                    bit = SKP_RSHIFT( abs_q, j ) & 1;
+                    SKP_Silk_range_encoder( psRC, bit, SKP_Silk_lsb_CDF );
+                }
+                bit = abs_q & 1;
+                SKP_Silk_range_encoder( psRC, bit, SKP_Silk_lsb_CDF );
+            }
+        }
+    }
+
+    /****************/
+    /* Encode signs */
+    /****************/
+    SKP_Silk_encode_signs( psRC, q, frame_length, sigtype, QuantOffsetType, RateLevelIndex );
+}
index 95308ff315ebf3109ed6b561a0aac39f873f6b1a..0d2ef58d3418baab769ed3a766c40ce90e0b83eb 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-#include "SKP_Silk_tuning_parameters.h"\r
-\r
-/* Finds LPC vector from correlations, and converts to NLSF */\r
-void SKP_Silk_find_LPC_FIX(\r
-    SKP_int             NLSF_Q15[],             /* O    NLSFs                                                                       */\r
-    SKP_int             *interpIndex,           /* O    NLSF interpolation index, only used for NLSF interpolation                  */\r
-    const SKP_int       prev_NLSFq_Q15[],       /* I    previous NLSFs, only used for NLSF interpolation                            */\r
-    const SKP_int       useInterpolatedNLSFs,   /* I    Flag                                                                        */\r
-    const SKP_int       LPC_order,              /* I    LPC order                                                                   */\r
-    const SKP_int16     x[],                    /* I    Input signal                                                                */\r
-    const SKP_int       subfr_length            /* I    Input signal subframe length including preceeding samples                   */\r
-)\r
-{\r
-    SKP_int     k;\r
-    SKP_int32   a_Q16[ MAX_LPC_ORDER ];\r
-    SKP_int     isInterpLower, shift;\r
-    SKP_int16   S[ MAX_LPC_ORDER ];\r
-    SKP_int32   res_nrg0, res_nrg1;\r
-    SKP_int     rshift0, rshift1; \r
-\r
-    /* Used only for LSF interpolation */\r
-    SKP_int32   a_tmp_Q16[ MAX_LPC_ORDER ], res_nrg_interp, res_nrg, res_tmp_nrg, res_nrg_2nd;\r
-    SKP_int     res_nrg_interp_Q, res_nrg_Q, res_tmp_nrg_Q, res_nrg_2nd_Q;\r
-    SKP_int16   a_tmp_Q12[ MAX_LPC_ORDER ];\r
-    SKP_int     NLSF0_Q15[ MAX_LPC_ORDER ];\r
-    SKP_int16   LPC_res[ ( MAX_FRAME_LENGTH + NB_SUBFR * MAX_LPC_ORDER ) / 2 ];\r
-\r
-    /* Default: no interpolation */\r
-    *interpIndex = 4;\r
-\r
-    /* Burg AR analysis for the full frame */\r
-    SKP_Silk_burg_modified( &res_nrg, &res_nrg_Q, a_Q16, x, subfr_length, NB_SUBFR, SKP_FIX_CONST( FIND_LPC_COND_FAC, 32 ), LPC_order );\r
-\r
-    SKP_Silk_bwexpander_32( a_Q16, LPC_order, SKP_FIX_CONST( FIND_LPC_CHIRP, 16 ) );\r
-\r
-    if( useInterpolatedNLSFs == 1 ) {\r
-\r
-        /* Optimal solution for last 10 ms */\r
-        SKP_Silk_burg_modified( &res_tmp_nrg, &res_tmp_nrg_Q, a_tmp_Q16, x + ( NB_SUBFR >> 1 ) * subfr_length, \r
-            subfr_length, ( NB_SUBFR >> 1 ), SKP_FIX_CONST( FIND_LPC_COND_FAC, 32 ), LPC_order );\r
-\r
-        SKP_Silk_bwexpander_32( a_tmp_Q16, LPC_order, SKP_FIX_CONST( FIND_LPC_CHIRP, 16 ) );\r
-\r
-        /* subtract residual energy here, as that's easier than adding it to the    */\r
-        /* residual energy of the first 10 ms in each iteration of the search below */\r
-        shift = res_tmp_nrg_Q - res_nrg_Q;\r
-        if( shift >= 0 ) {\r
-            if( shift < 32 ) { \r
-                res_nrg = res_nrg - SKP_RSHIFT( res_tmp_nrg, shift );\r
-            }\r
-        } else {\r
-            SKP_assert( shift > -32 ); \r
-            res_nrg   = SKP_RSHIFT( res_nrg, -shift ) - res_tmp_nrg;\r
-            res_nrg_Q = res_tmp_nrg_Q; \r
-        }\r
-        \r
-        /* Convert to NLSFs */\r
-        SKP_Silk_A2NLSF( NLSF_Q15, a_tmp_Q16, LPC_order );\r
-\r
-        /* Search over interpolation indices to find the one with lowest residual energy */\r
-        res_nrg_2nd = SKP_int32_MAX;\r
-        for( k = 3; k >= 0; k-- ) {\r
-            /* Interpolate NLSFs for first half */\r
-            SKP_Silk_interpolate( NLSF0_Q15, prev_NLSFq_Q15, NLSF_Q15, k, LPC_order );\r
-\r
-            /* Convert to LPC for residual energy evaluation */\r
-            SKP_Silk_NLSF2A_stable( a_tmp_Q12, NLSF0_Q15, LPC_order );\r
-\r
-            /* Calculate residual energy with NLSF interpolation */\r
-            SKP_memset( S, 0, LPC_order * sizeof( SKP_int16 ) );\r
-            SKP_Silk_LPC_analysis_filter( x, a_tmp_Q12, S, LPC_res, 2 * subfr_length, LPC_order );\r
-\r
-            SKP_Silk_sum_sqr_shift( &res_nrg0, &rshift0, LPC_res + LPC_order,                subfr_length - LPC_order );\r
-            SKP_Silk_sum_sqr_shift( &res_nrg1, &rshift1, LPC_res + LPC_order + subfr_length, subfr_length - LPC_order );\r
-\r
-            /* Add subframe energies from first half frame */\r
-            shift = rshift0 - rshift1;\r
-            if( shift >= 0 ) {\r
-                res_nrg1         = SKP_RSHIFT( res_nrg1, shift );\r
-                res_nrg_interp_Q = -rshift0;\r
-            } else {\r
-                res_nrg0         = SKP_RSHIFT( res_nrg0, -shift );\r
-                res_nrg_interp_Q = -rshift1;\r
-            }\r
-            res_nrg_interp = SKP_ADD32( res_nrg0, res_nrg1 );\r
-\r
-            /* Compare with first half energy without NLSF interpolation, or best interpolated value so far */\r
-            shift = res_nrg_interp_Q - res_nrg_Q;\r
-            if( shift >= 0 ) {\r
-                if( SKP_RSHIFT( res_nrg_interp, shift ) < res_nrg ) {\r
-                    isInterpLower = SKP_TRUE;\r
-                } else {\r
-                    isInterpLower = SKP_FALSE;\r
-                }\r
-            } else {\r
-                if( -shift < 32 ) { \r
-                    if( res_nrg_interp < SKP_RSHIFT( res_nrg, -shift ) ) {\r
-                        isInterpLower = SKP_TRUE;\r
-                    } else {\r
-                        isInterpLower = SKP_FALSE;\r
-                    }\r
-                } else {\r
-                    isInterpLower = SKP_FALSE;\r
-                }\r
-            }\r
-\r
-            /* Determine whether current interpolated NLSFs are best so far */\r
-            if( isInterpLower == SKP_TRUE ) {\r
-                /* Interpolation has lower residual energy */\r
-                res_nrg   = res_nrg_interp;\r
-                res_nrg_Q = res_nrg_interp_Q;\r
-                *interpIndex = k;\r
-            }\r
-            res_nrg_2nd   = res_nrg_interp;\r
-            res_nrg_2nd_Q = res_nrg_interp_Q;\r
-        }\r
-    }\r
-\r
-    if( *interpIndex == 4 ) {\r
-        /* NLSF interpolation is currently inactive, calculate NLSFs from full frame AR coefficients */\r
-        SKP_Silk_A2NLSF( NLSF_Q15, a_Q16, LPC_order );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_tuning_parameters.h"
+
+/* Finds LPC vector from correlations, and converts to NLSF */
+void SKP_Silk_find_LPC_FIX(
+    SKP_int             NLSF_Q15[],             /* O    NLSFs                                                                       */
+    SKP_int             *interpIndex,           /* O    NLSF interpolation index, only used for NLSF interpolation                  */
+    const SKP_int       prev_NLSFq_Q15[],       /* I    previous NLSFs, only used for NLSF interpolation                            */
+    const SKP_int       useInterpolatedNLSFs,   /* I    Flag                                                                        */
+    const SKP_int       LPC_order,              /* I    LPC order                                                                   */
+    const SKP_int16     x[],                    /* I    Input signal                                                                */
+    const SKP_int       subfr_length            /* I    Input signal subframe length including preceeding samples                   */
+)
+{
+    SKP_int     k;
+    SKP_int32   a_Q16[ MAX_LPC_ORDER ];
+    SKP_int     isInterpLower, shift;
+    SKP_int16   S[ MAX_LPC_ORDER ];
+    SKP_int32   res_nrg0, res_nrg1;
+    SKP_int     rshift0, rshift1; 
+
+    /* Used only for LSF interpolation */
+    SKP_int32   a_tmp_Q16[ MAX_LPC_ORDER ], res_nrg_interp, res_nrg, res_tmp_nrg, res_nrg_2nd;
+    SKP_int     res_nrg_interp_Q, res_nrg_Q, res_tmp_nrg_Q, res_nrg_2nd_Q;
+    SKP_int16   a_tmp_Q12[ MAX_LPC_ORDER ];
+    SKP_int     NLSF0_Q15[ MAX_LPC_ORDER ];
+    SKP_int16   LPC_res[ ( MAX_FRAME_LENGTH + NB_SUBFR * MAX_LPC_ORDER ) / 2 ];
+
+    /* Default: no interpolation */
+    *interpIndex = 4;
+
+    /* Burg AR analysis for the full frame */
+    SKP_Silk_burg_modified( &res_nrg, &res_nrg_Q, a_Q16, x, subfr_length, NB_SUBFR, SKP_FIX_CONST( FIND_LPC_COND_FAC, 32 ), LPC_order );
+
+    SKP_Silk_bwexpander_32( a_Q16, LPC_order, SKP_FIX_CONST( FIND_LPC_CHIRP, 16 ) );
+
+    if( useInterpolatedNLSFs == 1 ) {
+
+        /* Optimal solution for last 10 ms */
+        SKP_Silk_burg_modified( &res_tmp_nrg, &res_tmp_nrg_Q, a_tmp_Q16, x + ( NB_SUBFR >> 1 ) * subfr_length, 
+            subfr_length, ( NB_SUBFR >> 1 ), SKP_FIX_CONST( FIND_LPC_COND_FAC, 32 ), LPC_order );
+
+        SKP_Silk_bwexpander_32( a_tmp_Q16, LPC_order, SKP_FIX_CONST( FIND_LPC_CHIRP, 16 ) );
+
+        /* subtract residual energy here, as that's easier than adding it to the    */
+        /* residual energy of the first 10 ms in each iteration of the search below */
+        shift = res_tmp_nrg_Q - res_nrg_Q;
+        if( shift >= 0 ) {
+            if( shift < 32 ) { 
+                res_nrg = res_nrg - SKP_RSHIFT( res_tmp_nrg, shift );
+            }
+        } else {
+            SKP_assert( shift > -32 ); 
+            res_nrg   = SKP_RSHIFT( res_nrg, -shift ) - res_tmp_nrg;
+            res_nrg_Q = res_tmp_nrg_Q; 
+        }
+        
+        /* Convert to NLSFs */
+        SKP_Silk_A2NLSF( NLSF_Q15, a_tmp_Q16, LPC_order );
+
+        /* Search over interpolation indices to find the one with lowest residual energy */
+        res_nrg_2nd = SKP_int32_MAX;
+        for( k = 3; k >= 0; k-- ) {
+            /* Interpolate NLSFs for first half */
+            SKP_Silk_interpolate( NLSF0_Q15, prev_NLSFq_Q15, NLSF_Q15, k, LPC_order );
+
+            /* Convert to LPC for residual energy evaluation */
+            SKP_Silk_NLSF2A_stable( a_tmp_Q12, NLSF0_Q15, LPC_order );
+
+            /* Calculate residual energy with NLSF interpolation */
+            SKP_memset( S, 0, LPC_order * sizeof( SKP_int16 ) );
+            SKP_Silk_LPC_analysis_filter( x, a_tmp_Q12, S, LPC_res, 2 * subfr_length, LPC_order );
+
+            SKP_Silk_sum_sqr_shift( &res_nrg0, &rshift0, LPC_res + LPC_order,                subfr_length - LPC_order );
+            SKP_Silk_sum_sqr_shift( &res_nrg1, &rshift1, LPC_res + LPC_order + subfr_length, subfr_length - LPC_order );
+
+            /* Add subframe energies from first half frame */
+            shift = rshift0 - rshift1;
+            if( shift >= 0 ) {
+                res_nrg1         = SKP_RSHIFT( res_nrg1, shift );
+                res_nrg_interp_Q = -rshift0;
+            } else {
+                res_nrg0         = SKP_RSHIFT( res_nrg0, -shift );
+                res_nrg_interp_Q = -rshift1;
+            }
+            res_nrg_interp = SKP_ADD32( res_nrg0, res_nrg1 );
+
+            /* Compare with first half energy without NLSF interpolation, or best interpolated value so far */
+            shift = res_nrg_interp_Q - res_nrg_Q;
+            if( shift >= 0 ) {
+                if( SKP_RSHIFT( res_nrg_interp, shift ) < res_nrg ) {
+                    isInterpLower = SKP_TRUE;
+                } else {
+                    isInterpLower = SKP_FALSE;
+                }
+            } else {
+                if( -shift < 32 ) { 
+                    if( res_nrg_interp < SKP_RSHIFT( res_nrg, -shift ) ) {
+                        isInterpLower = SKP_TRUE;
+                    } else {
+                        isInterpLower = SKP_FALSE;
+                    }
+                } else {
+                    isInterpLower = SKP_FALSE;
+                }
+            }
+
+            /* Determine whether current interpolated NLSFs are best so far */
+            if( isInterpLower == SKP_TRUE ) {
+                /* Interpolation has lower residual energy */
+                res_nrg   = res_nrg_interp;
+                res_nrg_Q = res_nrg_interp_Q;
+                *interpIndex = k;
+            }
+            res_nrg_2nd   = res_nrg_interp;
+            res_nrg_2nd_Q = res_nrg_interp_Q;
+        }
+    }
+
+    if( *interpIndex == 4 ) {
+        /* NLSF interpolation is currently inactive, calculate NLSFs from full frame AR coefficients */
+        SKP_Silk_A2NLSF( NLSF_Q15, a_Q16, LPC_order );
+    }
+}
index 35ac03f9ddd5434657f2294951870ff20a8752bc..f119b1a4fe135f415a29c4d56f128e6e4967333f 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-#include "SKP_Silk_tuning_parameters.h"\r
-\r
-/* Head room for correlations                           */\r
-#define LTP_CORRS_HEAD_ROOM                             2\r
-\r
-void SKP_Silk_fit_LTP(\r
-    SKP_int32 LTP_coefs_Q16[ LTP_ORDER ],\r
-    SKP_int16 LTP_coefs_Q14[ LTP_ORDER ]\r
-);\r
-\r
-void SKP_Silk_find_LTP_FIX(\r
-    SKP_int16           b_Q14[ NB_SUBFR * LTP_ORDER ],              /* O    LTP coefs                                                   */\r
-    SKP_int32           WLTP[ NB_SUBFR * LTP_ORDER * LTP_ORDER ],   /* O    Weight for LTP quantization                                 */\r
-    SKP_int             *LTPredCodGain_Q7,                          /* O    LTP coding gain                                             */\r
-    const SKP_int16     r_first[],                                  /* I    residual signal after LPC signal + state for first 10 ms    */\r
-    const SKP_int16     r_last[],                                   /* I    residual signal after LPC signal + state for last 10 ms     */\r
-    const SKP_int       lag[ NB_SUBFR ],                            /* I    LTP lags                                                    */\r
-    const SKP_int32     Wght_Q15[ NB_SUBFR ],                       /* I    weights                                                     */\r
-    const SKP_int       subfr_length,                               /* I    subframe length                                             */\r
-    const SKP_int       mem_offset,                                 /* I    number of samples in LTP memory                             */\r
-    SKP_int             corr_rshifts[ NB_SUBFR ]                    /* O    right shifts applied to correlations                        */\r
-)\r
-{\r
-    SKP_int   i, k, lshift;\r
-    const SKP_int16 *r_ptr, *lag_ptr;\r
-    SKP_int16 *b_Q14_ptr;\r
-\r
-    SKP_int32 regu;\r
-    SKP_int32 *WLTP_ptr;\r
-    SKP_int32 b_Q16[ LTP_ORDER ], delta_b_Q14[ LTP_ORDER ], d_Q14[ NB_SUBFR ], nrg[ NB_SUBFR ], g_Q26;\r
-    SKP_int32 w[ NB_SUBFR ], WLTP_max, max_abs_d_Q14, max_w_bits;\r
-\r
-    SKP_int32 temp32, denom32;\r
-    SKP_int   extra_shifts;\r
-    SKP_int   rr_shifts, maxRshifts, maxRshifts_wxtra, LZs;\r
-    SKP_int32 LPC_res_nrg, LPC_LTP_res_nrg, div_Q16;\r
-    SKP_int32 Rr[ LTP_ORDER ], rr[ NB_SUBFR ];\r
-    SKP_int32 wd, m_Q12;\r
-    \r
-    b_Q14_ptr = b_Q14;\r
-    WLTP_ptr  = WLTP;\r
-    r_ptr     = &r_first[ mem_offset ];\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        if( k == ( NB_SUBFR >> 1 ) ) { /* shift residual for last 10 ms */\r
-            r_ptr = &r_last[ mem_offset ];\r
-        }\r
-        lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 );\r
-\r
-        SKP_Silk_sum_sqr_shift( &rr[ k ], &rr_shifts, r_ptr, subfr_length ); /* rr[ k ] in Q( -rr_shifts ) */\r
-\r
-        /* Assure headroom */\r
-        LZs = SKP_Silk_CLZ32( rr[k] );\r
-        if( LZs < LTP_CORRS_HEAD_ROOM ) {\r
-            rr[ k ] = SKP_RSHIFT_ROUND( rr[ k ], LTP_CORRS_HEAD_ROOM - LZs );\r
-            rr_shifts += ( LTP_CORRS_HEAD_ROOM - LZs );\r
-        }\r
-        corr_rshifts[ k ] = rr_shifts;\r
-        SKP_Silk_corrMatrix_FIX( lag_ptr, subfr_length, LTP_ORDER, LTP_CORRS_HEAD_ROOM, WLTP_ptr, &corr_rshifts[ k ] );  /* WLTP_fix_ptr in Q( -corr_rshifts[ k ] ) */\r
-\r
-        /* The correlation vector always has lower max abs value than rr and/or RR so head room is assured */\r
-        SKP_Silk_corrVector_FIX( lag_ptr, r_ptr, subfr_length, LTP_ORDER, Rr, corr_rshifts[ k ] );  /* Rr_fix_ptr   in Q( -corr_rshifts[ k ] ) */\r
-        if( corr_rshifts[ k ] > rr_shifts ) {\r
-            rr[ k ] = SKP_RSHIFT( rr[ k ], corr_rshifts[ k ] - rr_shifts ); /* rr[ k ] in Q( -corr_rshifts[ k ] ) */\r
-        }\r
-        SKP_assert( rr[ k ] >= 0 );\r
-\r
-        regu = 1;\r
-        regu = SKP_SMLAWB( regu, rr[ k ], SKP_FIX_CONST( LTP_DAMPING/3, 16 ) );\r
-        regu = SKP_SMLAWB( regu, matrix_ptr( WLTP_ptr, 0, 0, LTP_ORDER ), SKP_FIX_CONST( LTP_DAMPING/3, 16 ) );\r
-        regu = SKP_SMLAWB( regu, matrix_ptr( WLTP_ptr, LTP_ORDER-1, LTP_ORDER-1, LTP_ORDER ), SKP_FIX_CONST( LTP_DAMPING/3, 16 ) );\r
-        SKP_Silk_regularize_correlations_FIX( WLTP_ptr, &rr[k], regu, LTP_ORDER );\r
-\r
-        SKP_Silk_solve_LDL_FIX( WLTP_ptr, LTP_ORDER, Rr, b_Q16 ); /* WLTP_fix_ptr and Rr_fix_ptr both in Q(-corr_rshifts[k]) */\r
-\r
-        /* Limit and store in Q14 */\r
-        SKP_Silk_fit_LTP( b_Q16, b_Q14_ptr );\r
-\r
-        /* Calculate residual energy */\r
-        nrg[ k ] = SKP_Silk_residual_energy16_covar_FIX( b_Q14_ptr, WLTP_ptr, Rr, rr[ k ], LTP_ORDER, 14 ); /* nrg_fix in Q( -corr_rshifts[ k ] ) */\r
-\r
-        /* temp = Wght[ k ] / ( nrg[ k ] * Wght[ k ] + 0.01f * subfr_length ); */\r
-        extra_shifts = SKP_min_int( corr_rshifts[ k ], LTP_CORRS_HEAD_ROOM );\r
-        denom32 = SKP_LSHIFT_SAT32( SKP_SMULWB( nrg[ k ], Wght_Q15[ k ] ), 1 + extra_shifts ) + /* Q( -corr_rshifts[ k ] + extra_shifts ) */\r
-            SKP_RSHIFT( SKP_SMULWB( subfr_length, 655 ), corr_rshifts[ k ] - extra_shifts );    /* Q( -corr_rshifts[ k ] + extra_shifts ) */\r
-        denom32 = SKP_max( denom32, 1 );\r
-        SKP_assert( ((SKP_int64)Wght_Q15[ k ] << 16 ) < SKP_int32_MAX );                        /* Wght always < 0.5 in Q0 */\r
-        temp32 = SKP_DIV32( SKP_LSHIFT( ( SKP_int32 )Wght_Q15[ k ], 16 ), denom32 );            /* Q( 15 + 16 + corr_rshifts[k] - extra_shifts ) */\r
-        temp32 = SKP_RSHIFT( temp32, 31 + corr_rshifts[ k ] - extra_shifts - 26 );              /* Q26 */\r
-        \r
-        /* Limit temp such that the below scaling never wraps around */\r
-        WLTP_max = 0;\r
-        for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) {\r
-            WLTP_max = SKP_max( WLTP_ptr[ i ], WLTP_max );\r
-        }\r
-        lshift = SKP_Silk_CLZ32( WLTP_max ) - 1 - 3; /* keep 3 bits free for vq_nearest_neighbor_fix */\r
-        SKP_assert( 26 - 18 + lshift >= 0 );\r
-        if( 26 - 18 + lshift < 31 ) {\r
-            temp32 = SKP_min_32( temp32, SKP_LSHIFT( ( SKP_int32 )1, 26 - 18 + lshift ) );\r
-        }\r
-\r
-        SKP_Silk_scale_vector32_Q26_lshift_18( WLTP_ptr, temp32, LTP_ORDER * LTP_ORDER ); /* WLTP_ptr in Q( 18 - corr_rshifts[ k ] ) */\r
-        \r
-        w[ k ] = matrix_ptr( WLTP_ptr, ( LTP_ORDER >> 1 ), ( LTP_ORDER >> 1 ), LTP_ORDER ); /* w in Q( 18 - corr_rshifts[ k ] ) */\r
-        SKP_assert( w[k] >= 0 );\r
-\r
-        r_ptr     += subfr_length;\r
-        b_Q14_ptr += LTP_ORDER;\r
-        WLTP_ptr  += LTP_ORDER * LTP_ORDER;\r
-    }\r
-\r
-    maxRshifts = 0;\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        maxRshifts = SKP_max_int( corr_rshifts[ k ], maxRshifts );\r
-    }\r
-\r
-    /* Compute LTP coding gain */\r
-    if( LTPredCodGain_Q7 != NULL ) {\r
-        LPC_LTP_res_nrg = 0;\r
-        LPC_res_nrg     = 0;\r
-        SKP_assert( LTP_CORRS_HEAD_ROOM >= 2 ); /* Check that no overflow will happen when adding */\r
-        for( k = 0; k < NB_SUBFR; k++ ) {\r
-            LPC_res_nrg     = SKP_ADD32( LPC_res_nrg,     SKP_RSHIFT( SKP_ADD32( SKP_SMULWB(  rr[ k ], Wght_Q15[ k ] ), 1 ), 1 + ( maxRshifts - corr_rshifts[ k ] ) ) ); /*  Q( -maxRshifts ) */\r
-            LPC_LTP_res_nrg = SKP_ADD32( LPC_LTP_res_nrg, SKP_RSHIFT( SKP_ADD32( SKP_SMULWB( nrg[ k ], Wght_Q15[ k ] ), 1 ), 1 + ( maxRshifts - corr_rshifts[ k ] ) ) ); /*  Q( -maxRshifts ) */\r
-        }\r
-        LPC_LTP_res_nrg = SKP_max( LPC_LTP_res_nrg, 1 ); /* avoid division by zero */\r
-\r
-        div_Q16 = SKP_DIV32_varQ( LPC_res_nrg, LPC_LTP_res_nrg, 16 );\r
-        *LTPredCodGain_Q7 = ( SKP_int )SKP_SMULBB( 3, SKP_Silk_lin2log( div_Q16 ) - ( 16 << 7 ) );\r
-\r
-        SKP_assert( *LTPredCodGain_Q7 == ( SKP_int )SKP_SAT16( SKP_MUL( 3, SKP_Silk_lin2log( div_Q16 ) - ( 16 << 7 ) ) ) );\r
-    }\r
-\r
-    /* smoothing */\r
-    /* d = sum( B, 1 ); */\r
-    b_Q14_ptr = b_Q14;\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        d_Q14[ k ] = 0;\r
-        for( i = 0; i < LTP_ORDER; i++ ) {\r
-            d_Q14[ k ] += b_Q14_ptr[ i ];\r
-        }\r
-        b_Q14_ptr += LTP_ORDER;\r
-    }\r
-\r
-    /* m = ( w * d' ) / ( sum( w ) + 1e-3 ); */\r
-        \r
-    /* Find maximum absolute value of d_Q14 and the bits used by w in Q0 */\r
-    max_abs_d_Q14 = 0;\r
-    max_w_bits    = 0;\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        max_abs_d_Q14 = SKP_max_32( max_abs_d_Q14, SKP_abs( d_Q14[ k ] ) );\r
-        /* w[ k ] is in Q( 18 - corr_rshifts[ k ] ) */\r
-        /* Find bits needed in Q( 18 - maxRshifts ) */\r
-        max_w_bits = SKP_max_32( max_w_bits, 32 - SKP_Silk_CLZ32( w[ k ] ) + corr_rshifts[ k ] - maxRshifts ); \r
-    }\r
-\r
-    /* max_abs_d_Q14 = (5 << 15); worst case, i.e. LTP_ORDER * -SKP_int16_MIN */\r
-    SKP_assert( max_abs_d_Q14 <= ( 5 << 15 ) );\r
-\r
-    /* How many bits is needed for w*d' in Q( 18 - maxRshifts ) in the worst case, of all d_Q14's being equal to max_abs_d_Q14 */\r
-    extra_shifts = max_w_bits + 32 - SKP_Silk_CLZ32( max_abs_d_Q14 ) - 14;\r
-    \r
-    /* Subtract what we got available; bits in output var plus maxRshifts */\r
-    extra_shifts -= ( 32 - 1 - 2 + maxRshifts ); /* Keep sign bit free as well as 2 bits for accumulation */\r
-    extra_shifts = SKP_max_int( extra_shifts, 0 );\r
-\r
-    maxRshifts_wxtra = maxRshifts + extra_shifts;\r
-    \r
-    temp32 = SKP_RSHIFT( 262, maxRshifts + extra_shifts ) + 1; /* 1e-3f in Q( 18 - (maxRshifts + extra_shifts) ) */\r
-    wd = 0;\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        /* w has at least 2 bits of headroom so no overflow should happen */\r
-        temp32 = SKP_ADD32( temp32,                     SKP_RSHIFT( w[ k ], maxRshifts_wxtra - corr_rshifts[ k ] ) );                    /* Q( 18 - maxRshifts_wxtra ) */\r
-        wd     = SKP_ADD32( wd, SKP_LSHIFT( SKP_SMULWW( SKP_RSHIFT( w[ k ], maxRshifts_wxtra - corr_rshifts[ k ] ), d_Q14[ k ] ), 2 ) ); /* Q( 18 - maxRshifts_wxtra ) */\r
-    }\r
-    m_Q12 = SKP_DIV32_varQ( wd, temp32, 12 );\r
-\r
-    b_Q14_ptr = b_Q14;\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        /* w_fix[ k ] from Q( 18 - corr_rshifts[ k ] ) to Q( 16 ) */\r
-        if( 2 - corr_rshifts[k] > 0 ) {\r
-            temp32 = SKP_RSHIFT( w[ k ], 2 - corr_rshifts[ k ] );\r
-        } else {\r
-            temp32 = SKP_LSHIFT_SAT32( w[ k ], corr_rshifts[ k ] - 2 );\r
-        }\r
-\r
-        g_Q26 = SKP_MUL( \r
-            SKP_DIV32( \r
-                SKP_FIX_CONST( LTP_SMOOTHING, 26 ), \r
-                SKP_RSHIFT( SKP_FIX_CONST( LTP_SMOOTHING, 26 ), 10 ) + temp32 ),                                       /* Q10 */ \r
-            SKP_LSHIFT_SAT32( SKP_SUB_SAT32( ( SKP_int32 )m_Q12, SKP_RSHIFT( d_Q14[ k ], 2 ) ), 4 ) );  /* Q16 */\r
-\r
-        temp32 = 0;\r
-        for( i = 0; i < LTP_ORDER; i++ ) {\r
-            delta_b_Q14[ i ] = SKP_max_16( b_Q14_ptr[ i ], 1638 );  /* 1638_Q14 = 0.1_Q0 */\r
-            temp32 += delta_b_Q14[ i ];                          /* Q14 */\r
-        }\r
-        temp32 = SKP_DIV32( g_Q26, temp32 ); /* Q14->Q12 */\r
-        for( i = 0; i < LTP_ORDER; i++ ) {\r
-            b_Q14_ptr[ i ] = SKP_LIMIT_32( ( SKP_int32 )b_Q14_ptr[ i ] + SKP_SMULWB( SKP_LSHIFT_SAT32( temp32, 4 ), delta_b_Q14[ i ] ), -16000, 28000 );\r
-        }\r
-        b_Q14_ptr += LTP_ORDER;\r
-    }\r
-}\r
-\r
-void SKP_Silk_fit_LTP(\r
-    SKP_int32 LTP_coefs_Q16[ LTP_ORDER ],\r
-    SKP_int16 LTP_coefs_Q14[ LTP_ORDER ]\r
-)\r
-{\r
-    SKP_int i;\r
-\r
-    for( i = 0; i < LTP_ORDER; i++ ) {\r
-        LTP_coefs_Q14[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( LTP_coefs_Q16[ i ], 2 ) );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_tuning_parameters.h"
+
+/* Head room for correlations                           */
+#define LTP_CORRS_HEAD_ROOM                             2
+
+void SKP_Silk_fit_LTP(
+    SKP_int32 LTP_coefs_Q16[ LTP_ORDER ],
+    SKP_int16 LTP_coefs_Q14[ LTP_ORDER ]
+);
+
+void SKP_Silk_find_LTP_FIX(
+    SKP_int16           b_Q14[ NB_SUBFR * LTP_ORDER ],              /* O    LTP coefs                                                   */
+    SKP_int32           WLTP[ NB_SUBFR * LTP_ORDER * LTP_ORDER ],   /* O    Weight for LTP quantization                                 */
+    SKP_int             *LTPredCodGain_Q7,                          /* O    LTP coding gain                                             */
+    const SKP_int16     r_first[],                                  /* I    residual signal after LPC signal + state for first 10 ms    */
+    const SKP_int16     r_last[],                                   /* I    residual signal after LPC signal + state for last 10 ms     */
+    const SKP_int       lag[ NB_SUBFR ],                            /* I    LTP lags                                                    */
+    const SKP_int32     Wght_Q15[ NB_SUBFR ],                       /* I    weights                                                     */
+    const SKP_int       subfr_length,                               /* I    subframe length                                             */
+    const SKP_int       mem_offset,                                 /* I    number of samples in LTP memory                             */
+    SKP_int             corr_rshifts[ NB_SUBFR ]                    /* O    right shifts applied to correlations                        */
+)
+{
+    SKP_int   i, k, lshift;
+    const SKP_int16 *r_ptr, *lag_ptr;
+    SKP_int16 *b_Q14_ptr;
+
+    SKP_int32 regu;
+    SKP_int32 *WLTP_ptr;
+    SKP_int32 b_Q16[ LTP_ORDER ], delta_b_Q14[ LTP_ORDER ], d_Q14[ NB_SUBFR ], nrg[ NB_SUBFR ], g_Q26;
+    SKP_int32 w[ NB_SUBFR ], WLTP_max, max_abs_d_Q14, max_w_bits;
+
+    SKP_int32 temp32, denom32;
+    SKP_int   extra_shifts;
+    SKP_int   rr_shifts, maxRshifts, maxRshifts_wxtra, LZs;
+    SKP_int32 LPC_res_nrg, LPC_LTP_res_nrg, div_Q16;
+    SKP_int32 Rr[ LTP_ORDER ], rr[ NB_SUBFR ];
+    SKP_int32 wd, m_Q12;
+    
+    b_Q14_ptr = b_Q14;
+    WLTP_ptr  = WLTP;
+    r_ptr     = &r_first[ mem_offset ];
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        if( k == ( NB_SUBFR >> 1 ) ) { /* shift residual for last 10 ms */
+            r_ptr = &r_last[ mem_offset ];
+        }
+        lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 );
+
+        SKP_Silk_sum_sqr_shift( &rr[ k ], &rr_shifts, r_ptr, subfr_length ); /* rr[ k ] in Q( -rr_shifts ) */
+
+        /* Assure headroom */
+        LZs = SKP_Silk_CLZ32( rr[k] );
+        if( LZs < LTP_CORRS_HEAD_ROOM ) {
+            rr[ k ] = SKP_RSHIFT_ROUND( rr[ k ], LTP_CORRS_HEAD_ROOM - LZs );
+            rr_shifts += ( LTP_CORRS_HEAD_ROOM - LZs );
+        }
+        corr_rshifts[ k ] = rr_shifts;
+        SKP_Silk_corrMatrix_FIX( lag_ptr, subfr_length, LTP_ORDER, LTP_CORRS_HEAD_ROOM, WLTP_ptr, &corr_rshifts[ k ] );  /* WLTP_fix_ptr in Q( -corr_rshifts[ k ] ) */
+
+        /* The correlation vector always has lower max abs value than rr and/or RR so head room is assured */
+        SKP_Silk_corrVector_FIX( lag_ptr, r_ptr, subfr_length, LTP_ORDER, Rr, corr_rshifts[ k ] );  /* Rr_fix_ptr   in Q( -corr_rshifts[ k ] ) */
+        if( corr_rshifts[ k ] > rr_shifts ) {
+            rr[ k ] = SKP_RSHIFT( rr[ k ], corr_rshifts[ k ] - rr_shifts ); /* rr[ k ] in Q( -corr_rshifts[ k ] ) */
+        }
+        SKP_assert( rr[ k ] >= 0 );
+
+        regu = 1;
+        regu = SKP_SMLAWB( regu, rr[ k ], SKP_FIX_CONST( LTP_DAMPING/3, 16 ) );
+        regu = SKP_SMLAWB( regu, matrix_ptr( WLTP_ptr, 0, 0, LTP_ORDER ), SKP_FIX_CONST( LTP_DAMPING/3, 16 ) );
+        regu = SKP_SMLAWB( regu, matrix_ptr( WLTP_ptr, LTP_ORDER-1, LTP_ORDER-1, LTP_ORDER ), SKP_FIX_CONST( LTP_DAMPING/3, 16 ) );
+        SKP_Silk_regularize_correlations_FIX( WLTP_ptr, &rr[k], regu, LTP_ORDER );
+
+        SKP_Silk_solve_LDL_FIX( WLTP_ptr, LTP_ORDER, Rr, b_Q16 ); /* WLTP_fix_ptr and Rr_fix_ptr both in Q(-corr_rshifts[k]) */
+
+        /* Limit and store in Q14 */
+        SKP_Silk_fit_LTP( b_Q16, b_Q14_ptr );
+
+        /* Calculate residual energy */
+        nrg[ k ] = SKP_Silk_residual_energy16_covar_FIX( b_Q14_ptr, WLTP_ptr, Rr, rr[ k ], LTP_ORDER, 14 ); /* nrg_fix in Q( -corr_rshifts[ k ] ) */
+
+        /* temp = Wght[ k ] / ( nrg[ k ] * Wght[ k ] + 0.01f * subfr_length ); */
+        extra_shifts = SKP_min_int( corr_rshifts[ k ], LTP_CORRS_HEAD_ROOM );
+        denom32 = SKP_LSHIFT_SAT32( SKP_SMULWB( nrg[ k ], Wght_Q15[ k ] ), 1 + extra_shifts ) + /* Q( -corr_rshifts[ k ] + extra_shifts ) */
+            SKP_RSHIFT( SKP_SMULWB( subfr_length, 655 ), corr_rshifts[ k ] - extra_shifts );    /* Q( -corr_rshifts[ k ] + extra_shifts ) */
+        denom32 = SKP_max( denom32, 1 );
+        SKP_assert( ((SKP_int64)Wght_Q15[ k ] << 16 ) < SKP_int32_MAX );                        /* Wght always < 0.5 in Q0 */
+        temp32 = SKP_DIV32( SKP_LSHIFT( ( SKP_int32 )Wght_Q15[ k ], 16 ), denom32 );            /* Q( 15 + 16 + corr_rshifts[k] - extra_shifts ) */
+        temp32 = SKP_RSHIFT( temp32, 31 + corr_rshifts[ k ] - extra_shifts - 26 );              /* Q26 */
+        
+        /* Limit temp such that the below scaling never wraps around */
+        WLTP_max = 0;
+        for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) {
+            WLTP_max = SKP_max( WLTP_ptr[ i ], WLTP_max );
+        }
+        lshift = SKP_Silk_CLZ32( WLTP_max ) - 1 - 3; /* keep 3 bits free for vq_nearest_neighbor_fix */
+        SKP_assert( 26 - 18 + lshift >= 0 );
+        if( 26 - 18 + lshift < 31 ) {
+            temp32 = SKP_min_32( temp32, SKP_LSHIFT( ( SKP_int32 )1, 26 - 18 + lshift ) );
+        }
+
+        SKP_Silk_scale_vector32_Q26_lshift_18( WLTP_ptr, temp32, LTP_ORDER * LTP_ORDER ); /* WLTP_ptr in Q( 18 - corr_rshifts[ k ] ) */
+        
+        w[ k ] = matrix_ptr( WLTP_ptr, ( LTP_ORDER >> 1 ), ( LTP_ORDER >> 1 ), LTP_ORDER ); /* w in Q( 18 - corr_rshifts[ k ] ) */
+        SKP_assert( w[k] >= 0 );
+
+        r_ptr     += subfr_length;
+        b_Q14_ptr += LTP_ORDER;
+        WLTP_ptr  += LTP_ORDER * LTP_ORDER;
+    }
+
+    maxRshifts = 0;
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        maxRshifts = SKP_max_int( corr_rshifts[ k ], maxRshifts );
+    }
+
+    /* Compute LTP coding gain */
+    if( LTPredCodGain_Q7 != NULL ) {
+        LPC_LTP_res_nrg = 0;
+        LPC_res_nrg     = 0;
+        SKP_assert( LTP_CORRS_HEAD_ROOM >= 2 ); /* Check that no overflow will happen when adding */
+        for( k = 0; k < NB_SUBFR; k++ ) {
+            LPC_res_nrg     = SKP_ADD32( LPC_res_nrg,     SKP_RSHIFT( SKP_ADD32( SKP_SMULWB(  rr[ k ], Wght_Q15[ k ] ), 1 ), 1 + ( maxRshifts - corr_rshifts[ k ] ) ) ); /*  Q( -maxRshifts ) */
+            LPC_LTP_res_nrg = SKP_ADD32( LPC_LTP_res_nrg, SKP_RSHIFT( SKP_ADD32( SKP_SMULWB( nrg[ k ], Wght_Q15[ k ] ), 1 ), 1 + ( maxRshifts - corr_rshifts[ k ] ) ) ); /*  Q( -maxRshifts ) */
+        }
+        LPC_LTP_res_nrg = SKP_max( LPC_LTP_res_nrg, 1 ); /* avoid division by zero */
+
+        div_Q16 = SKP_DIV32_varQ( LPC_res_nrg, LPC_LTP_res_nrg, 16 );
+        *LTPredCodGain_Q7 = ( SKP_int )SKP_SMULBB( 3, SKP_Silk_lin2log( div_Q16 ) - ( 16 << 7 ) );
+
+        SKP_assert( *LTPredCodGain_Q7 == ( SKP_int )SKP_SAT16( SKP_MUL( 3, SKP_Silk_lin2log( div_Q16 ) - ( 16 << 7 ) ) ) );
+    }
+
+    /* smoothing */
+    /* d = sum( B, 1 ); */
+    b_Q14_ptr = b_Q14;
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        d_Q14[ k ] = 0;
+        for( i = 0; i < LTP_ORDER; i++ ) {
+            d_Q14[ k ] += b_Q14_ptr[ i ];
+        }
+        b_Q14_ptr += LTP_ORDER;
+    }
+
+    /* m = ( w * d' ) / ( sum( w ) + 1e-3 ); */
+        
+    /* Find maximum absolute value of d_Q14 and the bits used by w in Q0 */
+    max_abs_d_Q14 = 0;
+    max_w_bits    = 0;
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        max_abs_d_Q14 = SKP_max_32( max_abs_d_Q14, SKP_abs( d_Q14[ k ] ) );
+        /* w[ k ] is in Q( 18 - corr_rshifts[ k ] ) */
+        /* Find bits needed in Q( 18 - maxRshifts ) */
+        max_w_bits = SKP_max_32( max_w_bits, 32 - SKP_Silk_CLZ32( w[ k ] ) + corr_rshifts[ k ] - maxRshifts ); 
+    }
+
+    /* max_abs_d_Q14 = (5 << 15); worst case, i.e. LTP_ORDER * -SKP_int16_MIN */
+    SKP_assert( max_abs_d_Q14 <= ( 5 << 15 ) );
+
+    /* How many bits is needed for w*d' in Q( 18 - maxRshifts ) in the worst case, of all d_Q14's being equal to max_abs_d_Q14 */
+    extra_shifts = max_w_bits + 32 - SKP_Silk_CLZ32( max_abs_d_Q14 ) - 14;
+    
+    /* Subtract what we got available; bits in output var plus maxRshifts */
+    extra_shifts -= ( 32 - 1 - 2 + maxRshifts ); /* Keep sign bit free as well as 2 bits for accumulation */
+    extra_shifts = SKP_max_int( extra_shifts, 0 );
+
+    maxRshifts_wxtra = maxRshifts + extra_shifts;
+    
+    temp32 = SKP_RSHIFT( 262, maxRshifts + extra_shifts ) + 1; /* 1e-3f in Q( 18 - (maxRshifts + extra_shifts) ) */
+    wd = 0;
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        /* w has at least 2 bits of headroom so no overflow should happen */
+        temp32 = SKP_ADD32( temp32,                     SKP_RSHIFT( w[ k ], maxRshifts_wxtra - corr_rshifts[ k ] ) );                    /* Q( 18 - maxRshifts_wxtra ) */
+        wd     = SKP_ADD32( wd, SKP_LSHIFT( SKP_SMULWW( SKP_RSHIFT( w[ k ], maxRshifts_wxtra - corr_rshifts[ k ] ), d_Q14[ k ] ), 2 ) ); /* Q( 18 - maxRshifts_wxtra ) */
+    }
+    m_Q12 = SKP_DIV32_varQ( wd, temp32, 12 );
+
+    b_Q14_ptr = b_Q14;
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        /* w_fix[ k ] from Q( 18 - corr_rshifts[ k ] ) to Q( 16 ) */
+        if( 2 - corr_rshifts[k] > 0 ) {
+            temp32 = SKP_RSHIFT( w[ k ], 2 - corr_rshifts[ k ] );
+        } else {
+            temp32 = SKP_LSHIFT_SAT32( w[ k ], corr_rshifts[ k ] - 2 );
+        }
+
+        g_Q26 = SKP_MUL( 
+            SKP_DIV32( 
+                SKP_FIX_CONST( LTP_SMOOTHING, 26 ), 
+                SKP_RSHIFT( SKP_FIX_CONST( LTP_SMOOTHING, 26 ), 10 ) + temp32 ),                                       /* Q10 */ 
+            SKP_LSHIFT_SAT32( SKP_SUB_SAT32( ( SKP_int32 )m_Q12, SKP_RSHIFT( d_Q14[ k ], 2 ) ), 4 ) );  /* Q16 */
+
+        temp32 = 0;
+        for( i = 0; i < LTP_ORDER; i++ ) {
+            delta_b_Q14[ i ] = SKP_max_16( b_Q14_ptr[ i ], 1638 );  /* 1638_Q14 = 0.1_Q0 */
+            temp32 += delta_b_Q14[ i ];                          /* Q14 */
+        }
+        temp32 = SKP_DIV32( g_Q26, temp32 ); /* Q14->Q12 */
+        for( i = 0; i < LTP_ORDER; i++ ) {
+            b_Q14_ptr[ i ] = SKP_LIMIT_32( ( SKP_int32 )b_Q14_ptr[ i ] + SKP_SMULWB( SKP_LSHIFT_SAT32( temp32, 4 ), delta_b_Q14[ i ] ), -16000, 28000 );
+        }
+        b_Q14_ptr += LTP_ORDER;
+    }
+}
+
+void SKP_Silk_fit_LTP(
+    SKP_int32 LTP_coefs_Q16[ LTP_ORDER ],
+    SKP_int16 LTP_coefs_Q14[ LTP_ORDER ]
+)
+{
+    SKP_int i;
+
+    for( i = 0; i < LTP_ORDER; i++ ) {
+        LTP_coefs_Q14[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( LTP_coefs_Q16[ i ], 2 ) );
+    }
+}
index c290e9de714079e1164476d8770bb0248bb21bc3..ab9c43bb3076f992fa432b077e95005be781050f 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-#include "SKP_Silk_tuning_parameters.h"\r
-\r
-/* Find pitch lags */\r
-void SKP_Silk_find_pitch_lags_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */\r
-    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  encoder control                             */\r
-    SKP_int16                       res[],          /* O    residual                                    */\r
-    const SKP_int16                 x[]             /* I    Speech signal                               */\r
-)\r
-{\r
-    SKP_Silk_predict_state_FIX *psPredSt = &psEnc->sPred;\r
-    SKP_int   buf_len, i, scale;\r
-    SKP_int32 thrhld_Q15, res_nrg;\r
-    const SKP_int16 *x_buf, *x_buf_ptr;\r
-    SKP_int16 Wsig[      FIND_PITCH_LPC_WIN_MAX ], *Wsig_ptr;\r
-    SKP_int32 auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ];\r
-    SKP_int16 rc_Q15[    MAX_FIND_PITCH_LPC_ORDER ];\r
-    SKP_int32 A_Q24[     MAX_FIND_PITCH_LPC_ORDER ];\r
-    SKP_int32 FiltState[ MAX_FIND_PITCH_LPC_ORDER ];\r
-    SKP_int16 A_Q12[     MAX_FIND_PITCH_LPC_ORDER ];\r
-\r
-    /******************************************/\r
-    /* Setup buffer lengths etc based on Fs   */\r
-    /******************************************/\r
-    buf_len = SKP_ADD_LSHIFT( psEnc->sCmn.la_pitch, psEnc->sCmn.frame_length, 1 );\r
-\r
-    /* Safty check */\r
-    SKP_assert( buf_len >= psPredSt->pitch_LPC_win_length );\r
-\r
-    x_buf = x - psEnc->sCmn.frame_length;\r
-\r
-    /*************************************/\r
-    /* Estimate LPC AR coefficients      */\r
-    /*************************************/\r
-    \r
-    /* Calculate windowed signal */\r
-    \r
-    /* First LA_LTP samples */\r
-    x_buf_ptr = x_buf + buf_len - psPredSt->pitch_LPC_win_length;\r
-    Wsig_ptr  = Wsig;\r
-    SKP_Silk_apply_sine_window_new( Wsig_ptr, x_buf_ptr, 1, psEnc->sCmn.la_pitch );\r
-\r
-    /* Middle un - windowed samples */\r
-    Wsig_ptr  += psEnc->sCmn.la_pitch;\r
-    x_buf_ptr += psEnc->sCmn.la_pitch;\r
-    SKP_memcpy( Wsig_ptr, x_buf_ptr, ( psPredSt->pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 ) ) * sizeof( SKP_int16 ) );\r
-\r
-    /* Last LA_LTP samples */\r
-    Wsig_ptr  += psPredSt->pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 );\r
-    x_buf_ptr += psPredSt->pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 );\r
-    SKP_Silk_apply_sine_window_new( Wsig_ptr, x_buf_ptr, 2, psEnc->sCmn.la_pitch );\r
-\r
-    /* Calculate autocorrelation sequence */\r
-    SKP_Silk_autocorr( auto_corr, &scale, Wsig, psPredSt->pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1 ); \r
-        \r
-    /* Add white noise, as fraction of energy */\r
-    auto_corr[ 0 ] = SKP_SMLAWB( auto_corr[ 0 ], auto_corr[ 0 ], SKP_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) );\r
-\r
-    /* Calculate the reflection coefficients using schur */\r
-    res_nrg = SKP_Silk_schur( rc_Q15, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder );\r
-\r
-    /* Prediction gain */\r
-    psEncCtrl->predGain_Q16 = SKP_DIV32_varQ( auto_corr[ 0 ], SKP_max_int( res_nrg, 1 ), 16 );\r
-\r
-    /* Convert reflection coefficients to prediction coefficients */\r
-    SKP_Silk_k2a( A_Q24, rc_Q15, psEnc->sCmn.pitchEstimationLPCOrder );\r
-    \r
-    /* Convert From 32 bit Q24 to 16 bit Q12 coefs */\r
-    for( i = 0; i < psEnc->sCmn.pitchEstimationLPCOrder; i++ ) {\r
-        A_Q12[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT( A_Q24[ i ], 12 ) );\r
-    }\r
-\r
-    /* Do BWE */\r
-    SKP_Silk_bwexpander( A_Q12, psEnc->sCmn.pitchEstimationLPCOrder, SKP_FIX_CONST( FIND_PITCH_BANDWITH_EXPANSION, 16 ) );\r
-    \r
-    /*****************************************/\r
-    /* LPC analysis filtering                */\r
-    /*****************************************/\r
-    SKP_memset( FiltState, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int32 ) ); /* Not really necessary, but Valgrind will complain otherwise */\r
-    SKP_Silk_MA_Prediction( x_buf, A_Q12, FiltState, res, buf_len, psEnc->sCmn.pitchEstimationLPCOrder );\r
-    SKP_memset( res, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int16 ) );\r
-\r
-    /* Threshold for pitch estimator */\r
-    thrhld_Q15 = SKP_FIX_CONST( 0.45, 15 );\r
-    thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.004, 15 ), psEnc->sCmn.pitchEstimationLPCOrder );\r
-    thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.1,   7  ), psEnc->speech_activity_Q8 );\r
-    thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST(  0.15,  15 ), psEnc->sCmn.prev_sigtype );\r
-    thrhld_Q15 = SKP_SMLAWB( thrhld_Q15, SKP_FIX_CONST( -0.1,   16 ), psEncCtrl->input_tilt_Q15 );\r
-    thrhld_Q15 = SKP_SAT16(  thrhld_Q15 );\r
-\r
-    /*****************************************/\r
-    /* Call pitch estimator                  */\r
-    /*****************************************/\r
-    psEncCtrl->sCmn.sigtype = SKP_Silk_pitch_analysis_core( res, psEncCtrl->sCmn.pitchL, &psEncCtrl->sCmn.lagIndex, \r
-        &psEncCtrl->sCmn.contourIndex, &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16, \r
-        ( SKP_int16 )thrhld_Q15, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, SKP_FALSE );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_tuning_parameters.h"
+
+/* Find pitch lags */
+void SKP_Silk_find_pitch_lags_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  encoder control                             */
+    SKP_int16                       res[],          /* O    residual                                    */
+    const SKP_int16                 x[]             /* I    Speech signal                               */
+)
+{
+    SKP_Silk_predict_state_FIX *psPredSt = &psEnc->sPred;
+    SKP_int   buf_len, i, scale;
+    SKP_int32 thrhld_Q15, res_nrg;
+    const SKP_int16 *x_buf, *x_buf_ptr;
+    SKP_int16 Wsig[      FIND_PITCH_LPC_WIN_MAX ], *Wsig_ptr;
+    SKP_int32 auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ];
+    SKP_int16 rc_Q15[    MAX_FIND_PITCH_LPC_ORDER ];
+    SKP_int32 A_Q24[     MAX_FIND_PITCH_LPC_ORDER ];
+    SKP_int32 FiltState[ MAX_FIND_PITCH_LPC_ORDER ];
+    SKP_int16 A_Q12[     MAX_FIND_PITCH_LPC_ORDER ];
+
+    /******************************************/
+    /* Setup buffer lengths etc based on Fs   */
+    /******************************************/
+    buf_len = SKP_ADD_LSHIFT( psEnc->sCmn.la_pitch, psEnc->sCmn.frame_length, 1 );
+
+    /* Safty check */
+    SKP_assert( buf_len >= psPredSt->pitch_LPC_win_length );
+
+    x_buf = x - psEnc->sCmn.frame_length;
+
+    /*************************************/
+    /* Estimate LPC AR coefficients      */
+    /*************************************/
+    
+    /* Calculate windowed signal */
+    
+    /* First LA_LTP samples */
+    x_buf_ptr = x_buf + buf_len - psPredSt->pitch_LPC_win_length;
+    Wsig_ptr  = Wsig;
+    SKP_Silk_apply_sine_window_new( Wsig_ptr, x_buf_ptr, 1, psEnc->sCmn.la_pitch );
+
+    /* Middle un - windowed samples */
+    Wsig_ptr  += psEnc->sCmn.la_pitch;
+    x_buf_ptr += psEnc->sCmn.la_pitch;
+    SKP_memcpy( Wsig_ptr, x_buf_ptr, ( psPredSt->pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 ) ) * sizeof( SKP_int16 ) );
+
+    /* Last LA_LTP samples */
+    Wsig_ptr  += psPredSt->pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 );
+    x_buf_ptr += psPredSt->pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 );
+    SKP_Silk_apply_sine_window_new( Wsig_ptr, x_buf_ptr, 2, psEnc->sCmn.la_pitch );
+
+    /* Calculate autocorrelation sequence */
+    SKP_Silk_autocorr( auto_corr, &scale, Wsig, psPredSt->pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1 ); 
+        
+    /* Add white noise, as fraction of energy */
+    auto_corr[ 0 ] = SKP_SMLAWB( auto_corr[ 0 ], auto_corr[ 0 ], SKP_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) );
+
+    /* Calculate the reflection coefficients using schur */
+    res_nrg = SKP_Silk_schur( rc_Q15, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder );
+
+    /* Prediction gain */
+    psEncCtrl->predGain_Q16 = SKP_DIV32_varQ( auto_corr[ 0 ], SKP_max_int( res_nrg, 1 ), 16 );
+
+    /* Convert reflection coefficients to prediction coefficients */
+    SKP_Silk_k2a( A_Q24, rc_Q15, psEnc->sCmn.pitchEstimationLPCOrder );
+    
+    /* Convert From 32 bit Q24 to 16 bit Q12 coefs */
+    for( i = 0; i < psEnc->sCmn.pitchEstimationLPCOrder; i++ ) {
+        A_Q12[ i ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT( A_Q24[ i ], 12 ) );
+    }
+
+    /* Do BWE */
+    SKP_Silk_bwexpander( A_Q12, psEnc->sCmn.pitchEstimationLPCOrder, SKP_FIX_CONST( FIND_PITCH_BANDWITH_EXPANSION, 16 ) );
+    
+    /*****************************************/
+    /* LPC analysis filtering                */
+    /*****************************************/
+    SKP_memset( FiltState, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int32 ) ); /* Not really necessary, but Valgrind will complain otherwise */
+    SKP_Silk_MA_Prediction( x_buf, A_Q12, FiltState, res, buf_len, psEnc->sCmn.pitchEstimationLPCOrder );
+    SKP_memset( res, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int16 ) );
+
+    /* Threshold for pitch estimator */
+    thrhld_Q15 = SKP_FIX_CONST( 0.45, 15 );
+    thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.004, 15 ), psEnc->sCmn.pitchEstimationLPCOrder );
+    thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.1,   7  ), psEnc->speech_activity_Q8 );
+    thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST(  0.15,  15 ), psEnc->sCmn.prev_sigtype );
+    thrhld_Q15 = SKP_SMLAWB( thrhld_Q15, SKP_FIX_CONST( -0.1,   16 ), psEncCtrl->input_tilt_Q15 );
+    thrhld_Q15 = SKP_SAT16(  thrhld_Q15 );
+
+    /*****************************************/
+    /* Call pitch estimator                  */
+    /*****************************************/
+    psEncCtrl->sCmn.sigtype = SKP_Silk_pitch_analysis_core( res, psEncCtrl->sCmn.pitchL, &psEncCtrl->sCmn.lagIndex, 
+        &psEncCtrl->sCmn.contourIndex, &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16, 
+        ( SKP_int16 )thrhld_Q15, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, SKP_FALSE );
+}
index cce22c589fd1fa7a02555a48dfac631a571fe08b..73d9842bd42ffaec6cf96fae4572364ccaf05bc2 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-\r
-\r
-void SKP_Silk_find_pred_coefs_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */\r
-    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  encoder control                             */\r
-    const SKP_int16                 res_pitch[]     /* I    Residual from pitch analysis                */\r
-)\r
-{\r
-    SKP_int         i;\r
-    SKP_int32       WLTP[ NB_SUBFR * LTP_ORDER * LTP_ORDER ];\r
-    SKP_int32       invGains_Q16[ NB_SUBFR ], local_gains[ NB_SUBFR ], Wght_Q15[ NB_SUBFR ];\r
-    SKP_int         NLSF_Q15[ MAX_LPC_ORDER ];\r
-    const SKP_int16 *x_ptr;\r
-    SKP_int16       *x_pre_ptr, LPC_in_pre[ NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ];\r
-    SKP_int32       tmp, min_gain_Q16;\r
-    SKP_int         LTP_corrs_rshift[ NB_SUBFR ];\r
-\r
-\r
-    /* weighting for weighted least squares */\r
-    min_gain_Q16 = SKP_int32_MAX >> 6;\r
-    for( i = 0; i < NB_SUBFR; i++ ) {\r
-        min_gain_Q16 = SKP_min( min_gain_Q16, psEncCtrl->Gains_Q16[ i ] );\r
-    }\r
-    for( i = 0; i < NB_SUBFR; i++ ) {\r
-        /* Divide to Q16 */\r
-        SKP_assert( psEncCtrl->Gains_Q16[ i ] > 0 );\r
-        /* Invert and normalize gains, and ensure that maximum invGains_Q16 is within range of a 16 bit int */\r
-        invGains_Q16[ i ] = SKP_DIV32_varQ( min_gain_Q16, psEncCtrl->Gains_Q16[ i ], 16 - 2 );\r
-\r
-        /* Ensure Wght_Q15 a minimum value 1 */\r
-        invGains_Q16[ i ] = SKP_max( invGains_Q16[ i ], 363 ); \r
-        \r
-        /* Square the inverted gains */\r
-        SKP_assert( invGains_Q16[ i ] == SKP_SAT16( invGains_Q16[ i ] ) );\r
-        tmp = SKP_SMULWB( invGains_Q16[ i ], invGains_Q16[ i ] );\r
-        Wght_Q15[ i ] = SKP_RSHIFT( tmp, 1 );\r
-\r
-        /* Invert the inverted and normalized gains */\r
-        local_gains[ i ] = SKP_DIV32( ( 1 << 16 ), invGains_Q16[ i ] );\r
-    }\r
-\r
-    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {\r
-        /**********/\r
-        /* VOICED */\r
-        /**********/\r
-        SKP_assert( psEnc->sCmn.frame_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->sCmn.pitchL[ 0 ] + LTP_ORDER / 2 );\r
-\r
-        /* LTP analysis */\r
-        SKP_Silk_find_LTP_FIX( psEncCtrl->LTPCoef_Q14, WLTP, &psEncCtrl->LTPredCodGain_Q7, res_pitch, \r
-            res_pitch + SKP_RSHIFT( psEnc->sCmn.frame_length, 1 ), psEncCtrl->sCmn.pitchL, Wght_Q15, \r
-            psEnc->sCmn.subfr_length, psEnc->sCmn.frame_length, LTP_corrs_rshift );\r
-\r
-\r
-        /* Quantize LTP gain parameters */\r
-        SKP_Silk_quant_LTP_gains_FIX( psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.LTPIndex, &psEncCtrl->sCmn.PERIndex, \r
-            WLTP, psEnc->mu_LTP_Q8, psEnc->sCmn.LTPQuantLowComplexity );\r
-\r
-        /* Control LTP scaling */\r
-        SKP_Silk_LTP_scale_ctrl_FIX( psEnc, psEncCtrl );\r
-\r
-        /* Create LTP residual */\r
-        SKP_Silk_LTP_analysis_filter_FIX( LPC_in_pre, psEnc->x_buf + psEnc->sCmn.frame_length - psEnc->sCmn.predictLPCOrder, \r
-            psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.pitchL, invGains_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.predictLPCOrder );\r
-\r
-    } else {\r
-        /************/\r
-        /* UNVOICED */\r
-        /************/\r
-        /* Create signal with prepended subframes, scaled by inverse gains */\r
-        x_ptr     = psEnc->x_buf + psEnc->sCmn.frame_length - psEnc->sCmn.predictLPCOrder;\r
-        x_pre_ptr = LPC_in_pre;\r
-        for( i = 0; i < NB_SUBFR; i++ ) {\r
-            SKP_Silk_scale_copy_vector16( x_pre_ptr, x_ptr, invGains_Q16[ i ], \r
-                psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder );\r
-            x_pre_ptr += psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder;\r
-            x_ptr     += psEnc->sCmn.subfr_length;\r
-        }\r
-\r
-        SKP_memset( psEncCtrl->LTPCoef_Q14, 0, NB_SUBFR * LTP_ORDER * sizeof( SKP_int16 ) );\r
-        psEncCtrl->LTPredCodGain_Q7 = 0;\r
-    }\r
-\r
-    /* LPC_in_pre contains the LTP-filtered input for voiced, and the unfiltered input for unvoiced */\r
-    TIC(FIND_LPC)\r
-    SKP_Silk_find_LPC_FIX( NLSF_Q15, &psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sPred.prev_NLSFq_Q15, \r
-        psEnc->sCmn.useInterpolatedNLSFs * ( 1 - psEnc->sCmn.first_frame_after_reset ), psEnc->sCmn.predictLPCOrder, \r
-        LPC_in_pre, psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder );\r
-    TOC(FIND_LPC)\r
-\r
-\r
-    /* Quantize LSFs */\r
-    TIC(PROCESS_LSFS)\r
-        SKP_Silk_process_NLSFs_FIX( psEnc, psEncCtrl, NLSF_Q15 );\r
-    TOC(PROCESS_LSFS)\r
-\r
-    /* Calculate residual energy using quantized LPC coefficients */\r
-    SKP_Silk_residual_energy_FIX( psEncCtrl->ResNrg, psEncCtrl->ResNrgQ, LPC_in_pre, psEncCtrl->PredCoef_Q12, local_gains,\r
-        psEnc->sCmn.subfr_length, psEnc->sCmn.predictLPCOrder );\r
-\r
-    /* Copy to prediction struct for use in next frame for fluctuation reduction */\r
-    SKP_memcpy( psEnc->sPred.prev_NLSFq_Q15, NLSF_Q15, psEnc->sCmn.predictLPCOrder * sizeof( SKP_int ) );\r
-\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+
+void SKP_Silk_find_pred_coefs_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  encoder control                             */
+    const SKP_int16                 res_pitch[]     /* I    Residual from pitch analysis                */
+)
+{
+    SKP_int         i;
+    SKP_int32       WLTP[ NB_SUBFR * LTP_ORDER * LTP_ORDER ];
+    SKP_int32       invGains_Q16[ NB_SUBFR ], local_gains[ NB_SUBFR ], Wght_Q15[ NB_SUBFR ];
+    SKP_int         NLSF_Q15[ MAX_LPC_ORDER ];
+    const SKP_int16 *x_ptr;
+    SKP_int16       *x_pre_ptr, LPC_in_pre[ NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ];
+    SKP_int32       tmp, min_gain_Q16;
+    SKP_int         LTP_corrs_rshift[ NB_SUBFR ];
+
+
+    /* weighting for weighted least squares */
+    min_gain_Q16 = SKP_int32_MAX >> 6;
+    for( i = 0; i < NB_SUBFR; i++ ) {
+        min_gain_Q16 = SKP_min( min_gain_Q16, psEncCtrl->Gains_Q16[ i ] );
+    }
+    for( i = 0; i < NB_SUBFR; i++ ) {
+        /* Divide to Q16 */
+        SKP_assert( psEncCtrl->Gains_Q16[ i ] > 0 );
+        /* Invert and normalize gains, and ensure that maximum invGains_Q16 is within range of a 16 bit int */
+        invGains_Q16[ i ] = SKP_DIV32_varQ( min_gain_Q16, psEncCtrl->Gains_Q16[ i ], 16 - 2 );
+
+        /* Ensure Wght_Q15 a minimum value 1 */
+        invGains_Q16[ i ] = SKP_max( invGains_Q16[ i ], 363 ); 
+        
+        /* Square the inverted gains */
+        SKP_assert( invGains_Q16[ i ] == SKP_SAT16( invGains_Q16[ i ] ) );
+        tmp = SKP_SMULWB( invGains_Q16[ i ], invGains_Q16[ i ] );
+        Wght_Q15[ i ] = SKP_RSHIFT( tmp, 1 );
+
+        /* Invert the inverted and normalized gains */
+        local_gains[ i ] = SKP_DIV32( ( 1 << 16 ), invGains_Q16[ i ] );
+    }
+
+    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
+        /**********/
+        /* VOICED */
+        /**********/
+        SKP_assert( psEnc->sCmn.frame_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->sCmn.pitchL[ 0 ] + LTP_ORDER / 2 );
+
+        /* LTP analysis */
+        SKP_Silk_find_LTP_FIX( psEncCtrl->LTPCoef_Q14, WLTP, &psEncCtrl->LTPredCodGain_Q7, res_pitch, 
+            res_pitch + SKP_RSHIFT( psEnc->sCmn.frame_length, 1 ), psEncCtrl->sCmn.pitchL, Wght_Q15, 
+            psEnc->sCmn.subfr_length, psEnc->sCmn.frame_length, LTP_corrs_rshift );
+
+
+        /* Quantize LTP gain parameters */
+        SKP_Silk_quant_LTP_gains_FIX( psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.LTPIndex, &psEncCtrl->sCmn.PERIndex, 
+            WLTP, psEnc->mu_LTP_Q8, psEnc->sCmn.LTPQuantLowComplexity );
+
+        /* Control LTP scaling */
+        SKP_Silk_LTP_scale_ctrl_FIX( psEnc, psEncCtrl );
+
+        /* Create LTP residual */
+        SKP_Silk_LTP_analysis_filter_FIX( LPC_in_pre, psEnc->x_buf + psEnc->sCmn.frame_length - psEnc->sCmn.predictLPCOrder, 
+            psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.pitchL, invGains_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.predictLPCOrder );
+
+    } else {
+        /************/
+        /* UNVOICED */
+        /************/
+        /* Create signal with prepended subframes, scaled by inverse gains */
+        x_ptr     = psEnc->x_buf + psEnc->sCmn.frame_length - psEnc->sCmn.predictLPCOrder;
+        x_pre_ptr = LPC_in_pre;
+        for( i = 0; i < NB_SUBFR; i++ ) {
+            SKP_Silk_scale_copy_vector16( x_pre_ptr, x_ptr, invGains_Q16[ i ], 
+                psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder );
+            x_pre_ptr += psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder;
+            x_ptr     += psEnc->sCmn.subfr_length;
+        }
+
+        SKP_memset( psEncCtrl->LTPCoef_Q14, 0, NB_SUBFR * LTP_ORDER * sizeof( SKP_int16 ) );
+        psEncCtrl->LTPredCodGain_Q7 = 0;
+    }
+
+    /* LPC_in_pre contains the LTP-filtered input for voiced, and the unfiltered input for unvoiced */
+    TIC(FIND_LPC)
+    SKP_Silk_find_LPC_FIX( NLSF_Q15, &psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sPred.prev_NLSFq_Q15, 
+        psEnc->sCmn.useInterpolatedNLSFs * ( 1 - psEnc->sCmn.first_frame_after_reset ), psEnc->sCmn.predictLPCOrder, 
+        LPC_in_pre, psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder );
+    TOC(FIND_LPC)
+
+
+    /* Quantize LSFs */
+    TIC(PROCESS_LSFS)
+        SKP_Silk_process_NLSFs_FIX( psEnc, psEncCtrl, NLSF_Q15 );
+    TOC(PROCESS_LSFS)
+
+    /* Calculate residual energy using quantized LPC coefficients */
+    SKP_Silk_residual_energy_FIX( psEncCtrl->ResNrg, psEncCtrl->ResNrgQ, LPC_in_pre, psEncCtrl->PredCoef_Q12, local_gains,
+        psEnc->sCmn.subfr_length, psEnc->sCmn.predictLPCOrder );
+
+    /* Copy to prediction struct for use in next frame for fluctuation reduction */
+    SKP_memcpy( psEnc->sPred.prev_NLSFq_Q15, NLSF_Q15, psEnc->sCmn.predictLPCOrder * sizeof( SKP_int ) );
+
+}
+
index 0285c444ae35210cd57707d0cc0d56ec4f3e1e59..170d091619c27012ebf950dd2476d1b5acde8264 100644 (file)
@@ -1,94 +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
-#define OFFSET          ( ( MIN_QGAIN_DB * 128 ) / 6 + 16 * 128 )\r
-#define SCALE_Q16       ( ( 65536 * ( N_LEVELS_QGAIN - 1 ) ) / ( ( ( MAX_QGAIN_DB - MIN_QGAIN_DB ) * 128 ) / 6 ) )\r
-#define INV_SCALE_Q16   ( ( 65536 * ( ( ( MAX_QGAIN_DB - MIN_QGAIN_DB ) * 128 ) / 6 ) ) / ( N_LEVELS_QGAIN - 1 ) )\r
-\r
-/* Gain scalar quantization with hysteresis, uniform on log scale */\r
-void SKP_Silk_gains_quant(\r
-    SKP_int                         ind[ NB_SUBFR ],        /* O    gain indices                            */\r
-    SKP_int32                       gain_Q16[ NB_SUBFR ],   /* I/O  gains (quantized out)                   */\r
-    SKP_int                         *prev_ind,              /* I/O  last index in previous frame            */\r
-    const SKP_int                   conditional             /* I    first gain is delta coded if 1          */\r
-)\r
-{\r
-    SKP_int k;\r
-\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        /* Add half of previous quantization error, convert to log scale, scale, floor() */\r
-        ind[ k ] = SKP_SMULWB( SCALE_Q16, SKP_Silk_lin2log( gain_Q16[ k ] ) - OFFSET );\r
-\r
-        /* Round towards previous quantized gain (hysteresis) */\r
-        if( ind[ k ] < *prev_ind ) {\r
-            ind[ k ]++;\r
-        }\r
-\r
-        /* Compute delta indices and limit */\r
-        if( k == 0 && conditional == 0 ) {\r
-            /* Full index */\r
-            ind[ k ] = SKP_LIMIT_int( ind[ k ], 0, N_LEVELS_QGAIN - 1 );\r
-            ind[ k ] = SKP_max_int( ind[ k ], *prev_ind + MIN_DELTA_GAIN_QUANT );\r
-            *prev_ind = ind[ k ];\r
-        } else {\r
-            /* Delta index */\r
-            ind[ k ] = SKP_LIMIT_int( ind[ k ] - *prev_ind, MIN_DELTA_GAIN_QUANT, MAX_DELTA_GAIN_QUANT );\r
-            /* Accumulate deltas */\r
-            *prev_ind += ind[ k ];\r
-            /* Shift to make non-negative */\r
-            ind[ k ] -= MIN_DELTA_GAIN_QUANT;\r
-        }\r
-\r
-        /* Convert to linear scale and scale */\r
-        gain_Q16[ k ] = SKP_Silk_log2lin( SKP_min_32( SKP_SMULWB( INV_SCALE_Q16, *prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */\r
-    }\r
-}\r
-\r
-/* Gains scalar dequantization, uniform on log scale */\r
-void SKP_Silk_gains_dequant(\r
-    SKP_int32                       gain_Q16[ NB_SUBFR ],   /* O    quantized gains                         */\r
-    const SKP_int                   ind[ NB_SUBFR ],        /* I    gain indices                            */\r
-    SKP_int                         *prev_ind,              /* I/O  last index in previous frame            */\r
-    const SKP_int                   conditional             /* I    first gain is delta coded if 1          */\r
-)\r
-{\r
-    SKP_int   k;\r
-\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        if( k == 0 && conditional == 0 ) {\r
-            *prev_ind = ind[ k ];\r
-        } else {\r
-            /* Delta index */\r
-            *prev_ind += ind[ k ] + MIN_DELTA_GAIN_QUANT;\r
-        }\r
-\r
-        /* Convert to linear scale and scale */\r
-        gain_Q16[ k ] = SKP_Silk_log2lin( SKP_min_32( SKP_SMULWB( INV_SCALE_Q16, *prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+#define OFFSET          ( ( MIN_QGAIN_DB * 128 ) / 6 + 16 * 128 )
+#define SCALE_Q16       ( ( 65536 * ( N_LEVELS_QGAIN - 1 ) ) / ( ( ( MAX_QGAIN_DB - MIN_QGAIN_DB ) * 128 ) / 6 ) )
+#define INV_SCALE_Q16   ( ( 65536 * ( ( ( MAX_QGAIN_DB - MIN_QGAIN_DB ) * 128 ) / 6 ) ) / ( N_LEVELS_QGAIN - 1 ) )
+
+/* Gain scalar quantization with hysteresis, uniform on log scale */
+void SKP_Silk_gains_quant(
+    SKP_int                         ind[ NB_SUBFR ],        /* O    gain indices                            */
+    SKP_int32                       gain_Q16[ NB_SUBFR ],   /* I/O  gains (quantized out)                   */
+    SKP_int                         *prev_ind,              /* I/O  last index in previous frame            */
+    const SKP_int                   conditional             /* I    first gain is delta coded if 1          */
+)
+{
+    SKP_int k;
+
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        /* Add half of previous quantization error, convert to log scale, scale, floor() */
+        ind[ k ] = SKP_SMULWB( SCALE_Q16, SKP_Silk_lin2log( gain_Q16[ k ] ) - OFFSET );
+
+        /* Round towards previous quantized gain (hysteresis) */
+        if( ind[ k ] < *prev_ind ) {
+            ind[ k ]++;
+        }
+
+        /* Compute delta indices and limit */
+        if( k == 0 && conditional == 0 ) {
+            /* Full index */
+            ind[ k ] = SKP_LIMIT_int( ind[ k ], 0, N_LEVELS_QGAIN - 1 );
+            ind[ k ] = SKP_max_int( ind[ k ], *prev_ind + MIN_DELTA_GAIN_QUANT );
+            *prev_ind = ind[ k ];
+        } else {
+            /* Delta index */
+            ind[ k ] = SKP_LIMIT_int( ind[ k ] - *prev_ind, MIN_DELTA_GAIN_QUANT, MAX_DELTA_GAIN_QUANT );
+            /* Accumulate deltas */
+            *prev_ind += ind[ k ];
+            /* Shift to make non-negative */
+            ind[ k ] -= MIN_DELTA_GAIN_QUANT;
+        }
+
+        /* Convert to linear scale and scale */
+        gain_Q16[ k ] = SKP_Silk_log2lin( SKP_min_32( SKP_SMULWB( INV_SCALE_Q16, *prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */
+    }
+}
+
+/* Gains scalar dequantization, uniform on log scale */
+void SKP_Silk_gains_dequant(
+    SKP_int32                       gain_Q16[ NB_SUBFR ],   /* O    quantized gains                         */
+    const SKP_int                   ind[ NB_SUBFR ],        /* I    gain indices                            */
+    SKP_int                         *prev_ind,              /* I/O  last index in previous frame            */
+    const SKP_int                   conditional             /* I    first gain is delta coded if 1          */
+)
+{
+    SKP_int   k;
+
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        if( k == 0 && conditional == 0 ) {
+            *prev_ind = ind[ k ];
+        } else {
+            /* Delta index */
+            *prev_ind += ind[ k ] + MIN_DELTA_GAIN_QUANT;
+        }
+
+        /* Convert to linear scale and scale */
+        gain_Q16[ k ] = SKP_Silk_log2lin( SKP_min_32( SKP_SMULWB( INV_SCALE_Q16, *prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */
+    }
+}
index 9a3617063b6cb1db5cabad0557e46a61328e93a1..67959e46aebadda656e4eb0877b865e8f67d6e9b 100644 (file)
@@ -1,56 +1,56 @@
-/***********************************************************************\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_FIX.h"\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 FIX encoder state       */\r
-) {\r
-    SKP_int ret = 0;\r
-    /* Clear the entire encoder state */\r
-    SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FIX ) );\r
-\r
-#if HIGH_PASS_INPUT\r
-    psEnc->variable_HP_smth1_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */\r
-    psEnc->variable_HP_smth2_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */\r
-#endif\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
-    /* Initialize NSQ */\r
-    psEnc->sNSQ.prev_inv_gain_Q16      = 65536;\r
-    psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536;\r
-\r
-    return( ret );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+/*********************************/
+/* Initialize Silk Encoder state */
+/*********************************/
+SKP_int SKP_Silk_init_encoder_FIX(
+    SKP_Silk_encoder_state_FIX  *psEnc                  /* I/O  Pointer to Silk FIX encoder state       */
+) {
+    SKP_int ret = 0;
+    /* Clear the entire encoder state */
+    SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FIX ) );
+
+#if HIGH_PASS_INPUT
+    psEnc->variable_HP_smth1_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */
+    psEnc->variable_HP_smth2_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */
+#endif
+
+    /* Used to deactivate e.g. LSF interpolation and fluctuation reduction */
+    psEnc->sCmn.first_frame_after_reset = 1;
+
+    /* Initialize Silk VAD */
+    ret += SKP_Silk_VAD_Init( &psEnc->sCmn.sVAD );
+
+    /* Initialize NSQ */
+    psEnc->sNSQ.prev_inv_gain_Q16      = 65536;
+    psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536;
+
+    return( ret );
+}
index 940160183a51dde9dd440a9051aba263e6ad1541..7535630d92495d2289a6369c88e01b16ac25c4c4 100644 (file)
@@ -1,69 +1,69 @@
-/***********************************************************************\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_inner_prod_aligned.c                                                *\r
- *                                                                                *\r
- *                                                                                *\r
- * Copyright 2008-2010 (c), Skype Limited                                              *\r
- * Date: 080601                                                                   *\r
- *                                                                                */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* sum= for(i=0;i<len;i++)inVec1[i]*inVec2[i];      ---        inner product    */\r
-/* Note for ARM asm:                                                            */\r
-/*        * inVec1 and inVec2 should be at least 2 byte aligned.    (Or defined as short/int16) */\r
-/*        * len should be positive 16bit integer.                               */\r
-/*        * 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
-)\r
-{\r
-    SKP_int   i; \r
-    SKP_int32 sum = 0;\r
-    for( i = 0; i < len; i++ ) {\r
-        sum = SKP_SMLABB( sum, inVec1[ i ], inVec2[ i ] );\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
-)\r
-{\r
-    SKP_int   i; \r
-    SKP_int64 sum = 0;\r
-    for( i = 0; i < len; i++ ) {\r
-        sum = SKP_SMLALBB( sum, inVec1[ i ], inVec2[ i ] );\r
-    }\r
-    return sum;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                                *
+ * SKP_Silk_inner_prod_aligned.c                                                *
+ *                                                                                *
+ *                                                                                *
+ * Copyright 2008-2010 (c), Skype Limited                                              *
+ * Date: 080601                                                                   *
+ *                                                                                */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* sum= for(i=0;i<len;i++)inVec1[i]*inVec2[i];      ---        inner product    */
+/* Note for ARM asm:                                                            */
+/*        * inVec1 and inVec2 should be at least 2 byte aligned.    (Or defined as short/int16) */
+/*        * len should be positive 16bit integer.                               */
+/*        * only when len>6, memory access can be reduced by half.              */
+
+SKP_int32 SKP_Silk_inner_prod_aligned(
+    const SKP_int16* const inVec1,  /*    I input vector 1    */
+    const SKP_int16* const inVec2,  /*    I input vector 2    */
+    const SKP_int             len   /*    I vector lengths    */
+)
+{
+    SKP_int   i; 
+    SKP_int32 sum = 0;
+    for( i = 0; i < len; i++ ) {
+        sum = SKP_SMLABB( sum, inVec1[ i ], inVec2[ i ] );
+    }
+    return sum;
+}
+
+SKP_int64 SKP_Silk_inner_prod16_aligned_64(
+    const SKP_int16 *inVec1,        /*    I input vector 1    */ 
+    const SKP_int16 *inVec2,        /*    I input vector 2    */
+    const SKP_int   len             /*    I vector lengths    */
+)
+{
+    SKP_int   i; 
+    SKP_int64 sum = 0;
+    for( i = 0; i < len; i++ ) {
+        sum = SKP_SMLALBB( sum, inVec1[ i ], inVec2[ i ] );
+    }
+    return sum;
+}
index f3adcbedab7516990b8860ffc4de9a57db7aa954..e3d5cacda334687d12ffdd8d146f9d9912047f58 100644 (file)
@@ -1,47 +1,47 @@
-/***********************************************************************\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
-/* Interpolate two vectors */\r
-void SKP_Silk_interpolate(\r
-    SKP_int                         xi[ MAX_LPC_ORDER ],    /* O    interpolated vector                     */\r
-    const SKP_int                   x0[ MAX_LPC_ORDER ],    /* I    first vector                            */\r
-    const SKP_int                   x1[ MAX_LPC_ORDER ],    /* I    second vector                           */\r
-    const SKP_int                   ifact_Q2,               /* I    interp. factor, weight on 2nd vector    */\r
-    const SKP_int                   d                       /* I    number of parameters                    */\r
-)\r
-{\r
-    SKP_int i;\r
-\r
-    SKP_assert( ifact_Q2 >= 0 );\r
-    SKP_assert( ifact_Q2 <= ( 1 << 2 ) );\r
-\r
-    for( i = 0; i < d; i++ ) {\r
-        xi[ i ] = ( SKP_int )( ( SKP_int32 )x0[ i ] + SKP_RSHIFT( SKP_MUL( ( SKP_int32 )x1[ i ] - ( SKP_int32 )x0[ i ], ifact_Q2 ), 2 ) );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Interpolate two vectors */
+void SKP_Silk_interpolate(
+    SKP_int                         xi[ MAX_LPC_ORDER ],    /* O    interpolated vector                     */
+    const SKP_int                   x0[ MAX_LPC_ORDER ],    /* I    first vector                            */
+    const SKP_int                   x1[ MAX_LPC_ORDER ],    /* I    second vector                           */
+    const SKP_int                   ifact_Q2,               /* I    interp. factor, weight on 2nd vector    */
+    const SKP_int                   d                       /* I    number of parameters                    */
+)
+{
+    SKP_int i;
+
+    SKP_assert( ifact_Q2 >= 0 );
+    SKP_assert( ifact_Q2 <= ( 1 << 2 ) );
+
+    for( i = 0; i < d; i++ ) {
+        xi[ i ] = ( SKP_int )( ( SKP_int32 )x0[ i ] + SKP_RSHIFT( SKP_MUL( ( SKP_int32 )x1[ i ] - ( SKP_int32 )x0[ i ], ifact_Q2 ), 2 ) );
+    }
+}
index 0cb5482a6d30c77559034976b25a6de71ae458e6..972c464df16f0e0122ba001d9cf366c564a0dadc 100644 (file)
@@ -1,58 +1,58 @@
-/***********************************************************************\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_k2a.c                                                     *\r
- *                                                                      *\r
- * Step up function, converts reflection coefficients to prediction     *\r
- * coefficients                                                         *\r
- *                                                                      *\r
- * Copyright 2008 (c), Skype Limited                                    *\r
- * Date: 080103                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Step up function, converts reflection coefficients to prediction coefficients */\r
-void SKP_Silk_k2a(\r
-    SKP_int32            *A_Q24,                 /* O:    Prediction coefficients [order] Q24         */\r
-    const SKP_int16      *rc_Q15,                /* I:    Reflection coefficients [order] Q15         */\r
-    const SKP_int32      order                   /* I:    Prediction order                            */\r
-)\r
-{\r
-    SKP_int   k, n;\r
-    SKP_int32 Atmp[ SKP_Silk_MAX_ORDER_LPC ];\r
-\r
-    for( k = 0; k < order; k++ ) {\r
-        for( n = 0; n < k; n++ ) {\r
-            Atmp[ n ] = A_Q24[ n ];\r
-        }\r
-        for( n = 0; n < k; n++ ) {\r
-            A_Q24[ n ] = SKP_SMLAWB( A_Q24[ n ], SKP_LSHIFT( Atmp[ k - n - 1 ], 1 ), rc_Q15[ k ] );\r
-        }\r
-        A_Q24[ k ] = -SKP_LSHIFT( (SKP_int32)rc_Q15[ k ], 9 );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_k2a.c                                                     *
+ *                                                                      *
+ * Step up function, converts reflection coefficients to prediction     *
+ * coefficients                                                         *
+ *                                                                      *
+ * Copyright 2008 (c), Skype Limited                                    *
+ * Date: 080103                                                         *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Step up function, converts reflection coefficients to prediction coefficients */
+void SKP_Silk_k2a(
+    SKP_int32            *A_Q24,                 /* O:    Prediction coefficients [order] Q24         */
+    const SKP_int16      *rc_Q15,                /* I:    Reflection coefficients [order] Q15         */
+    const SKP_int32      order                   /* I:    Prediction order                            */
+)
+{
+    SKP_int   k, n;
+    SKP_int32 Atmp[ SKP_Silk_MAX_ORDER_LPC ];
+
+    for( k = 0; k < order; k++ ) {
+        for( n = 0; n < k; n++ ) {
+            Atmp[ n ] = A_Q24[ n ];
+        }
+        for( n = 0; n < k; n++ ) {
+            A_Q24[ n ] = SKP_SMLAWB( A_Q24[ n ], SKP_LSHIFT( Atmp[ k - n - 1 ], 1 ), rc_Q15[ k ] );
+        }
+        A_Q24[ k ] = -SKP_LSHIFT( (SKP_int32)rc_Q15[ k ], 9 );
+    }
+}
index c59719de6450e7573314e8e3fc00ef6b77468c99..2671a1a3c0904adfd91fb5ccf53752cb821b2ee7 100644 (file)
@@ -1,58 +1,58 @@
-/***********************************************************************\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_k2a.c                                                     *\r
- *                                                                      *\r
- * Step up function, converts reflection coefficients to prediction     *\r
- * coefficients                                                         *\r
- *                                                                      *\r
- * Copyright 2008 (c), Skype Limited                                    *\r
- * Date: 080103                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Step up function, converts reflection coefficients to prediction coefficients */\r
-void SKP_Silk_k2a_Q16(\r
-    SKP_int32            *A_Q24,                 /* O:    Prediction coefficients [order] Q24         */\r
-    const SKP_int32      *rc_Q16,                /* I:    Reflection coefficients [order] Q16         */\r
-    const SKP_int32      order                   /* I:    Prediction order                            */\r
-)\r
-{\r
-    SKP_int   k, n;\r
-    SKP_int32 Atmp[ SKP_Silk_MAX_ORDER_LPC ];\r
-\r
-    for( k = 0; k < order; k++ ) {\r
-        for( n = 0; n < k; n++ ) {\r
-            Atmp[ n ] = A_Q24[ n ];\r
-        }\r
-        for( n = 0; n < k; n++ ) {\r
-            A_Q24[ n ] = SKP_SMLAWW( A_Q24[ n ], Atmp[ k - n - 1 ], rc_Q16[ k ] );\r
-        }\r
-        A_Q24[ k ] = -SKP_LSHIFT( rc_Q16[ k ], 8 );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_k2a.c                                                     *
+ *                                                                      *
+ * Step up function, converts reflection coefficients to prediction     *
+ * coefficients                                                         *
+ *                                                                      *
+ * Copyright 2008 (c), Skype Limited                                    *
+ * Date: 080103                                                         *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Step up function, converts reflection coefficients to prediction coefficients */
+void SKP_Silk_k2a_Q16(
+    SKP_int32            *A_Q24,                 /* O:    Prediction coefficients [order] Q24         */
+    const SKP_int32      *rc_Q16,                /* I:    Reflection coefficients [order] Q16         */
+    const SKP_int32      order                   /* I:    Prediction order                            */
+)
+{
+    SKP_int   k, n;
+    SKP_int32 Atmp[ SKP_Silk_MAX_ORDER_LPC ];
+
+    for( k = 0; k < order; k++ ) {
+        for( n = 0; n < k; n++ ) {
+            Atmp[ n ] = A_Q24[ n ];
+        }
+        for( n = 0; n < k; n++ ) {
+            A_Q24[ n ] = SKP_SMLAWW( A_Q24[ n ], Atmp[ k - n - 1 ], rc_Q16[ k ] );
+        }
+        A_Q24[ k ] = -SKP_LSHIFT( rc_Q16[ k ], 8 );
+    }
+}
index 31cb05bffc525869ad62e71dd7d07bb0964bd4bc..db3f08aa1639c9b33b8a345b24be69b0faec7ead 100644 (file)
@@ -1,49 +1,49 @@
-/***********************************************************************\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_lin2log.c                                                 *\r
- *                                                                      *\r
- * Convert input to a log scale                                         *\r
- * Approximation of 128 * log2()                                        *\r
- *                                                                      *\r
- * Copyright 2006 (c), Skype Limited                                    *\r
- * Date: 060221                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-/* Approximation of 128 * log2() (very close inverse of approx 2^() below) */\r
-/* Convert input to a log scale    */ \r
-SKP_int32 SKP_Silk_lin2log( const SKP_int32 inLin )    /* I:    Input in linear scale */\r
-{\r
-    SKP_int32 lz, frac_Q7;\r
-\r
-    SKP_Silk_CLZ_FRAC( inLin, &lz, &frac_Q7 );\r
-\r
-    /* Piece-wise parabolic approximation */\r
-    return( SKP_LSHIFT( 31 - lz, 7 ) + SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), 179 ) );\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_lin2log.c                                                 *
+ *                                                                      *
+ * Convert input to a log scale                                         *
+ * Approximation of 128 * log2()                                        *
+ *                                                                      *
+ * Copyright 2006 (c), Skype Limited                                    *
+ * Date: 060221                                                         *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+/* Approximation of 128 * log2() (very close inverse of approx 2^() below) */
+/* Convert input to a log scale    */ 
+SKP_int32 SKP_Silk_lin2log( const SKP_int32 inLin )    /* I:    Input in linear scale */
+{
+    SKP_int32 lz, frac_Q7;
+
+    SKP_Silk_CLZ_FRAC( inLin, &lz, &frac_Q7 );
+
+    /* Piece-wise parabolic approximation */
+    return( SKP_LSHIFT( 31 - lz, 7 ) + SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), 179 ) );
+}
+
index 258627cf328952a55ea3fabac05f6b09c36a058a..33db15b5213a17d623f84fb83511df31f34afc0f 100644 (file)
@@ -1,58 +1,58 @@
-/***********************************************************************\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_log2lin.c                                                 *\r
- *                                                                      *\r
- * Convert input to a linear scale                                      *\r
- *                                                                      *\r
- * Copyright 2006 (c), Skype Limited                                    *\r
- * Date: 060221                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Approximation of 2^() (very close inverse of SKP_Silk_lin2log()) */\r
-/* Convert input to a linear scale    */ \r
-SKP_int32 SKP_Silk_log2lin( const SKP_int32 inLog_Q7 )    /* I:    Input on log scale */ \r
-{\r
-    SKP_int32 out, frac_Q7;\r
-\r
-    if( inLog_Q7 < 0 ) {\r
-        return 0;\r
-    }\r
-\r
-    out = SKP_LSHIFT( 1, SKP_RSHIFT( inLog_Q7, 7 ) );\r
-    frac_Q7 = inLog_Q7 & 0x7F;\r
-    if( inLog_Q7 < 2048 ) {\r
-        /* Piece-wise parabolic approximation */\r
-        out = SKP_ADD_RSHIFT( out, SKP_MUL( out, SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), -174 ) ), 7 );\r
-    } else {\r
-        /* Piece-wise parabolic approximation */\r
-        out = SKP_MLA( out, SKP_RSHIFT( out, 7 ), SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), -174 ) );\r
-    }\r
-    return out;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_log2lin.c                                                 *
+ *                                                                      *
+ * Convert input to a linear scale                                      *
+ *                                                                      *
+ * Copyright 2006 (c), Skype Limited                                    *
+ * Date: 060221                                                         *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Approximation of 2^() (very close inverse of SKP_Silk_lin2log()) */
+/* Convert input to a linear scale    */ 
+SKP_int32 SKP_Silk_log2lin( const SKP_int32 inLog_Q7 )    /* I:    Input on log scale */ 
+{
+    SKP_int32 out, frac_Q7;
+
+    if( inLog_Q7 < 0 ) {
+        return 0;
+    }
+
+    out = SKP_LSHIFT( 1, SKP_RSHIFT( inLog_Q7, 7 ) );
+    frac_Q7 = inLog_Q7 & 0x7F;
+    if( inLog_Q7 < 2048 ) {
+        /* Piece-wise parabolic approximation */
+        out = SKP_ADD_RSHIFT( out, SKP_MUL( out, SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), -174 ) ), 7 );
+    } else {
+        /* Piece-wise parabolic approximation */
+        out = SKP_MLA( out, SKP_RSHIFT( out, 7 ), SKP_SMLAWB( frac_Q7, SKP_MUL( frac_Q7, 128 - frac_Q7 ), -174 ) );
+    }
+    return out;
+}
index 53b0a17fc72a68c425cfa63990e043f0a2454ebb..b2d5e94d6e1a0724a25e083f210d0842e5d82ce0 100644 (file)
-/***********************************************************************\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
-#ifndef _SKP_SILK_API_C_H_\r
-#define _SKP_SILK_API_C_H_\r
-\r
-// This is an inline header file for general platform.\r
-\r
-// (a32 * (SKP_int32)((SKP_int16)(b32))) >> 16 output have to be 32bit int\r
-#define SKP_SMULWB(a32, b32)            ((((a32) >> 16) * (SKP_int32)((SKP_int16)(b32))) + ((((a32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(b32))) >> 16))\r
-\r
-// a32 + (b32 * (SKP_int32)((SKP_int16)(c32))) >> 16 output have to be 32bit int\r
-#define SKP_SMLAWB(a32, b32, c32)       ((a32) + ((((b32) >> 16) * (SKP_int32)((SKP_int16)(c32))) + ((((b32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(c32))) >> 16)))\r
-\r
-// (a32 * (b32 >> 16)) >> 16\r
-#define SKP_SMULWT(a32, b32)            (((a32) >> 16) * ((b32) >> 16) + ((((a32) & 0x0000FFFF) * ((b32) >> 16)) >> 16))\r
-\r
-// a32 + (b32 * (c32 >> 16)) >> 16\r
-#define SKP_SMLAWT(a32, b32, c32)       ((a32) + (((b32) >> 16) * ((c32) >> 16)) + ((((b32) & 0x0000FFFF) * ((c32) >> 16)) >> 16))\r
-\r
-// (SKP_int32)((SKP_int16)(a3))) * (SKP_int32)((SKP_int16)(b32)) output have to be 32bit int\r
-#define SKP_SMULBB(a32, b32)            ((SKP_int32)((SKP_int16)(a32)) * (SKP_int32)((SKP_int16)(b32)))\r
-\r
-// a32 + (SKP_int32)((SKP_int16)(b32)) * (SKP_int32)((SKP_int16)(c32)) output have to be 32bit int\r
-#define SKP_SMLABB(a32, b32, c32)       ((a32) + ((SKP_int32)((SKP_int16)(b32))) * (SKP_int32)((SKP_int16)(c32)))\r
-\r
-// (SKP_int32)((SKP_int16)(a32)) * (b32 >> 16)\r
-#define SKP_SMULBT(a32, b32)            ((SKP_int32)((SKP_int16)(a32)) * ((b32) >> 16))\r
-\r
-// a32 + (SKP_int32)((SKP_int16)(b32)) * (c32 >> 16)\r
-#define SKP_SMLABT(a32, b32, c32)       ((a32) + ((SKP_int32)((SKP_int16)(b32))) * ((c32) >> 16))\r
-\r
-// a64 + (b32 * c32)\r
-#define SKP_SMLAL(a64, b32, c32)        (SKP_ADD64((a64), ((SKP_int64)(b32) * (SKP_int64)(c32))))\r
-\r
-// (a32 * b32) >> 16\r
-#define SKP_SMULWW(a32, b32)            SKP_MLA(SKP_SMULWB((a32), (b32)), (a32), SKP_RSHIFT_ROUND((b32), 16))\r
-\r
-// a32 + ((b32 * c32) >> 16)\r
-#define SKP_SMLAWW(a32, b32, c32)       SKP_MLA(SKP_SMLAWB((a32), (b32), (c32)), (b32), SKP_RSHIFT_ROUND((c32), 16))\r
-\r
-/* add/subtract with output saturated */\r
-#define SKP_ADD_SAT32(a, b)             ((((a) + (b)) & 0x80000000) == 0 ?                              \\r
-                                        ((((a) & (b)) & 0x80000000) != 0 ? SKP_int32_MIN : (a)+(b)) :   \\r
-                                        ((((a) | (b)) & 0x80000000) == 0 ? SKP_int32_MAX : (a)+(b)) )\r
-\r
-#define SKP_SUB_SAT32(a, b)             ((((a)-(b)) & 0x80000000) == 0 ?                                        \\r
-                                        (( (a) & ((b)^0x80000000) & 0x80000000) ? SKP_int32_MIN : (a)-(b)) :    \\r
-                                        ((((a)^0x80000000) & (b)  & 0x80000000) ? SKP_int32_MAX : (a)-(b)) )\r
-    \r
-SKP_INLINE SKP_int32 SKP_Silk_CLZ16(SKP_int16 in16)\r
-{\r
-    SKP_int32 out32 = 0;\r
-    if( in16 == 0 ) {\r
-        return 16;\r
-    }\r
-    /* test nibbles */\r
-    if( in16 & 0xFF00 ) {\r
-        if( in16 & 0xF000 ) {\r
-            in16 >>= 12;\r
-        } else {\r
-            out32 += 4;\r
-            in16 >>= 8;\r
-        }\r
-    } else {\r
-        if( in16 & 0xFFF0 ) {\r
-            out32 += 8;\r
-            in16 >>= 4;\r
-        } else {\r
-            out32 += 12;\r
-        }\r
-    }\r
-    /* test bits and return */\r
-    if( in16 & 0xC ) {\r
-        if( in16 & 0x8 )\r
-            return out32 + 0;\r
-        else\r
-            return out32 + 1;\r
-    } else {\r
-        if( in16 & 0xE )\r
-            return out32 + 2;\r
-        else\r
-            return out32 + 3;\r
-    }\r
-}\r
-\r
-SKP_INLINE SKP_int32 SKP_Silk_CLZ32(SKP_int32 in32)\r
-{\r
-    /* test highest 16 bits and convert to SKP_int16 */\r
-    if( in32 & 0xFFFF0000 ) {\r
-        return SKP_Silk_CLZ16((SKP_int16)(in32 >> 16));\r
-    } else {\r
-        return SKP_Silk_CLZ16((SKP_int16)in32) + 16;\r
-    }\r
-}\r
-\r
-#endif //_SKP_SILK_API_C_H_\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef _SKP_SILK_API_C_H_
+#define _SKP_SILK_API_C_H_
+
+// This is an inline header file for general platform.
+
+// (a32 * (SKP_int32)((SKP_int16)(b32))) >> 16 output have to be 32bit int
+#define SKP_SMULWB(a32, b32)            ((((a32) >> 16) * (SKP_int32)((SKP_int16)(b32))) + ((((a32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(b32))) >> 16))
+
+// a32 + (b32 * (SKP_int32)((SKP_int16)(c32))) >> 16 output have to be 32bit int
+#define SKP_SMLAWB(a32, b32, c32)       ((a32) + ((((b32) >> 16) * (SKP_int32)((SKP_int16)(c32))) + ((((b32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(c32))) >> 16)))
+
+// (a32 * (b32 >> 16)) >> 16
+#define SKP_SMULWT(a32, b32)            (((a32) >> 16) * ((b32) >> 16) + ((((a32) & 0x0000FFFF) * ((b32) >> 16)) >> 16))
+
+// a32 + (b32 * (c32 >> 16)) >> 16
+#define SKP_SMLAWT(a32, b32, c32)       ((a32) + (((b32) >> 16) * ((c32) >> 16)) + ((((b32) & 0x0000FFFF) * ((c32) >> 16)) >> 16))
+
+// (SKP_int32)((SKP_int16)(a3))) * (SKP_int32)((SKP_int16)(b32)) output have to be 32bit int
+#define SKP_SMULBB(a32, b32)            ((SKP_int32)((SKP_int16)(a32)) * (SKP_int32)((SKP_int16)(b32)))
+
+// a32 + (SKP_int32)((SKP_int16)(b32)) * (SKP_int32)((SKP_int16)(c32)) output have to be 32bit int
+#define SKP_SMLABB(a32, b32, c32)       ((a32) + ((SKP_int32)((SKP_int16)(b32))) * (SKP_int32)((SKP_int16)(c32)))
+
+// (SKP_int32)((SKP_int16)(a32)) * (b32 >> 16)
+#define SKP_SMULBT(a32, b32)            ((SKP_int32)((SKP_int16)(a32)) * ((b32) >> 16))
+
+// a32 + (SKP_int32)((SKP_int16)(b32)) * (c32 >> 16)
+#define SKP_SMLABT(a32, b32, c32)       ((a32) + ((SKP_int32)((SKP_int16)(b32))) * ((c32) >> 16))
+
+// a64 + (b32 * c32)
+#define SKP_SMLAL(a64, b32, c32)        (SKP_ADD64((a64), ((SKP_int64)(b32) * (SKP_int64)(c32))))
+
+// (a32 * b32) >> 16
+#define SKP_SMULWW(a32, b32)            SKP_MLA(SKP_SMULWB((a32), (b32)), (a32), SKP_RSHIFT_ROUND((b32), 16))
+
+// a32 + ((b32 * c32) >> 16)
+#define SKP_SMLAWW(a32, b32, c32)       SKP_MLA(SKP_SMLAWB((a32), (b32), (c32)), (b32), SKP_RSHIFT_ROUND((c32), 16))
+
+/* add/subtract with output saturated */
+#define SKP_ADD_SAT32(a, b)             ((((a) + (b)) & 0x80000000) == 0 ?                              \
+                                        ((((a) & (b)) & 0x80000000) != 0 ? SKP_int32_MIN : (a)+(b)) :   \
+                                        ((((a) | (b)) & 0x80000000) == 0 ? SKP_int32_MAX : (a)+(b)) )
+
+#define SKP_SUB_SAT32(a, b)             ((((a)-(b)) & 0x80000000) == 0 ?                                        \
+                                        (( (a) & ((b)^0x80000000) & 0x80000000) ? SKP_int32_MIN : (a)-(b)) :    \
+                                        ((((a)^0x80000000) & (b)  & 0x80000000) ? SKP_int32_MAX : (a)-(b)) )
+    
+SKP_INLINE SKP_int32 SKP_Silk_CLZ16(SKP_int16 in16)
+{
+    SKP_int32 out32 = 0;
+    if( in16 == 0 ) {
+        return 16;
+    }
+    /* test nibbles */
+    if( in16 & 0xFF00 ) {
+        if( in16 & 0xF000 ) {
+            in16 >>= 12;
+        } else {
+            out32 += 4;
+            in16 >>= 8;
+        }
+    } else {
+        if( in16 & 0xFFF0 ) {
+            out32 += 8;
+            in16 >>= 4;
+        } else {
+            out32 += 12;
+        }
+    }
+    /* test bits and return */
+    if( in16 & 0xC ) {
+        if( in16 & 0x8 )
+            return out32 + 0;
+        else
+            return out32 + 1;
+    } else {
+        if( in16 & 0xE )
+            return out32 + 2;
+        else
+            return out32 + 3;
+    }
+}
+
+SKP_INLINE SKP_int32 SKP_Silk_CLZ32(SKP_int32 in32)
+{
+    /* test highest 16 bits and convert to SKP_int16 */
+    if( in32 & 0xFFFF0000 ) {
+        return SKP_Silk_CLZ16((SKP_int16)(in32 >> 16));
+    } else {
+        return SKP_Silk_CLZ16((SKP_int16)in32) + 16;
+    }
+}
+
+#endif //_SKP_SILK_API_C_H_
+
index 55b7057a009625a0933a431cffe25c6f75658a7b..3984782f20d9cc1c318e9b79879e81fca2f37430 100644 (file)
-/***********************************************************************\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
-#ifndef SKP_SILK_MAIN_H\r
-#define SKP_SILK_MAIN_H\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_define.h"\r
-#include "SKP_Silk_structs.h"\r
-#include "SKP_Silk_tables.h"\r
-#include "SKP_Silk_PLC.h"\r
-\r
-\r
-/* Encodes signs of excitation */\r
-void SKP_Silk_encode_signs(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
-    const SKP_int8              q[],                /* I    pulse signal                                */\r
-    const SKP_int               length,             /* I    length of input                             */\r
-    const SKP_int               sigtype,            /* I    Signal type                                 */\r
-    const SKP_int               QuantOffsetType,    /* I    Quantization offset type                    */\r
-    const SKP_int               RateLevelIndex      /* I    Rate Level Index                            */\r
-);\r
-\r
-/* Decodes signs of excitation */\r
-void SKP_Silk_decode_signs(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
-    SKP_int                     q[],                /* I/O  pulse signal                                */\r
-    const SKP_int               length,             /* I    length of output                            */\r
-    const SKP_int               sigtype,            /* I    Signal type                                 */\r
-    const SKP_int               QuantOffsetType,    /* I    Quantization offset type                    */\r
-    const SKP_int               RateLevelIndex      /* I    Rate Level Index                            */\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
-    const SKP_int32             TargetRate_bps      /* I    Target max bitrate (bps)                    */\r
-);\r
-\r
-/***************/\r
-/* Shell coder */\r
-/***************/\r
-\r
-/* Encode quantization indices of excitation */\r
-void SKP_Silk_encode_pulses(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
-    const SKP_int               sigtype,            /* I    Sigtype                                     */\r
-    const SKP_int               QuantOffsetType,    /* I    QuantOffsetType                             */\r
-    const SKP_int8              q[],                /* I    quantization indices                        */\r
-    const SKP_int               frame_length        /* I    Frame length                                */\r
-);\r
-\r
-/* Shell encoder, operates on one shell code frame of 16 pulses */\r
-void SKP_Silk_shell_encoder(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int               *pulses0            /* I    data: nonnegative pulse amplitudes          */\r
-);\r
-\r
-/* Shell decoder, operates on one shell code frame of 16 pulses */\r
-void SKP_Silk_shell_decoder(\r
-    SKP_int                     *pulses0,           /* O    data: nonnegative pulse amplitudes          */\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int               pulses4             /* I    number of pulses per pulse-subframe         */\r
-);\r
-\r
-/***************/\r
-/* Range coder */\r
-/***************/\r
-/* Range encoder for one symbol */\r
-void SKP_Silk_range_encoder(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int               data,               /* I    uncompressed data                           */\r
-    const SKP_uint16            prob[]              /* I    cumulative density functions                */\r
-);\r
-    \r
-/* Range encoder for multiple symbols */\r
-void SKP_Silk_range_encoder_multi(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int               data[],             /* I    uncompressed data    [nSymbols]             */\r
-    const SKP_uint16 * const    prob[],             /* I    cumulative density functions                */\r
-    const SKP_int               nSymbols            /* I    number of data symbols                      */\r
-);\r
-\r
-/* Range decoder for one symbol */\r
-void SKP_Silk_range_decoder(\r
-    SKP_int                     data[],             /* O    uncompressed data                           */\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_uint16            prob[],             /* I    cumulative density function                 */\r
-    SKP_int                     probIx              /* I    initial (middle) entry of cdf               */\r
-);\r
-\r
-/* Range decoder for multiple symbols */\r
-void SKP_Silk_range_decoder_multi(\r
-    SKP_int                     data[],             /* O    uncompressed data                [nSymbols] */\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_uint16 * const    prob[],             /* I    cumulative density functions                */\r
-    const SKP_int               probStartIx[],      /* I    initial (middle) entries of cdfs [nSymbols] */\r
-    const SKP_int               nSymbols            /* I    number of data symbols                      */\r
-);\r
-\r
-/* Initialize range coder structure for encoder */\r
-void SKP_Silk_range_enc_init(\r
-    SKP_Silk_range_coder_state  *psRC               /* O    compressor data structure                   */\r
-);\r
-\r
-/* Initialize range coder structure for decoder */\r
-void SKP_Silk_range_dec_init(\r
-    SKP_Silk_range_coder_state  *psRC,              /* O    compressor data structure                   */\r
-    const SKP_uint8             buffer[],           /* I    buffer for compressed data [bufferLength]   */\r
-    const SKP_int32             bufferLength        /* I    buffer length (in bytes)                    */\r
-);\r
-\r
-/* Determine length of bitstream */\r
-SKP_int SKP_Silk_range_coder_get_length(            /* O    returns number of BITS in stream            */\r
-    const SKP_Silk_range_coder_state    *psRC,      /* I    compressed data structure                   */\r
-    SKP_int                             *nBytes     /* O    number of BYTES in stream                   */\r
-);\r
-\r
-/* Write decodable stream to buffer, and determine its length */\r
-void SKP_Silk_range_enc_wrap_up(\r
-    SKP_Silk_range_coder_state  *psRC               /* I/O  compressed data structure                   */\r
-);\r
-\r
-/* Check that any remaining bits in the last byte are set to 1 */\r
-void SKP_Silk_range_coder_check_after_decoding(\r
-    SKP_Silk_range_coder_state  *psRC               /* I/O  compressed data structure                   */\r
-);\r
-\r
-/* Gain scalar quantization with hysteresis, uniform on log scale */\r
-void SKP_Silk_gains_quant(\r
-    SKP_int                     ind[ NB_SUBFR ],        /* O    gain indices                            */\r
-    SKP_int32                   gain_Q16[ NB_SUBFR ],   /* I/O  gains (quantized out)                   */\r
-    SKP_int                     *prev_ind,              /* I/O  last index in previous frame            */\r
-    const SKP_int               conditional             /* I    first gain is delta coded if 1          */\r
-);\r
-\r
-/* Gains scalar dequantization, uniform on log scale */\r
-void SKP_Silk_gains_dequant(\r
-    SKP_int32                   gain_Q16[ NB_SUBFR ],   /* O    quantized gains                         */\r
-    const SKP_int               ind[ NB_SUBFR ],        /* I    gain indices                            */\r
-    SKP_int                     *prev_ind,              /* I/O  last index in previous frame            */\r
-    const SKP_int               conditional             /* I    first gain is delta coded if 1          */\r
-);\r
-\r
-/* Convert NLSF parameters to stable AR prediction filter coefficients */\r
-void SKP_Silk_NLSF2A_stable(\r
-    SKP_int16                   pAR_Q12[ MAX_LPC_ORDER ],   /* O    Stabilized AR coefs [LPC_order]     */ \r
-    const SKP_int               pNLSF[ MAX_LPC_ORDER ],     /* I    NLSF vector         [LPC_order]     */\r
-    const SKP_int               LPC_order                   /* I    LPC/LSF order                       */\r
-);\r
-\r
-/* Interpolate two vectors */\r
-void SKP_Silk_interpolate(\r
-    SKP_int                     xi[ MAX_LPC_ORDER ],    /* O    interpolated vector                     */\r
-    const SKP_int               x0[ MAX_LPC_ORDER ],    /* I    first vector                            */\r
-    const SKP_int               x1[ MAX_LPC_ORDER ],    /* I    second vector                           */\r
-    const SKP_int               ifact_Q2,               /* I    interp. factor, weight on 2nd vector    */\r
-    const SKP_int               d                       /* I    number of parameters                    */\r
-);\r
-\r
-/***********************************/\r
-/* Noise shaping quantization (NSQ)*/\r
-/***********************************/\r
-void SKP_Silk_NSQ(\r
-    SKP_Silk_encoder_state          *psEncC,                                    /* I/O  Encoder State                       */\r
-    SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */\r
-    SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */\r
-    const SKP_int16                 x[],                                        /* I    prefiltered input signal            */\r
-    SKP_int8                        q[],                                        /* O    quantized qulse signal              */\r
-    const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */\r
-    const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Short term prediction coefficients  */\r
-    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    Long term prediction coefficients   */\r
-    const SKP_int16                 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ],  /* I                                        */\r
-    const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */\r
-    const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */\r
-    const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */\r
-    const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */\r
-    const SKP_int                   Lambda_Q10,                                 /* I                                        */\r
-    const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */\r
-);\r
-\r
-/* Noise shaping using delayed decision */\r
-void SKP_Silk_NSQ_del_dec(\r
-    SKP_Silk_encoder_state          *psEncC,                                    /* I/O  Encoder State                       */\r
-    SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */\r
-    SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */\r
-    const SKP_int16                 x[],                                        /* I    Prefiltered input signal            */\r
-    SKP_int8                        q[],                                        /* O    Quantized pulse signal              */\r
-    const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */\r
-    const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Prediction coefs                    */\r
-    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    LT prediction coefs                 */\r
-    const SKP_int16                 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ],  /* I                                        */\r
-    const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */\r
-    const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */\r
-    const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */\r
-    const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */\r
-    const SKP_int                   Lambda_Q10,                                 /* I                                        */\r
-    const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */\r
-);\r
-\r
-/************/\r
-/* Silk VAD */\r
-/************/\r
-/* Initialize the Silk VAD */\r
-SKP_int SKP_Silk_VAD_Init(                          /* O    Return value, 0 if success                  */ \r
-    SKP_Silk_VAD_state          *psSilk_VAD         /* I/O  Pointer to Silk VAD state                   */ \r
-); \r
-\r
-/* Silk VAD noise level estimation */\r
-void SKP_Silk_VAD_GetNoiseLevels(\r
-    const SKP_int32             pX[ VAD_N_BANDS ],  /* I    subband energies                            */\r
-    SKP_Silk_VAD_state          *psSilk_VAD         /* I/O  Pointer to Silk VAD state                   */ \r
-);\r
-\r
-/* Get speech activity level in Q8 */\r
-SKP_int SKP_Silk_VAD_GetSA_Q8(                                  /* O    Return value, 0 if success      */\r
-    SKP_Silk_VAD_state          *psSilk_VAD,                    /* I/O  Silk VAD state                  */\r
-    SKP_int                     *pSA_Q8,                        /* O    Speech activity level in Q8     */\r
-    SKP_int                     *pSNR_dB_Q7,                    /* O    SNR for current frame in Q7     */\r
-    SKP_int                     pQuality_Q15[ VAD_N_BANDS ],    /* O    Smoothed SNR for each band      */\r
-    SKP_int                     *pTilt_Q15,                     /* O    current frame's frequency tilt  */\r
-    const SKP_int16             pIn[],                          /* I    PCM input       [framelength]   */\r
-    const SKP_int               framelength                     /* I    Input frame length              */\r
-);\r
-\r
-/* Detect signal in 8 - 12 khz range */\r
-void SKP_Silk_detect_SWB_input(\r
-    SKP_Silk_detect_SWB_state   *psSWBdetect,       /* I/O  Encoder state                               */\r
-    const SKP_int16             samplesIn[],        /* I    Input to encoder                            */\r
-    SKP_int                     nSamplesIn          /* 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
-void SKP_Silk_LP_variable_cutoff(\r
-    SKP_Silk_LP_state           *psLP,              /* I/O  LP filter state                             */\r
-    SKP_int16                   *out,               /* O    Low-pass filtered output signal             */\r
-    const SKP_int16             *in,                /* I    Input signal                                */\r
-    const SKP_int               frame_length        /* I    Frame length                                */\r
-);\r
-#endif\r
-\r
-/****************************************************/\r
-/* Decoder Functions                                */\r
-/****************************************************/\r
-SKP_int SKP_Silk_create_decoder(\r
-    SKP_Silk_decoder_state      **ppsDec            /* I/O  Decoder state pointer pointer               */\r
-);\r
-\r
-SKP_int SKP_Silk_free_decoder(\r
-    SKP_Silk_decoder_state      *psDec              /* I/O  Decoder state pointer                       */\r
-);\r
-\r
-SKP_int SKP_Silk_init_decoder(\r
-    SKP_Silk_decoder_state      *psDec              /* I/O  Decoder state pointer                       */\r
-);\r
-\r
-/* Set decoder sampling rate */\r
-void SKP_Silk_decoder_set_fs(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O  Decoder state pointer                       */\r
-    SKP_int                     fs_kHz              /* I    Sampling frequency (kHz)                    */\r
-);\r
-\r
-/****************/\r
-/* Decode frame */\r
-/****************/\r
-SKP_int SKP_Silk_decode_frame(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O  Pointer to Silk decoder state               */\r
-    SKP_int16                   pOut[],             /* O    Pointer to output speech frame              */\r
-    SKP_int16                   *pN,                /* O    Pointer to size of output frame             */\r
-    const SKP_uint8             pCode[],            /* I    Pointer to payload                          */\r
-    const SKP_int               nBytes,             /* I    Payload length                              */\r
-    SKP_int                     action,             /* I    Action from Jitter Buffer                   */\r
-    SKP_int                     *decBytes           /* O    Used bytes to decode this frame             */\r
-);\r
-\r
-/* Decode parameters from payload */\r
-void SKP_Silk_decode_parameters(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O  State                                       */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */\r
-    SKP_int                     q[],                /* O    Excitation signal                           */\r
-    const SKP_int               fullDecoding        /* I    Flag to tell if only arithmetic decoding    */\r
-);\r
-\r
-/* Core decoder. Performs inverse NSQ operation LTP + LPC */\r
-void SKP_Silk_decode_core(\r
-    SKP_Silk_decoder_state      *psDec,                             /* I/O  Decoder state               */\r
-    SKP_Silk_decoder_control    *psDecCtrl,                         /* I    Decoder control             */\r
-    SKP_int16                   xq[],                               /* O    Decoded speech              */\r
-    const SKP_int               q[ MAX_FRAME_LENGTH ]               /* I    Pulse signal                */\r
-);\r
-\r
-/* NLSF vector decoder */\r
-void SKP_Silk_NLSF_MSVQ_decode(\r
-    SKP_int                         *pNLSF_Q15,     /* O    Pointer to decoded output [LPC_ORDER x 1]   */\r
-    const SKP_Silk_NLSF_CB_struct   *psNLSF_CB,     /* I    Pointer to NLSF codebook struct             */\r
-    const SKP_int                   *NLSFIndices,   /* I    Pointer to NLSF indices [nStages x 1]       */\r
-    const SKP_int                   LPC_order       /* I    LPC order                                   */\r
-);\r
-\r
-/**********************/\r
-/* Arithmetic coding */\r
-/*********************/\r
-\r
-/* Decode quantization indices of excitation (Shell coding) */\r
-void SKP_Silk_decode_pulses(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */\r
-    SKP_int                     q[],                /* O    Excitation signal                           */\r
-    const SKP_int               frame_length        /* I    Frame length (preliminary)                  */\r
-);\r
-\r
-/******************/\r
-/* CNG */\r
-/******************/\r
-\r
-/* Reset CNG */\r
-void SKP_Silk_CNG_Reset(\r
-    SKP_Silk_decoder_state      *psDec              /* I/O  Decoder state                               */\r
-);\r
-\r
-/* Updates CNG estimate, and applies the CNG when packet was lost   */\r
-void SKP_Silk_CNG(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O  Decoder state                               */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */\r
-    SKP_int16                   signal[],           /* I/O  Signal                                      */\r
-    SKP_int                     length              /* I    Length of residual                          */\r
-);\r
-\r
-/* Encoding of various parameters */\r
-void SKP_Silk_encode_parameters(\r
-    SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */\r
-    SKP_Silk_encoder_control    *psEncCtrlC,        /* I/O  Encoder control                             */\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
-    const SKP_int8               *q                 /* I    Quantization indices                        */\r
-);\r
-\r
-/* Extract lowest layer encoding */\r
-void SKP_Silk_get_low_layer_internal(\r
-    const SKP_uint8             *indata,            /* I:   Encoded input vector                        */\r
-    const SKP_int16             nBytesIn,           /* I:   Number of input Bytes                       */\r
-    SKP_uint8                   *Layer0data,        /* O:   Layer0 payload                              */\r
-    SKP_int16                   *nLayer0Bytes       /* O:   Number of FEC Bytes                         */\r
-);\r
-\r
-/* Resets LBRR buffer, used if packet size changes */\r
-void SKP_Silk_LBRR_reset( \r
-    SKP_Silk_encoder_state      *psEncC             /* I/O  Pointer to Silk encoder state               */\r
-);\r
-\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_MAIN_H
+#define SKP_SILK_MAIN_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_define.h"
+#include "SKP_Silk_structs.h"
+#include "SKP_Silk_tables.h"
+#include "SKP_Silk_PLC.h"
+
+
+/* Encodes signs of excitation */
+void SKP_Silk_encode_signs(
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */
+    const SKP_int8              q[],                /* I    pulse signal                                */
+    const SKP_int               length,             /* I    length of input                             */
+    const SKP_int               sigtype,            /* I    Signal type                                 */
+    const SKP_int               QuantOffsetType,    /* I    Quantization offset type                    */
+    const SKP_int               RateLevelIndex      /* I    Rate Level Index                            */
+);
+
+/* Decodes signs of excitation */
+void SKP_Silk_decode_signs(
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */
+    SKP_int                     q[],                /* I/O  pulse signal                                */
+    const SKP_int               length,             /* I    length of output                            */
+    const SKP_int               sigtype,            /* I    Signal type                                 */
+    const SKP_int               QuantOffsetType,    /* I    Quantization offset type                    */
+    const SKP_int               RateLevelIndex      /* I    Rate Level Index                            */
+);
+
+/* Control internal sampling rate */
+SKP_int SKP_Silk_control_audio_bandwidth(
+    SKP_Silk_encoder_state      *psEncC,            /* I/O  Pointer to Silk encoder state               */
+    const SKP_int32             TargetRate_bps      /* I    Target max bitrate (bps)                    */
+);
+
+/***************/
+/* Shell coder */
+/***************/
+
+/* Encode quantization indices of excitation */
+void SKP_Silk_encode_pulses(
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */
+    const SKP_int               sigtype,            /* I    Sigtype                                     */
+    const SKP_int               QuantOffsetType,    /* I    QuantOffsetType                             */
+    const SKP_int8              q[],                /* I    quantization indices                        */
+    const SKP_int               frame_length        /* I    Frame length                                */
+);
+
+/* Shell encoder, operates on one shell code frame of 16 pulses */
+void SKP_Silk_shell_encoder(
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
+    const SKP_int               *pulses0            /* I    data: nonnegative pulse amplitudes          */
+);
+
+/* Shell decoder, operates on one shell code frame of 16 pulses */
+void SKP_Silk_shell_decoder(
+    SKP_int                     *pulses0,           /* O    data: nonnegative pulse amplitudes          */
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
+    const SKP_int               pulses4             /* I    number of pulses per pulse-subframe         */
+);
+
+/***************/
+/* Range coder */
+/***************/
+/* Range encoder for one symbol */
+void SKP_Silk_range_encoder(
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
+    const SKP_int               data,               /* I    uncompressed data                           */
+    const SKP_uint16            prob[]              /* I    cumulative density functions                */
+);
+    
+/* Range encoder for multiple symbols */
+void SKP_Silk_range_encoder_multi(
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
+    const SKP_int               data[],             /* I    uncompressed data    [nSymbols]             */
+    const SKP_uint16 * const    prob[],             /* I    cumulative density functions                */
+    const SKP_int               nSymbols            /* I    number of data symbols                      */
+);
+
+/* Range decoder for one symbol */
+void SKP_Silk_range_decoder(
+    SKP_int                     data[],             /* O    uncompressed data                           */
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
+    const SKP_uint16            prob[],             /* I    cumulative density function                 */
+    SKP_int                     probIx              /* I    initial (middle) entry of cdf               */
+);
+
+/* Range decoder for multiple symbols */
+void SKP_Silk_range_decoder_multi(
+    SKP_int                     data[],             /* O    uncompressed data                [nSymbols] */
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
+    const SKP_uint16 * const    prob[],             /* I    cumulative density functions                */
+    const SKP_int               probStartIx[],      /* I    initial (middle) entries of cdfs [nSymbols] */
+    const SKP_int               nSymbols            /* I    number of data symbols                      */
+);
+
+/* Initialize range coder structure for encoder */
+void SKP_Silk_range_enc_init(
+    SKP_Silk_range_coder_state  *psRC               /* O    compressor data structure                   */
+);
+
+/* Initialize range coder structure for decoder */
+void SKP_Silk_range_dec_init(
+    SKP_Silk_range_coder_state  *psRC,              /* O    compressor data structure                   */
+    const SKP_uint8             buffer[],           /* I    buffer for compressed data [bufferLength]   */
+    const SKP_int32             bufferLength        /* I    buffer length (in bytes)                    */
+);
+
+/* Determine length of bitstream */
+SKP_int SKP_Silk_range_coder_get_length(            /* O    returns number of BITS in stream            */
+    const SKP_Silk_range_coder_state    *psRC,      /* I    compressed data structure                   */
+    SKP_int                             *nBytes     /* O    number of BYTES in stream                   */
+);
+
+/* Write decodable stream to buffer, and determine its length */
+void SKP_Silk_range_enc_wrap_up(
+    SKP_Silk_range_coder_state  *psRC               /* I/O  compressed data structure                   */
+);
+
+/* Check that any remaining bits in the last byte are set to 1 */
+void SKP_Silk_range_coder_check_after_decoding(
+    SKP_Silk_range_coder_state  *psRC               /* I/O  compressed data structure                   */
+);
+
+/* Gain scalar quantization with hysteresis, uniform on log scale */
+void SKP_Silk_gains_quant(
+    SKP_int                     ind[ NB_SUBFR ],        /* O    gain indices                            */
+    SKP_int32                   gain_Q16[ NB_SUBFR ],   /* I/O  gains (quantized out)                   */
+    SKP_int                     *prev_ind,              /* I/O  last index in previous frame            */
+    const SKP_int               conditional             /* I    first gain is delta coded if 1          */
+);
+
+/* Gains scalar dequantization, uniform on log scale */
+void SKP_Silk_gains_dequant(
+    SKP_int32                   gain_Q16[ NB_SUBFR ],   /* O    quantized gains                         */
+    const SKP_int               ind[ NB_SUBFR ],        /* I    gain indices                            */
+    SKP_int                     *prev_ind,              /* I/O  last index in previous frame            */
+    const SKP_int               conditional             /* I    first gain is delta coded if 1          */
+);
+
+/* Convert NLSF parameters to stable AR prediction filter coefficients */
+void SKP_Silk_NLSF2A_stable(
+    SKP_int16                   pAR_Q12[ MAX_LPC_ORDER ],   /* O    Stabilized AR coefs [LPC_order]     */ 
+    const SKP_int               pNLSF[ MAX_LPC_ORDER ],     /* I    NLSF vector         [LPC_order]     */
+    const SKP_int               LPC_order                   /* I    LPC/LSF order                       */
+);
+
+/* Interpolate two vectors */
+void SKP_Silk_interpolate(
+    SKP_int                     xi[ MAX_LPC_ORDER ],    /* O    interpolated vector                     */
+    const SKP_int               x0[ MAX_LPC_ORDER ],    /* I    first vector                            */
+    const SKP_int               x1[ MAX_LPC_ORDER ],    /* I    second vector                           */
+    const SKP_int               ifact_Q2,               /* I    interp. factor, weight on 2nd vector    */
+    const SKP_int               d                       /* I    number of parameters                    */
+);
+
+/***********************************/
+/* Noise shaping quantization (NSQ)*/
+/***********************************/
+void SKP_Silk_NSQ(
+    SKP_Silk_encoder_state          *psEncC,                                    /* I/O  Encoder State                       */
+    SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */
+    SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */
+    const SKP_int16                 x[],                                        /* I    prefiltered input signal            */
+    SKP_int8                        q[],                                        /* O    quantized qulse signal              */
+    const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */
+    const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Short term prediction coefficients  */
+    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    Long term prediction coefficients   */
+    const SKP_int16                 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ],  /* I                                        */
+    const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */
+    const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */
+    const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */
+    const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */
+    const SKP_int                   Lambda_Q10,                                 /* I                                        */
+    const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */
+);
+
+/* Noise shaping using delayed decision */
+void SKP_Silk_NSQ_del_dec(
+    SKP_Silk_encoder_state          *psEncC,                                    /* I/O  Encoder State                       */
+    SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */
+    SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */
+    const SKP_int16                 x[],                                        /* I    Prefiltered input signal            */
+    SKP_int8                        q[],                                        /* O    Quantized pulse signal              */
+    const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */
+    const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Prediction coefs                    */
+    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    LT prediction coefs                 */
+    const SKP_int16                 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ],  /* I                                        */
+    const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */
+    const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */
+    const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */
+    const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */
+    const SKP_int                   Lambda_Q10,                                 /* I                                        */
+    const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */
+);
+
+/************/
+/* Silk VAD */
+/************/
+/* Initialize the Silk VAD */
+SKP_int SKP_Silk_VAD_Init(                          /* O    Return value, 0 if success                  */ 
+    SKP_Silk_VAD_state          *psSilk_VAD         /* I/O  Pointer to Silk VAD state                   */ 
+); 
+
+/* Silk VAD noise level estimation */
+void SKP_Silk_VAD_GetNoiseLevels(
+    const SKP_int32             pX[ VAD_N_BANDS ],  /* I    subband energies                            */
+    SKP_Silk_VAD_state          *psSilk_VAD         /* I/O  Pointer to Silk VAD state                   */ 
+);
+
+/* Get speech activity level in Q8 */
+SKP_int SKP_Silk_VAD_GetSA_Q8(                                  /* O    Return value, 0 if success      */
+    SKP_Silk_VAD_state          *psSilk_VAD,                    /* I/O  Silk VAD state                  */
+    SKP_int                     *pSA_Q8,                        /* O    Speech activity level in Q8     */
+    SKP_int                     *pSNR_dB_Q7,                    /* O    SNR for current frame in Q7     */
+    SKP_int                     pQuality_Q15[ VAD_N_BANDS ],    /* O    Smoothed SNR for each band      */
+    SKP_int                     *pTilt_Q15,                     /* O    current frame's frequency tilt  */
+    const SKP_int16             pIn[],                          /* I    PCM input       [framelength]   */
+    const SKP_int               framelength                     /* I    Input frame length              */
+);
+
+/* Detect signal in 8 - 12 khz range */
+void SKP_Silk_detect_SWB_input(
+    SKP_Silk_detect_SWB_state   *psSWBdetect,       /* I/O  Encoder state                               */
+    const SKP_int16             samplesIn[],        /* I    Input to encoder                            */
+    SKP_int                     nSamplesIn          /* I    Length of input                             */
+);
+
+#if SWITCH_TRANSITION_FILTERING
+/* Low-pass filter with variable cutoff frequency based on  */
+/* piece-wise linear interpolation between elliptic filters */
+/* Start by setting transition_frame_no = 1;                */
+void SKP_Silk_LP_variable_cutoff(
+    SKP_Silk_LP_state           *psLP,              /* I/O  LP filter state                             */
+    SKP_int16                   *out,               /* O    Low-pass filtered output signal             */
+    const SKP_int16             *in,                /* I    Input signal                                */
+    const SKP_int               frame_length        /* I    Frame length                                */
+);
+#endif
+
+/****************************************************/
+/* Decoder Functions                                */
+/****************************************************/
+SKP_int SKP_Silk_create_decoder(
+    SKP_Silk_decoder_state      **ppsDec            /* I/O  Decoder state pointer pointer               */
+);
+
+SKP_int SKP_Silk_free_decoder(
+    SKP_Silk_decoder_state      *psDec              /* I/O  Decoder state pointer                       */
+);
+
+SKP_int SKP_Silk_init_decoder(
+    SKP_Silk_decoder_state      *psDec              /* I/O  Decoder state pointer                       */
+);
+
+/* Set decoder sampling rate */
+void SKP_Silk_decoder_set_fs(
+    SKP_Silk_decoder_state      *psDec,             /* I/O  Decoder state pointer                       */
+    SKP_int                     fs_kHz              /* I    Sampling frequency (kHz)                    */
+);
+
+/****************/
+/* Decode frame */
+/****************/
+SKP_int SKP_Silk_decode_frame(
+    SKP_Silk_decoder_state      *psDec,             /* I/O  Pointer to Silk decoder state               */
+    SKP_int16                   pOut[],             /* O    Pointer to output speech frame              */
+    SKP_int16                   *pN,                /* O    Pointer to size of output frame             */
+    const SKP_uint8             pCode[],            /* I    Pointer to payload                          */
+    const SKP_int               nBytes,             /* I    Payload length                              */
+    SKP_int                     action,             /* I    Action from Jitter Buffer                   */
+    SKP_int                     *decBytes           /* O    Used bytes to decode this frame             */
+);
+
+/* Decode parameters from payload */
+void SKP_Silk_decode_parameters(
+    SKP_Silk_decoder_state      *psDec,             /* I/O  State                                       */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */
+    SKP_int                     q[],                /* O    Excitation signal                           */
+    const SKP_int               fullDecoding        /* I    Flag to tell if only arithmetic decoding    */
+);
+
+/* Core decoder. Performs inverse NSQ operation LTP + LPC */
+void SKP_Silk_decode_core(
+    SKP_Silk_decoder_state      *psDec,                             /* I/O  Decoder state               */
+    SKP_Silk_decoder_control    *psDecCtrl,                         /* I    Decoder control             */
+    SKP_int16                   xq[],                               /* O    Decoded speech              */
+    const SKP_int               q[ MAX_FRAME_LENGTH ]               /* I    Pulse signal                */
+);
+
+/* NLSF vector decoder */
+void SKP_Silk_NLSF_MSVQ_decode(
+    SKP_int                         *pNLSF_Q15,     /* O    Pointer to decoded output [LPC_ORDER x 1]   */
+    const SKP_Silk_NLSF_CB_struct   *psNLSF_CB,     /* I    Pointer to NLSF codebook struct             */
+    const SKP_int                   *NLSFIndices,   /* I    Pointer to NLSF indices [nStages x 1]       */
+    const SKP_int                   LPC_order       /* I    LPC order                                   */
+);
+
+/**********************/
+/* Arithmetic coding */
+/*********************/
+
+/* Decode quantization indices of excitation (Shell coding) */
+void SKP_Silk_decode_pulses(
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */
+    SKP_int                     q[],                /* O    Excitation signal                           */
+    const SKP_int               frame_length        /* I    Frame length (preliminary)                  */
+);
+
+/******************/
+/* CNG */
+/******************/
+
+/* Reset CNG */
+void SKP_Silk_CNG_Reset(
+    SKP_Silk_decoder_state      *psDec              /* I/O  Decoder state                               */
+);
+
+/* Updates CNG estimate, and applies the CNG when packet was lost   */
+void SKP_Silk_CNG(
+    SKP_Silk_decoder_state      *psDec,             /* I/O  Decoder state                               */
+    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */
+    SKP_int16                   signal[],           /* I/O  Signal                                      */
+    SKP_int                     length              /* I    Length of residual                          */
+);
+
+/* Encoding of various parameters */
+void SKP_Silk_encode_parameters(
+    SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */
+    SKP_Silk_encoder_control    *psEncCtrlC,        /* I/O  Encoder control                             */
+    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */
+    const SKP_int8               *q                 /* I    Quantization indices                        */
+);
+
+/* Extract lowest layer encoding */
+void SKP_Silk_get_low_layer_internal(
+    const SKP_uint8             *indata,            /* I:   Encoded input vector                        */
+    const SKP_int16             nBytesIn,           /* I:   Number of input Bytes                       */
+    SKP_uint8                   *Layer0data,        /* O:   Layer0 payload                              */
+    SKP_int16                   *nLayer0Bytes       /* O:   Number of FEC Bytes                         */
+);
+
+/* Resets LBRR buffer, used if packet size changes */
+void SKP_Silk_LBRR_reset( 
+    SKP_Silk_encoder_state      *psEncC             /* I/O  Pointer to Silk encoder state               */
+);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 935e6c74378a13259674f3cbea7c21235dc8f7e1..37d554645ce36f22194767fb97f8b239281de3d7 100644 (file)
-/***********************************************************************\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
-#ifndef SKP_SILK_MAIN_FIX_H\r
-#define SKP_SILK_MAIN_FIX_H\r
-\r
-#include <stdlib.h>\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_structs_FIX.h"\r
-#include "SKP_Silk_main.h"\r
-#include "SKP_Silk_PLC.h"\r
-#define TIC(TAG_NAME)\r
-#define TOC(TAG_NAME)\r
-\r
-#ifndef FORCE_CPP_BUILD\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-#endif\r
-\r
-/*********************/\r
-/* Encoder Functions */\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
-);\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               DTX_enabled,            /* I    Enable / disable DTX                    */\r
-    const SKP_int               Complexity              /* I    Complexity (0->low; 1->medium; 2->high) */\r
-);\r
-\r
-/* Encoder main function */\r
-SKP_int SKP_Silk_encode_frame_FIX( \r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk FIX encoder state           */\r
-    SKP_uint8                       *pCode,             /* O    Pointer to payload                          */\r
-    SKP_int16                       *pnBytesOut,        /* I/O  Pointer to number of payload bytes;         */\r
-                                                        /*      input: max length; output: used             */\r
-    const SKP_int16                 *pIn                /* I    Pointer to input speech frame               */\r
-);\r
-\r
-/* Low BitRate Redundancy encoding functionality. 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
-    SKP_uint8                       *pCode,         /* O    Pointer to payload                          */\r
-    SKP_int16                       *pnBytesOut,    /* I/O  Pointer to number of payload bytes          */\r
-    SKP_int16                       xfw[]           /* I    Input signal                                */\r
-);\r
-\r
-/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */\r
-void SKP_Silk_HP_variable_cutoff_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Encoder state                               */\r
-    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  Encoder control                             */\r
-    SKP_int16                       *out,           /* O    high-pass filtered output signal            */\r
-    const SKP_int16                 *in             /* I    input signal                                */\r
-);\r
-\r
-/****************/\r
-/* Prefiltering */\r
-/****************/\r
-void SKP_Silk_prefilter_FIX(\r
-    SKP_Silk_encoder_state_FIX          *psEnc,         /* I/O  Encoder state                               */\r
-    const SKP_Silk_encoder_control_FIX  *psEncCtrl,     /* I    Encoder control                             */\r
-    SKP_int16                           xw[],           /* O    Weighted signal                             */\r
-    const SKP_int16                     x[]             /* I    Speech signal                               */\r
-);\r
-\r
-/**************************************************************/\r
-/* Compute noise shaping coefficients and initial gain values */\r
-/**************************************************************/\r
-void SKP_Silk_noise_shape_analysis_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
-    const SKP_int16                 *pitch_res,     /* I    LPC residual from pitch analysis            */\r
-    const SKP_int16                 *x              /* I    Input signal [ frame_length + la_shape ]    */\r
-);\r
-\r
-/* Autocorrelations for a warped frequency axis */\r
-void SKP_Silk_warped_autocorrelation_FIX(\r
-          SKP_int32                 *corr,              /* O    Result [order + 1]                      */\r
-          SKP_int                   *scale,             /* O    Scaling of the correlation vector       */\r
-    const SKP_int16                 *input,             /* I    Input data to correlate                 */\r
-    const SKP_int16                 warping_Q16,        /* I    Warping coefficient                     */\r
-    const SKP_int                   length,             /* I    Length of input                         */\r
-    const SKP_int                   order               /* I    Correlation order (even)                */\r
-);\r
-\r
-/* Processing of gains */\r
-void SKP_Silk_process_gains_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Encoder state                               */\r
-    SKP_Silk_encoder_control_FIX    *psEncCtrl      /* I/O  Encoder control                             */\r
-);\r
-\r
-/* Control low bitrate redundancy usage */\r
-void SKP_Silk_LBRR_ctrl_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */\r
-    SKP_Silk_encoder_control        *psEncCtrlC     /* I/O  encoder control                             */\r
-);\r
-\r
-/* Calculation of LTP state scaling */\r
-void SKP_Silk_LTP_scale_ctrl_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */\r
-    SKP_Silk_encoder_control_FIX    *psEncCtrl      /* I/O  encoder control                             */\r
-);\r
-\r
-/**********************************************/\r
-/* Prediction Analysis                        */\r
-/**********************************************/\r
-\r
-/* Find pitch lags */\r
-void SKP_Silk_find_pitch_lags_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */\r
-    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  encoder control                             */\r
-    SKP_int16                       res[],          /* O    residual                                    */\r
-    const SKP_int16                 x[]             /* I    Speech signal                               */\r
-);\r
-\r
-void SKP_Silk_find_pred_coefs_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */\r
-    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  encoder control                             */\r
-    const SKP_int16                 res_pitch[]     /* I    Residual from pitch analysis                */\r
-);\r
-\r
-void SKP_Silk_find_LPC_FIX(\r
-    SKP_int             NLSF_Q15[],             /* O    NLSFs                                                                       */\r
-    SKP_int             *interpIndex,           /* O    NLSF interpolation index, only used for NLSF interpolation                  */\r
-    const SKP_int       prev_NLSFq_Q15[],       /* I    previous NLSFs, only used for NLSF interpolation                            */\r
-    const SKP_int       useInterpolatedLSFs,    /* I    Flag                                                                        */\r
-    const SKP_int       LPC_order,              /* I    LPC order                                                                   */\r
-    const SKP_int16     x[],                    /* I    Input signal                                                                */\r
-    const SKP_int       subfr_length            /* I    Input signal subframe length including preceeding samples                   */\r
-);\r
-\r
-void SKP_Silk_LTP_analysis_filter_FIX(\r
-    SKP_int16       *LTP_res,                           /* O:   LTP residual signal of length NB_SUBFR * ( pre_length + subfr_length )  */\r
-    const SKP_int16 *x,                                 /* I:   Pointer to input signal with at least max( pitchL ) preceeding samples  */\r
-    const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],/* I:   LTP_ORDER LTP coefficients for each NB_SUBFR subframe                   */\r
-    const SKP_int   pitchL[ NB_SUBFR ],                 /* I:   Pitch lag, one for each subframe                                        */\r
-    const SKP_int32 invGains_Q16[ NB_SUBFR ],           /* I:   Inverse quantization gains, one for each subframe                       */\r
-    const SKP_int   subfr_length,                       /* I:   Length of each subframe                                                 */\r
-    const SKP_int   pre_length                          /* I:   Length of the preceeding samples starting at &x[0] for each subframe    */\r
-);\r
-\r
-/* Finds LTP vector from correlations */\r
-void SKP_Silk_find_LTP_FIX(\r
-    SKP_int16           b_Q14[ NB_SUBFR * LTP_ORDER ],              /* O    LTP coefs                                                   */\r
-    SKP_int32           WLTP[ NB_SUBFR * LTP_ORDER * LTP_ORDER ],   /* O    Weight for LTP quantization                                 */\r
-    SKP_int             *LTPredCodGain_Q7,                          /* O    LTP coding gain                                             */\r
-    const SKP_int16     r_first[],                                  /* I    residual signal after LPC signal + state for first 10 ms    */\r
-    const SKP_int16     r_last[],                                   /* I    residual signal after LPC signal + state for last 10 ms     */\r
-    const SKP_int       lag[ NB_SUBFR ],                            /* I    LTP lags                                                    */\r
-    const SKP_int32     Wght_Q15[ NB_SUBFR ],                       /* I    weights                                                     */\r
-    const SKP_int       subfr_length,                               /* I    subframe length                                             */\r
-    const SKP_int       mem_offset,                                 /* I    number of samples in LTP memory                             */\r
-    SKP_int             corr_rshifts[ NB_SUBFR ]                    /* O    right shifts applied to correlations                        */\r
-);\r
-\r
-/* LTP tap quantizer */\r
-void SKP_Silk_quant_LTP_gains_FIX(\r
-    SKP_int16               B_Q14[],                /* I/O  (un)quantized LTP gains     */\r
-    SKP_int                 cbk_index[],            /* O    Codebook Index              */\r
-    SKP_int                 *periodicity_index,     /* O    Periodicity Index           */\r
-    const SKP_int32         W_Q18[],                /* I    Error Weights in Q18        */\r
-    SKP_int                 mu_Q8,                  /* I    Mu value (R/D tradeoff)     */\r
-    SKP_int                 lowComplexity           /* I    Flag for low complexity     */\r
-);\r
-\r
-/******************/\r
-/* NLSF Quantizer */\r
-/******************/\r
-\r
-/* Limit, stabilize, convert and quantize NLSFs.    */ \r
-void SKP_Silk_process_NLSFs_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,     /* I/O  encoder state                               */\r
-    SKP_Silk_encoder_control_FIX    *psEncCtrl, /* I/O  encoder control                             */\r
-    SKP_int                         *pNLSF_Q15  /* I/O  Normalized LSFs (quant out) (0 - (2^15-1))  */\r
-);\r
-\r
-/* NLSF vector encoder */\r
-void SKP_Silk_NLSF_MSVQ_encode_FIX(\r
-          SKP_int                   *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_Q6,                 /* 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
-/* Rate-Distortion calculations for multiple input data vectors */\r
-void SKP_Silk_NLSF_VQ_rate_distortion_FIX(\r
-    SKP_int32                       *pRD_Q20,           /* O    Rate-distortion values [psNLSF_CBS->nVectors*N] */\r
-    const SKP_Silk_NLSF_CBS         *psNLSF_CBS,        /* I    NLSF codebook stage struct                      */\r
-    const SKP_int                   *in_Q15,            /* I    Input vectors to be quantized                   */\r
-    const SKP_int                   *w_Q6,              /* I    Weight vector                                   */\r
-    const SKP_int32                 *rate_acc_Q5,       /* 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                   LPC_order           /* I    LPC order                                       */\r
-);\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_FIX(\r
-    SKP_int32                       *err_Q20,           /* O    Weighted quantization errors  [N*K]         */\r
-    const SKP_int                   *in_Q15,            /* I    Input vectors to be quantized [N*LPC_order] */\r
-    const SKP_int                   *w_Q6,              /* I    Weighting vectors             [N*LPC_order] */\r
-    const SKP_int16                 *pCB_Q15,           /* 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                   LPC_order           /* I    Number of LPCs                              */\r
-);\r
-\r
-/* Entropy constrained MATRIX-weighted VQ, for a single input data vector */\r
-void SKP_Silk_VQ_WMat_EC_FIX(\r
-    SKP_int                         *ind,               /* O    index of best codebook vector               */\r
-    SKP_int32                       *rate_dist_Q14,     /* O    best weighted quantization error + mu * rate*/\r
-    const SKP_int16                 *in_Q14,            /* I    input vector to be quantized                */\r
-    const SKP_int32                 *W_Q18,             /* I    weighting matrix                            */\r
-    const SKP_int16                 *cb_Q14,            /* I    codebook                                    */\r
-    const SKP_int16                 *cl_Q6,             /* I    code length for each codebook vector        */\r
-    const SKP_int                   mu_Q8,              /* I    tradeoff between weighted error and rate    */\r
-    SKP_int                         L                   /* I    number of vectors in codebook               */\r
-);\r
-\r
-/******************/\r
-/* Linear Algebra */\r
-/******************/\r
-\r
-/* Calculates correlation matrix X'*X */\r
-void SKP_Silk_corrMatrix_FIX(\r
-    const SKP_int16                 *x,         /* I    x vector [L + order - 1] used to form data matrix X */\r
-    const SKP_int                   L,          /* I    Length of vectors                                   */\r
-    const SKP_int                   order,      /* I    Max lag for correlation                             */\r
-    const SKP_int                   head_room,  /* I    Desired headroom                                    */\r
-    SKP_int32                       *XX,        /* O    Pointer to X'*X correlation matrix [ order x order ]*/\r
-    SKP_int                         *rshifts    /* I/O  Right shifts of correlations                        */\r
-);\r
-\r
-/* Calculates correlation vector X'*t */\r
-void SKP_Silk_corrVector_FIX(\r
-    const SKP_int16                 *x,         /* I    x vector [L + order - 1] used to form data matrix X */\r
-    const SKP_int16                 *t,         /* I    Target vector [L]                                   */\r
-    const SKP_int                   L,          /* I    Length of vectors                                   */\r
-    const SKP_int                   order,      /* I    Max lag for correlation                             */\r
-    SKP_int32                       *Xt,        /* O    Pointer to X'*t correlation vector [order]          */\r
-    const SKP_int                   rshifts     /* I    Right shifts of correlations                        */\r
-);\r
-\r
-/* Add noise to matrix diagonal */\r
-void SKP_Silk_regularize_correlations_FIX(\r
-    SKP_int32                       *XX,                /* I/O  Correlation matrices                        */\r
-    SKP_int32                       *xx,                /* I/O  Correlation values                          */\r
-    SKP_int32                       noise,              /* I    Noise to add                                */\r
-    SKP_int                         D                   /* I    Dimension of XX                             */\r
-);\r
-\r
-/* Solves Ax = b, assuming A is symmetric */\r
-void SKP_Silk_solve_LDL_FIX(\r
-    SKP_int32                       *A,                 /* I    Pointer to symetric square matrix A         */\r
-    SKP_int                         M,                  /* I    Size of matrix                              */\r
-    const SKP_int32                 *b,                 /* I    Pointer to b vector                         */\r
-    SKP_int32                       *x_Q16              /* O    Pointer to x solution vector                */\r
-);\r
-\r
-/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */\r
-SKP_int32 SKP_Silk_residual_energy16_covar_FIX(\r
-    const SKP_int16                 *c,                 /* I    Prediction vector                           */\r
-    const SKP_int32                 *wXX,               /* I    Correlation matrix                          */\r
-    const SKP_int32                 *wXx,               /* I    Correlation vector                          */\r
-    SKP_int32                       wxx,                /* I    Signal energy                               */\r
-    SKP_int                         D,                  /* I    Dimension                                   */\r
-    SKP_int                         cQ                  /* I    Q value for c vector 0 - 15                 */\r
-);\r
-\r
-/* Calculates residual energies of input subframes where all subframes have LPC_order   */\r
-/* of preceeding samples                                                                */\r
-void SKP_Silk_residual_energy_FIX(\r
-          SKP_int32 nrgs[ NB_SUBFR ],           /* O    Residual energy per subframe    */\r
-          SKP_int   nrgsQ[ NB_SUBFR ],          /* O    Q value per subframe            */\r
-    const SKP_int16 x[],                        /* I    Input signal                    */\r
-          SKP_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ],/* I    AR coefs for each frame half    */\r
-    const SKP_int32 gains[ NB_SUBFR ],          /* I    Quantization gains              */\r
-    const SKP_int   subfr_length,               /* I    Subframe length                 */\r
-    const SKP_int   LPC_order                   /* I    LPC order                       */\r
-);\r
-\r
-#ifndef FORCE_CPP_BUILD\r
-#ifdef __cplusplus\r
-}\r
-#endif /* __cplusplus */\r
-#endif /* FORCE_CPP_BUILD */\r
-#endif /* SKP_SILK_MAIN_FIX_H */\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_MAIN_FIX_H
+#define SKP_SILK_MAIN_FIX_H
+
+#include <stdlib.h>
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_structs_FIX.h"
+#include "SKP_Silk_main.h"
+#include "SKP_Silk_PLC.h"
+#define TIC(TAG_NAME)
+#define TOC(TAG_NAME)
+
+#ifndef FORCE_CPP_BUILD
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+#endif
+
+/*********************/
+/* Encoder Functions */
+/*********************/
+
+/* Initializes the Silk encoder state */
+SKP_int SKP_Silk_init_encoder_FIX(
+    SKP_Silk_encoder_state_FIX  *psEnc                  /* I/O  Pointer to Silk FIX encoder state       */
+);
+
+/* Control the Silk encoder */
+SKP_int SKP_Silk_control_encoder_FIX( 
+    SKP_Silk_encoder_state_FIX  *psEnc,                 /* I/O  Pointer to Silk encoder state           */
+    const SKP_int               PacketSize_ms,          /* I    Packet length (ms)                      */
+    const SKP_int32             TargetRate_bps,         /* I    Target max bitrate (bps)                */
+    const SKP_int               PacketLoss_perc,        /* I    Packet loss rate (in percent)           */
+    const SKP_int               DTX_enabled,            /* I    Enable / disable DTX                    */
+    const SKP_int               Complexity              /* I    Complexity (0->low; 1->medium; 2->high) */
+);
+
+/* Encoder main function */
+SKP_int SKP_Silk_encode_frame_FIX( 
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk FIX encoder state           */
+    SKP_uint8                       *pCode,             /* O    Pointer to payload                          */
+    SKP_int16                       *pnBytesOut,        /* I/O  Pointer to number of payload bytes;         */
+                                                        /*      input: max length; output: used             */
+    const SKP_int16                 *pIn                /* I    Pointer to input speech frame               */
+);
+
+/* Low BitRate Redundancy encoding functionality. Reuse all parameters but encode with lower bitrate */
+void SKP_Silk_LBRR_encode_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Pointer to Silk FIX encoder state           */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  Pointer to Silk FIX encoder control struct  */
+    SKP_uint8                       *pCode,         /* O    Pointer to payload                          */
+    SKP_int16                       *pnBytesOut,    /* I/O  Pointer to number of payload bytes          */
+    SKP_int16                       xfw[]           /* I    Input signal                                */
+);
+
+/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */
+void SKP_Silk_HP_variable_cutoff_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Encoder state                               */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  Encoder control                             */
+    SKP_int16                       *out,           /* O    high-pass filtered output signal            */
+    const SKP_int16                 *in             /* I    input signal                                */
+);
+
+/****************/
+/* Prefiltering */
+/****************/
+void SKP_Silk_prefilter_FIX(
+    SKP_Silk_encoder_state_FIX          *psEnc,         /* I/O  Encoder state                               */
+    const SKP_Silk_encoder_control_FIX  *psEncCtrl,     /* I    Encoder control                             */
+    SKP_int16                           xw[],           /* O    Weighted signal                             */
+    const SKP_int16                     x[]             /* I    Speech signal                               */
+);
+
+/**************************************************************/
+/* Compute noise shaping coefficients and initial gain values */
+/**************************************************************/
+void SKP_Silk_noise_shape_analysis_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Encoder state FIX                           */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  Encoder control FIX                         */
+    const SKP_int16                 *pitch_res,     /* I    LPC residual from pitch analysis            */
+    const SKP_int16                 *x              /* I    Input signal [ frame_length + la_shape ]    */
+);
+
+/* Autocorrelations for a warped frequency axis */
+void SKP_Silk_warped_autocorrelation_FIX(
+          SKP_int32                 *corr,              /* O    Result [order + 1]                      */
+          SKP_int                   *scale,             /* O    Scaling of the correlation vector       */
+    const SKP_int16                 *input,             /* I    Input data to correlate                 */
+    const SKP_int16                 warping_Q16,        /* I    Warping coefficient                     */
+    const SKP_int                   length,             /* I    Length of input                         */
+    const SKP_int                   order               /* I    Correlation order (even)                */
+);
+
+/* Processing of gains */
+void SKP_Silk_process_gains_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Encoder state                               */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl      /* I/O  Encoder control                             */
+);
+
+/* Control low bitrate redundancy usage */
+void SKP_Silk_LBRR_ctrl_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */
+    SKP_Silk_encoder_control        *psEncCtrlC     /* I/O  encoder control                             */
+);
+
+/* Calculation of LTP state scaling */
+void SKP_Silk_LTP_scale_ctrl_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl      /* I/O  encoder control                             */
+);
+
+/**********************************************/
+/* Prediction Analysis                        */
+/**********************************************/
+
+/* Find pitch lags */
+void SKP_Silk_find_pitch_lags_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  encoder control                             */
+    SKP_int16                       res[],          /* O    residual                                    */
+    const SKP_int16                 x[]             /* I    Speech signal                               */
+);
+
+void SKP_Silk_find_pred_coefs_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  encoder state                               */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  encoder control                             */
+    const SKP_int16                 res_pitch[]     /* I    Residual from pitch analysis                */
+);
+
+void SKP_Silk_find_LPC_FIX(
+    SKP_int             NLSF_Q15[],             /* O    NLSFs                                                                       */
+    SKP_int             *interpIndex,           /* O    NLSF interpolation index, only used for NLSF interpolation                  */
+    const SKP_int       prev_NLSFq_Q15[],       /* I    previous NLSFs, only used for NLSF interpolation                            */
+    const SKP_int       useInterpolatedLSFs,    /* I    Flag                                                                        */
+    const SKP_int       LPC_order,              /* I    LPC order                                                                   */
+    const SKP_int16     x[],                    /* I    Input signal                                                                */
+    const SKP_int       subfr_length            /* I    Input signal subframe length including preceeding samples                   */
+);
+
+void SKP_Silk_LTP_analysis_filter_FIX(
+    SKP_int16       *LTP_res,                           /* O:   LTP residual signal of length NB_SUBFR * ( pre_length + subfr_length )  */
+    const SKP_int16 *x,                                 /* I:   Pointer to input signal with at least max( pitchL ) preceeding samples  */
+    const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],/* I:   LTP_ORDER LTP coefficients for each NB_SUBFR subframe                   */
+    const SKP_int   pitchL[ NB_SUBFR ],                 /* I:   Pitch lag, one for each subframe                                        */
+    const SKP_int32 invGains_Q16[ NB_SUBFR ],           /* I:   Inverse quantization gains, one for each subframe                       */
+    const SKP_int   subfr_length,                       /* I:   Length of each subframe                                                 */
+    const SKP_int   pre_length                          /* I:   Length of the preceeding samples starting at &x[0] for each subframe    */
+);
+
+/* Finds LTP vector from correlations */
+void SKP_Silk_find_LTP_FIX(
+    SKP_int16           b_Q14[ NB_SUBFR * LTP_ORDER ],              /* O    LTP coefs                                                   */
+    SKP_int32           WLTP[ NB_SUBFR * LTP_ORDER * LTP_ORDER ],   /* O    Weight for LTP quantization                                 */
+    SKP_int             *LTPredCodGain_Q7,                          /* O    LTP coding gain                                             */
+    const SKP_int16     r_first[],                                  /* I    residual signal after LPC signal + state for first 10 ms    */
+    const SKP_int16     r_last[],                                   /* I    residual signal after LPC signal + state for last 10 ms     */
+    const SKP_int       lag[ NB_SUBFR ],                            /* I    LTP lags                                                    */
+    const SKP_int32     Wght_Q15[ NB_SUBFR ],                       /* I    weights                                                     */
+    const SKP_int       subfr_length,                               /* I    subframe length                                             */
+    const SKP_int       mem_offset,                                 /* I    number of samples in LTP memory                             */
+    SKP_int             corr_rshifts[ NB_SUBFR ]                    /* O    right shifts applied to correlations                        */
+);
+
+/* LTP tap quantizer */
+void SKP_Silk_quant_LTP_gains_FIX(
+    SKP_int16               B_Q14[],                /* I/O  (un)quantized LTP gains     */
+    SKP_int                 cbk_index[],            /* O    Codebook Index              */
+    SKP_int                 *periodicity_index,     /* O    Periodicity Index           */
+    const SKP_int32         W_Q18[],                /* I    Error Weights in Q18        */
+    SKP_int                 mu_Q8,                  /* I    Mu value (R/D tradeoff)     */
+    SKP_int                 lowComplexity           /* I    Flag for low complexity     */
+);
+
+/******************/
+/* NLSF Quantizer */
+/******************/
+
+/* Limit, stabilize, convert and quantize NLSFs.    */ 
+void SKP_Silk_process_NLSFs_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,     /* I/O  encoder state                               */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl, /* I/O  encoder control                             */
+    SKP_int                         *pNLSF_Q15  /* I/O  Normalized LSFs (quant out) (0 - (2^15-1))  */
+);
+
+/* NLSF vector encoder */
+void SKP_Silk_NLSF_MSVQ_encode_FIX(
+          SKP_int                   *NLSFIndices,           /* O    Codebook path vector [ CB_STAGES ]      */
+          SKP_int                   *pNLSF_Q15,             /* I/O  Quantized NLSF vector [ LPC_ORDER ]     */
+    const SKP_Silk_NLSF_CB_struct   *psNLSF_CB,             /* I    Codebook object                         */
+    const SKP_int                   *pNLSF_q_Q15_prev,      /* I    Prev. quantized NLSF vector [LPC_ORDER] */
+    const SKP_int                   *pW_Q6,                 /* I    NLSF weight vector [ LPC_ORDER ]        */
+    const SKP_int                   NLSF_mu_Q15,            /* I    Rate weight for the RD optimization     */
+    const SKP_int                   NLSF_mu_fluc_red_Q16,   /* I    Fluctuation reduction error weight      */
+    const SKP_int                   NLSF_MSVQ_Survivors,    /* I    Max survivors from each stage           */
+    const SKP_int                   LPC_order,              /* I    LPC order                               */
+    const SKP_int                   deactivate_fluc_red     /* I    Deactivate fluctuation reduction        */
+);
+
+/* Rate-Distortion calculations for multiple input data vectors */
+void SKP_Silk_NLSF_VQ_rate_distortion_FIX(
+    SKP_int32                       *pRD_Q20,           /* O    Rate-distortion values [psNLSF_CBS->nVectors*N] */
+    const SKP_Silk_NLSF_CBS         *psNLSF_CBS,        /* I    NLSF codebook stage struct                      */
+    const SKP_int                   *in_Q15,            /* I    Input vectors to be quantized                   */
+    const SKP_int                   *w_Q6,              /* I    Weight vector                                   */
+    const SKP_int32                 *rate_acc_Q5,       /* I    Accumulated rates from previous stage           */
+    const SKP_int                   mu_Q15,             /* I    Weight between weighted error and rate          */
+    const SKP_int                   N,                  /* I    Number of input vectors to be quantized         */
+    const SKP_int                   LPC_order           /* I    LPC order                                       */
+);
+
+/* Compute weighted quantization errors for an LPC_order element input vector, over one codebook stage */
+void SKP_Silk_NLSF_VQ_sum_error_FIX(
+    SKP_int32                       *err_Q20,           /* O    Weighted quantization errors  [N*K]         */
+    const SKP_int                   *in_Q15,            /* I    Input vectors to be quantized [N*LPC_order] */
+    const SKP_int                   *w_Q6,              /* I    Weighting vectors             [N*LPC_order] */
+    const SKP_int16                 *pCB_Q15,           /* I    Codebook vectors              [K*LPC_order] */
+    const SKP_int                   N,                  /* I    Number of input vectors                     */
+    const SKP_int                   K,                  /* I    Number of codebook vectors                  */
+    const SKP_int                   LPC_order           /* I    Number of LPCs                              */
+);
+
+/* Entropy constrained MATRIX-weighted VQ, for a single input data vector */
+void SKP_Silk_VQ_WMat_EC_FIX(
+    SKP_int                         *ind,               /* O    index of best codebook vector               */
+    SKP_int32                       *rate_dist_Q14,     /* O    best weighted quantization error + mu * rate*/
+    const SKP_int16                 *in_Q14,            /* I    input vector to be quantized                */
+    const SKP_int32                 *W_Q18,             /* I    weighting matrix                            */
+    const SKP_int16                 *cb_Q14,            /* I    codebook                                    */
+    const SKP_int16                 *cl_Q6,             /* I    code length for each codebook vector        */
+    const SKP_int                   mu_Q8,              /* I    tradeoff between weighted error and rate    */
+    SKP_int                         L                   /* I    number of vectors in codebook               */
+);
+
+/******************/
+/* Linear Algebra */
+/******************/
+
+/* Calculates correlation matrix X'*X */
+void SKP_Silk_corrMatrix_FIX(
+    const SKP_int16                 *x,         /* I    x vector [L + order - 1] used to form data matrix X */
+    const SKP_int                   L,          /* I    Length of vectors                                   */
+    const SKP_int                   order,      /* I    Max lag for correlation                             */
+    const SKP_int                   head_room,  /* I    Desired headroom                                    */
+    SKP_int32                       *XX,        /* O    Pointer to X'*X correlation matrix [ order x order ]*/
+    SKP_int                         *rshifts    /* I/O  Right shifts of correlations                        */
+);
+
+/* Calculates correlation vector X'*t */
+void SKP_Silk_corrVector_FIX(
+    const SKP_int16                 *x,         /* I    x vector [L + order - 1] used to form data matrix X */
+    const SKP_int16                 *t,         /* I    Target vector [L]                                   */
+    const SKP_int                   L,          /* I    Length of vectors                                   */
+    const SKP_int                   order,      /* I    Max lag for correlation                             */
+    SKP_int32                       *Xt,        /* O    Pointer to X'*t correlation vector [order]          */
+    const SKP_int                   rshifts     /* I    Right shifts of correlations                        */
+);
+
+/* Add noise to matrix diagonal */
+void SKP_Silk_regularize_correlations_FIX(
+    SKP_int32                       *XX,                /* I/O  Correlation matrices                        */
+    SKP_int32                       *xx,                /* I/O  Correlation values                          */
+    SKP_int32                       noise,              /* I    Noise to add                                */
+    SKP_int                         D                   /* I    Dimension of XX                             */
+);
+
+/* Solves Ax = b, assuming A is symmetric */
+void SKP_Silk_solve_LDL_FIX(
+    SKP_int32                       *A,                 /* I    Pointer to symetric square matrix A         */
+    SKP_int                         M,                  /* I    Size of matrix                              */
+    const SKP_int32                 *b,                 /* I    Pointer to b vector                         */
+    SKP_int32                       *x_Q16              /* O    Pointer to x solution vector                */
+);
+
+/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
+SKP_int32 SKP_Silk_residual_energy16_covar_FIX(
+    const SKP_int16                 *c,                 /* I    Prediction vector                           */
+    const SKP_int32                 *wXX,               /* I    Correlation matrix                          */
+    const SKP_int32                 *wXx,               /* I    Correlation vector                          */
+    SKP_int32                       wxx,                /* I    Signal energy                               */
+    SKP_int                         D,                  /* I    Dimension                                   */
+    SKP_int                         cQ                  /* I    Q value for c vector 0 - 15                 */
+);
+
+/* Calculates residual energies of input subframes where all subframes have LPC_order   */
+/* of preceeding samples                                                                */
+void SKP_Silk_residual_energy_FIX(
+          SKP_int32 nrgs[ NB_SUBFR ],           /* O    Residual energy per subframe    */
+          SKP_int   nrgsQ[ NB_SUBFR ],          /* O    Q value per subframe            */
+    const SKP_int16 x[],                        /* I    Input signal                    */
+          SKP_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ],/* I    AR coefs for each frame half    */
+    const SKP_int32 gains[ NB_SUBFR ],          /* I    Quantization gains              */
+    const SKP_int   subfr_length,               /* I    Subframe length                 */
+    const SKP_int   LPC_order                   /* I    LPC order                       */
+);
+
+#ifndef FORCE_CPP_BUILD
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* FORCE_CPP_BUILD */
+#endif /* SKP_SILK_MAIN_FIX_H */
index c7aa416afdebecc7f9c4bc31a18a12bbb7d5ce4c..76df7cd901f6a8343f9640d9275576948a2802a1 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-#include "SKP_Silk_tuning_parameters.h"\r
-\r
-/* Compute gain to make warped filter coefficients have a zero mean log frequency response on a     */\r
-/* non-warped frequency scale. (So that it can be implemented with a minimum-phase monic filter.)   */\r
-SKP_INLINE SKP_int32 warped_gain( // gain in Q16\r
-    const SKP_int32     *coefs_Q24, \r
-    SKP_int             lambda_Q16, \r
-    SKP_int             order \r
-) {\r
-    SKP_int   i;\r
-    SKP_int32 gain_Q24;\r
-\r
-    lambda_Q16 = -lambda_Q16;\r
-    gain_Q24 = coefs_Q24[ order - 1 ];\r
-    for( i = order - 2; i >= 0; i-- ) {\r
-        gain_Q24 = SKP_SMLAWB( coefs_Q24[ i ], gain_Q24, lambda_Q16 );\r
-    }\r
-    gain_Q24  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), gain_Q24, -lambda_Q16 );\r
-    return SKP_INVERSE32_varQ( gain_Q24, 40 );\r
-}\r
-\r
-/* Convert warped filter coefficients to monic pseudo-warped coefficients and limit maximum     */\r
-/* amplitude of monic warped coefficients by using bandwidth expansion on the true coefficients */\r
-SKP_INLINE void limit_warped_coefs( \r
-    SKP_int32           *coefs_syn_Q24,\r
-    SKP_int32           *coefs_ana_Q24,\r
-    SKP_int             lambda_Q16,\r
-    SKP_int32           limit_Q24,\r
-    SKP_int             order\r
-) {\r
-    SKP_int   i, iter, ind = 0;\r
-    SKP_int32 tmp, maxabs_Q24, chirp_Q16, gain_syn_Q16, gain_ana_Q16;\r
-    SKP_int32 nom_Q16, den_Q24;\r
-\r
-    /* Convert to monic coefficients */\r
-    lambda_Q16 = -lambda_Q16;\r
-    for( i = order - 1; i > 0; i-- ) {\r
-        coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 );\r
-        coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 );\r
-    }\r
-    lambda_Q16 = -lambda_Q16;\r
-    nom_Q16  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 16 ), -lambda_Q16,        lambda_Q16 );\r
-    den_Q24  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_syn_Q24[ 0 ], lambda_Q16 );\r
-    gain_syn_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );\r
-    den_Q24  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_ana_Q24[ 0 ], lambda_Q16 );\r
-    gain_ana_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );\r
-    for( i = 0; i < order; i++ ) {\r
-        coefs_syn_Q24[ i ] = SKP_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] );\r
-        coefs_ana_Q24[ i ] = SKP_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] );\r
-    }\r
-\r
-    for( iter = 0; iter < 10; iter++ ) {\r
-        /* Find maximum absolute value */\r
-        maxabs_Q24 = -1;\r
-        for( i = 0; i < order; i++ ) {\r
-            tmp = SKP_max( SKP_abs_int32( coefs_syn_Q24[ i ] ), SKP_abs_int32( coefs_ana_Q24[ i ] ) );\r
-            if( tmp > maxabs_Q24 ) {\r
-                maxabs_Q24 = tmp;\r
-                ind = i;\r
-            }\r
-        }\r
-        if( maxabs_Q24 <= limit_Q24 ) {\r
-            /* Coefficients are within range - done */\r
-            return;\r
-        }\r
-\r
-        /* Convert back to true warped coefficients */\r
-        for( i = 1; i < order; i++ ) {\r
-            coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 );\r
-            coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 );\r
-        }\r
-        gain_syn_Q16 = SKP_INVERSE32_varQ( gain_syn_Q16, 32 );\r
-        gain_ana_Q16 = SKP_INVERSE32_varQ( gain_ana_Q16, 32 );\r
-        for( i = 0; i < order; i++ ) {\r
-            coefs_syn_Q24[ i ] = SKP_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] );\r
-            coefs_ana_Q24[ i ] = SKP_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] );\r
-        }\r
-\r
-        /* Apply bandwidth expansion */\r
-        chirp_Q16 = SKP_FIX_CONST( 0.99, 16 ) - SKP_DIV32_varQ(\r
-            SKP_SMULWB( maxabs_Q24 - limit_Q24, SKP_SMLABB( SKP_FIX_CONST( 0.8, 10 ), SKP_FIX_CONST( 0.1, 10 ), iter ) ), \r
-            SKP_MUL( maxabs_Q24, ind + 1 ), 22 );\r
-        SKP_Silk_bwexpander_32( coefs_syn_Q24, order, chirp_Q16 );\r
-        SKP_Silk_bwexpander_32( coefs_ana_Q24, order, chirp_Q16 );\r
-\r
-        /* Convert to monic warped coefficients */\r
-        lambda_Q16 = -lambda_Q16;\r
-        for( i = order - 1; i > 0; i-- ) {\r
-            coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 );\r
-            coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 );\r
-        }\r
-        lambda_Q16 = -lambda_Q16;\r
-        nom_Q16  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 16 ), -lambda_Q16,        lambda_Q16 );\r
-        den_Q24  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_syn_Q24[ 0 ], lambda_Q16 );\r
-        gain_syn_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );\r
-        den_Q24  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_ana_Q24[ 0 ], lambda_Q16 );\r
-        gain_ana_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );\r
-        for( i = 0; i < order; i++ ) {\r
-            coefs_syn_Q24[ i ] = SKP_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] );\r
-            coefs_ana_Q24[ i ] = SKP_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] );\r
-        }\r
-    }\r
-       SKP_assert( 0 );\r
-}\r
-\r
-/**************************************************************/\r
-/* Compute noise shaping coefficients and initial gain values */\r
-/**************************************************************/\r
-void SKP_Silk_noise_shape_analysis_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
-    const SKP_int16                 *pitch_res,     /* I    LPC residual from pitch analysis            */\r
-    const SKP_int16                 *x              /* I    Input signal [ frame_length + la_shape ]    */\r
-)\r
-{\r
-    SKP_Silk_shape_state_FIX *psShapeSt = &psEnc->sShape;\r
-    SKP_int     k, i, nSamples, Qnrg, b_Q14, warping_Q16, scale = 0;\r
-    SKP_int32   SNR_adj_dB_Q7, HarmBoost_Q16, HarmShapeGain_Q16, Tilt_Q16, tmp32;\r
-    SKP_int32   nrg, pre_nrg_Q30, log_energy_Q7, log_energy_prev_Q7, energy_variation_Q7;\r
-    SKP_int32   delta_Q16, BWExp1_Q16, BWExp2_Q16, gain_mult_Q16, gain_add_Q16, strength_Q16, b_Q8;\r
-    SKP_int32   auto_corr[     MAX_SHAPE_LPC_ORDER + 1 ];\r
-    SKP_int32   refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ];\r
-    SKP_int32   AR1_Q24[       MAX_SHAPE_LPC_ORDER ];\r
-    SKP_int32   AR2_Q24[       MAX_SHAPE_LPC_ORDER ];\r
-    SKP_int16   x_windowed[    SHAPE_LPC_WIN_MAX ];\r
-    const SKP_int16 *x_ptr, *pitch_res_ptr;\r
-\r
-    SKP_int32   sqrt_nrg[ NB_SUBFR ], Qnrg_vec[ NB_SUBFR ];\r
-\r
-    /* Point to start of first LPC analysis block */\r
-    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_SMULWB( SKP_LSHIFT( ( SKP_int32 )psEnc->BufferedInChannel_ms, 7 ), \r
-        SKP_FIX_CONST( 0.05, 16 ) );\r
-\r
-    /* Reduce SNR_dB if inband FEC used */\r
-    if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) ) {\r
-        psEncCtrl->current_SNR_dB_Q7 -= SKP_RSHIFT( psEnc->inBandFEC_SNR_comp_Q8, 1 );\r
-    }\r
-\r
-    /****************/\r
-    /* GAIN CONTROL */\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 )psEncCtrl->input_quality_bands_Q15[ 0 ] \r
-        + psEncCtrl->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
-        SKP_FIX_CONST( 18.0, 7 ), 4 ) ), 1 );\r
-\r
-    /* Reduce coding SNR during low speech activity */\r
-    b_Q8 = SKP_FIX_CONST( 1.0, 8 ) - psEnc->speech_activity_Q8;\r
-    b_Q8 = SKP_SMULWB( SKP_LSHIFT( b_Q8, 8 ), b_Q8 );\r
-    SNR_adj_dB_Q7 = SKP_SMLAWB( psEncCtrl->current_SNR_dB_Q7,\r
-        SKP_SMULBB( SKP_FIX_CONST( -BG_SNR_DECR_dB, 7 ) >> ( 4 + 1 ), b_Q8 ),                                       // Q11\r
-        SKP_SMULWB( SKP_FIX_CONST( 1.0, 14 ) + psEncCtrl->input_quality_Q14, psEncCtrl->coding_quality_Q14 ) );     // Q12\r
-\r
-    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {\r
-        /* Reduce gains for periodic signals */\r
-        SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, SKP_FIX_CONST( HARM_SNR_INCR_dB, 8 ), psEnc->LTPCorr_Q15 );\r
-    } 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_FIX_CONST( 1.0, 14 ) - psEncCtrl->input_quality_Q14 );\r
-    }\r
-\r
-    /*************************/\r
-    /* SPARSENESS PROCESSING */\r
-    /*************************/\r
-    /* Set quantizer offset */\r
-    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {\r
-        /* Initally set to 0; may be overruled in process_gains(..) */\r
-        psEncCtrl->sCmn.QuantOffsetType = 0;\r
-        psEncCtrl->sparseness_Q8 = 0;\r
-    } else {\r
-        /* Sparseness measure, based on relative fluctuations of energy per 2 milliseconds */\r
-        nSamples = SKP_LSHIFT( psEnc->sCmn.fs_kHz, 1 );\r
-        energy_variation_Q7 = 0;\r
-        log_energy_prev_Q7  = 0;\r
-        pitch_res_ptr = pitch_res;\r
-        for( k = 0; k < FRAME_LENGTH_MS / 2; k++ ) {    \r
-            SKP_Silk_sum_sqr_shift( &nrg, &scale, pitch_res_ptr, nSamples );\r
-            nrg += SKP_RSHIFT( nSamples, scale );           // Q(-scale)\r
-            \r
-            log_energy_Q7 = SKP_Silk_lin2log( nrg );\r
-            if( k > 0 ) {\r
-                energy_variation_Q7 += SKP_abs( log_energy_Q7 - log_energy_prev_Q7 );\r
-            }\r
-            log_energy_prev_Q7 = log_energy_Q7;\r
-            pitch_res_ptr += nSamples;\r
-        }\r
-\r
-        psEncCtrl->sparseness_Q8 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_SMULWB( energy_variation_Q7 - \r
-            SKP_FIX_CONST( 5.0, 7 ), SKP_FIX_CONST( 0.1, 16 ) ) ), 7 );\r
-\r
-        /* Set quantization offset depending on sparseness measure */\r
-        if( psEncCtrl->sparseness_Q8 > SKP_FIX_CONST( SPARSENESS_THRESHOLD_QNT_OFFSET, 8 ) ) {\r
-            psEncCtrl->sCmn.QuantOffsetType = 0;\r
-        } else {\r
-            psEncCtrl->sCmn.QuantOffsetType = 1;\r
-        }\r
-        \r
-        /* Increase coding SNR for sparse signals */\r
-        SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, SKP_FIX_CONST( SPARSE_SNR_INCR_dB, 15 ), psEncCtrl->sparseness_Q8 - SKP_FIX_CONST( 0.5, 8 ) );\r
-    }\r
-\r
-    /*******************************/\r
-    /* Control bandwidth expansion */\r
-    /*******************************/\r
-    /* More BWE for signals with high prediction gain */\r
-    strength_Q16 = SKP_SMULWB( psEncCtrl->predGain_Q16, SKP_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) );\r
-    BWExp1_Q16 = BWExp2_Q16 = SKP_DIV32_varQ( SKP_FIX_CONST( BANDWIDTH_EXPANSION, 16 ), \r
-        SKP_SMLAWW( SKP_FIX_CONST( 1.0, 16 ), strength_Q16, strength_Q16 ), 16 );\r
-    delta_Q16  = SKP_SMULWB( SKP_FIX_CONST( 1.0, 16 ) - SKP_SMULBB( 3, psEncCtrl->coding_quality_Q14 ), \r
-        SKP_FIX_CONST( LOW_RATE_BANDWIDTH_EXPANSION_DELTA, 16 ) );\r
-    BWExp1_Q16 = SKP_SUB32( BWExp1_Q16, delta_Q16 );\r
-    BWExp2_Q16 = SKP_ADD32( BWExp2_Q16, delta_Q16 );\r
-    /* BWExp1 will be applied after BWExp2, so make it relative */\r
-    BWExp1_Q16 = SKP_DIV32_16( SKP_LSHIFT( BWExp1_Q16, 14 ), SKP_RSHIFT( BWExp2_Q16, 2 ) );\r
-\r
-    if( psEnc->sCmn.warping_Q16 > 0 ) {\r
-        /* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */\r
-        warping_Q16 = SKP_SMLAWB( psEnc->sCmn.warping_Q16, psEncCtrl->coding_quality_Q14, SKP_FIX_CONST( 0.01, 18 ) );\r
-    } else {\r
-        warping_Q16 = 0;\r
-    }\r
-\r
-    /********************************************/\r
-    /* Compute noise shaping AR coefs and gains */\r
-    /********************************************/\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        /* Apply window: sine slope followed by flat part followed by cosine slope */\r
-        SKP_int shift, slope_part, flat_part;\r
-        flat_part = psEnc->sCmn.fs_kHz * 5;\r
-        slope_part = SKP_RSHIFT( psEnc->sCmn.shapeWinLength - flat_part, 1 );\r
-\r
-        SKP_Silk_apply_sine_window_new( x_windowed, x_ptr, 1, slope_part );\r
-        shift = slope_part;\r
-        SKP_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(SKP_int16) );\r
-        shift += flat_part;\r
-        SKP_Silk_apply_sine_window_new( x_windowed + shift, x_ptr + shift, 2, slope_part );\r
-        \r
-        /* Update pointer: next LPC analysis block */\r
-        x_ptr += psEnc->sCmn.subfr_length;\r
-\r
-        if( psEnc->sCmn.warping_Q16 > 0 ) {\r
-            /* Calculate warped auto correlation */\r
-            SKP_Silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, warping_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder ); \r
-        } else {\r
-            /* Calculate regular auto correlation */\r
-            SKP_Silk_autocorr( auto_corr, &scale, x_windowed, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder + 1 );\r
-        }\r
-\r
-        /* Add white noise, as a fraction of energy */\r
-        auto_corr[0] = SKP_ADD32( auto_corr[0], SKP_max_32( SKP_SMULWB( SKP_RSHIFT( auto_corr[ 0 ], 4 ), \r
-            SKP_FIX_CONST( SHAPE_WHITE_NOISE_FRACTION, 20 ) ), 1 ) ); \r
-\r
-        /* Calculate the reflection coefficients using schur */\r
-        nrg = SKP_Silk_schur64( refl_coef_Q16, auto_corr, psEnc->sCmn.shapingLPCOrder );\r
-        SKP_assert( nrg >= 0 );\r
-\r
-        /* Convert reflection coefficients to prediction coefficients */\r
-        SKP_Silk_k2a_Q16( AR2_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder );\r
-\r
-        Qnrg = -scale;          // range: -12...30\r
-        SKP_assert( Qnrg >= -12 );\r
-        SKP_assert( Qnrg <=  30 );\r
-\r
-        /* Make sure that Qnrg is an even number */\r
-        if( Qnrg & 1 ) {\r
-            Qnrg -= 1;\r
-            nrg >>= 1;\r
-        }\r
-\r
-        tmp32 = SKP_Silk_SQRT_APPROX( nrg );\r
-        Qnrg >>= 1;             // range: -6...15\r
-\r
-        sqrt_nrg[ k ] = tmp32;\r
-        Qnrg_vec[ k ] = Qnrg;\r
-\r
-        psEncCtrl->Gains_Q16[ k ] = SKP_LSHIFT_SAT32( tmp32, 16 - Qnrg );\r
-\r
-        if( psEnc->sCmn.warping_Q16 > 0 ) {\r
-            /* Adjust gain for warping */\r
-            gain_mult_Q16 = warped_gain( AR2_Q24, warping_Q16, psEnc->sCmn.shapingLPCOrder );\r
-            SKP_assert( psEncCtrl->Gains_Q16[ k ] >= 0 );\r
-            psEncCtrl->Gains_Q16[ k ] = SKP_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 );\r
-            if( psEncCtrl->Gains_Q16[ k ] < 0 ) {\r
-                psEncCtrl->Gains_Q16[ k ] = SKP_int32_MAX;\r
-            }\r
-        }\r
-\r
-        /* Bandwidth expansion for synthesis filter shaping */\r
-        SKP_Silk_bwexpander_32( AR2_Q24, psEnc->sCmn.shapingLPCOrder, BWExp2_Q16 );\r
-\r
-        /* Compute noise shaping filter coefficients */\r
-        SKP_memcpy( AR1_Q24, AR2_Q24, psEnc->sCmn.shapingLPCOrder * sizeof( SKP_int32 ) );\r
-\r
-        /* Bandwidth expansion for analysis filter shaping */\r
-        SKP_assert( BWExp1_Q16 <= SKP_FIX_CONST( 1.0, 16 ) );\r
-        SKP_Silk_bwexpander_32( AR1_Q24, psEnc->sCmn.shapingLPCOrder, BWExp1_Q16 );\r
-\r
-        /* Ratio of prediction gains, in energy domain */\r
-        SKP_Silk_LPC_inverse_pred_gain_Q24( &pre_nrg_Q30, AR2_Q24, psEnc->sCmn.shapingLPCOrder );\r
-        SKP_Silk_LPC_inverse_pred_gain_Q24( &nrg,         AR1_Q24, psEnc->sCmn.shapingLPCOrder );\r
-\r
-        //psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ) = 0.3f + 0.7f * pre_nrg / nrg;\r
-        pre_nrg_Q30 = SKP_LSHIFT32( SKP_SMULWB( pre_nrg_Q30, SKP_FIX_CONST( 0.7, 15 ) ), 1 );\r
-        psEncCtrl->GainsPre_Q14[ k ] = ( SKP_int ) SKP_FIX_CONST( 0.3, 14 ) + SKP_DIV32_varQ( pre_nrg_Q30, nrg, 14 );\r
-\r
-        /* Convert to monic warped prediction coefficients and limit absolute values */\r
-        limit_warped_coefs( AR2_Q24, AR1_Q24, warping_Q16, SKP_FIX_CONST( 3.999, 24 ), psEnc->sCmn.shapingLPCOrder );\r
-\r
-        /* Convert from Q24 to Q13 and store in int16 */\r
-        for( i = 0; i < psEnc->sCmn.shapingLPCOrder; i++ ) {\r
-            psEncCtrl->AR1_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( AR1_Q24[ i ], 11 ) );\r
-            psEncCtrl->AR2_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( AR2_Q24[ i ], 11 ) );\r
-        }\r
-    }\r
-\r
-    /*****************/\r
-    /* Gain tweaking */\r
-    /*****************/\r
-    /* Increase gains during low speech activity and put lower limit on gains */\r
-    gain_mult_Q16 = SKP_Silk_log2lin( -SKP_SMLAWB( -SKP_FIX_CONST( 16.0, 7 ), SNR_adj_dB_Q7,                            SKP_FIX_CONST( 0.16, 16 ) ) );\r
-    gain_add_Q16  = SKP_Silk_log2lin(  SKP_SMLAWB(  SKP_FIX_CONST( 16.0, 7 ), SKP_FIX_CONST( NOISE_FLOOR_dB, 7 ),       SKP_FIX_CONST( 0.16, 16 ) ) );\r
-    tmp32         = SKP_Silk_log2lin(  SKP_SMLAWB(  SKP_FIX_CONST( 16.0, 7 ), SKP_FIX_CONST( RELATIVE_MIN_GAIN_dB, 7 ), SKP_FIX_CONST( 0.16, 16 ) ) );\r
-    tmp32 = SKP_SMULWW( psEnc->avgGain_Q16, tmp32 );\r
-    gain_add_Q16 = SKP_ADD_SAT32( gain_add_Q16, tmp32 );\r
-    SKP_assert( gain_mult_Q16 >= 0 );\r
-\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        psEncCtrl->Gains_Q16[ k ] = SKP_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 );\r
-        if( psEncCtrl->Gains_Q16[ k ] < 0 ) {\r
-            psEncCtrl->Gains_Q16[ k ] = SKP_int32_MAX;\r
-        }\r
-    }\r
-\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        psEncCtrl->Gains_Q16[ k ] = SKP_ADD_POS_SAT32( psEncCtrl->Gains_Q16[ k ], gain_add_Q16 );\r
-        psEnc->avgGain_Q16 = SKP_ADD_SAT32( \r
-            psEnc->avgGain_Q16, \r
-            SKP_SMULWB(\r
-                psEncCtrl->Gains_Q16[ k ] - psEnc->avgGain_Q16, \r
-                SKP_RSHIFT_ROUND( SKP_SMULBB( psEnc->speech_activity_Q8, SKP_FIX_CONST( GAIN_SMOOTHING_COEF, 10 ) ), 2 ) \r
-            ) );\r
-    }\r
-\r
-    /************************************************/\r
-    /* Decrease level during fricatives (de-essing) */\r
-    /************************************************/\r
-    gain_mult_Q16 = SKP_FIX_CONST( 1.0, 16 ) + SKP_RSHIFT_ROUND( SKP_MLA( SKP_FIX_CONST( INPUT_TILT, 26 ), \r
-        psEncCtrl->coding_quality_Q14, SKP_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) ), 10 );\r
-\r
-    if( psEncCtrl->input_tilt_Q15 <= 0 && psEncCtrl->sCmn.sigtype == SIG_TYPE_UNVOICED ) {\r
-        if( psEnc->sCmn.fs_kHz == 24 ) {\r
-            SKP_int32 essStrength_Q15 = SKP_SMULWW( -psEncCtrl->input_tilt_Q15, \r
-                SKP_SMULBB( psEnc->speech_activity_Q8, SKP_FIX_CONST( 1.0, 8 ) - psEncCtrl->sparseness_Q8 ) );\r
-            tmp32 = SKP_Silk_log2lin( SKP_FIX_CONST( 16.0, 7 ) - SKP_SMULWB( essStrength_Q15, \r
-                SKP_SMULWB( SKP_FIX_CONST( DE_ESSER_COEF_SWB_dB, 7 ), SKP_FIX_CONST( 0.16, 17 ) ) ) );\r
-            gain_mult_Q16 = SKP_SMULWW( gain_mult_Q16, tmp32 );\r
-        } else if( psEnc->sCmn.fs_kHz == 16 ) {\r
-            SKP_int32 essStrength_Q15 = SKP_SMULWW(-psEncCtrl->input_tilt_Q15, \r
-                SKP_SMULBB( psEnc->speech_activity_Q8, SKP_FIX_CONST( 1.0, 8 ) - psEncCtrl->sparseness_Q8 ));\r
-            tmp32 = SKP_Silk_log2lin( SKP_FIX_CONST( 16.0, 7 ) - SKP_SMULWB( essStrength_Q15, \r
-                SKP_SMULWB( SKP_FIX_CONST( DE_ESSER_COEF_WB_dB, 7 ), SKP_FIX_CONST( 0.16, 17 ) ) ) );\r
-            gain_mult_Q16 = SKP_SMULWW( gain_mult_Q16, tmp32 );\r
-        } else {\r
-            SKP_assert( psEnc->sCmn.fs_kHz == 12 || psEnc->sCmn.fs_kHz == 8 );\r
-        }\r
-    }\r
-\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        psEncCtrl->GainsPre_Q14[ k ] = SKP_SMULWB( gain_mult_Q16, psEncCtrl->GainsPre_Q14[ k ] );\r
-    }\r
-\r
-    /************************************************/\r
-    /* Control low-frequency shaping and noise tilt */\r
-    /************************************************/\r
-    /* Less low frequency shaping for noisy inputs */\r
-    strength_Q16 = SKP_MUL( SKP_FIX_CONST( LOW_FREQ_SHAPING, 0 ), SKP_FIX_CONST( 1.0, 16 ) + \r
-        SKP_SMULBB( SKP_FIX_CONST( LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 1 ), psEncCtrl->input_quality_bands_Q15[ 0 ] - SKP_FIX_CONST( 1.0, 15 ) ) );\r
-    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {\r
-        /* Reduce low frequencies quantization noise for periodic signals, depending on pitch lag */\r
-        /*f = 400; freqz([1, -0.98 + 2e-4 * f], [1, -0.97 + 7e-4 * f], 2^12, Fs); axis([0, 1000, -10, 1])*/\r
-        SKP_int fs_kHz_inv = SKP_DIV32_16( SKP_FIX_CONST( 0.2, 14 ), psEnc->sCmn.fs_kHz );\r
-        for( k = 0; k < NB_SUBFR; k++ ) {\r
-            b_Q14 = fs_kHz_inv + SKP_DIV32_16( SKP_FIX_CONST( 3.0, 14 ), psEncCtrl->sCmn.pitchL[ k ] ); \r
-            /* Pack two coefficients in one int32 */\r
-            psEncCtrl->LF_shp_Q14[ k ]  = SKP_LSHIFT( SKP_FIX_CONST( 1.0, 14 ) - b_Q14 - SKP_SMULWB( strength_Q16, b_Q14 ), 16 );\r
-            psEncCtrl->LF_shp_Q14[ k ] |= (SKP_uint16)( b_Q14 - SKP_FIX_CONST( 1.0, 14 ) );\r
-        }\r
-        SKP_assert( SKP_FIX_CONST( HARM_HP_NOISE_COEF, 24 ) < SKP_FIX_CONST( 0.5, 24 ) ); // Guarantees that second argument to SMULWB() is within range of an SKP_int16\r
-        Tilt_Q16 = - SKP_FIX_CONST( HP_NOISE_COEF, 16 ) - \r
-            SKP_SMULWB( SKP_FIX_CONST( 1.0, 16 ) - SKP_FIX_CONST( HP_NOISE_COEF, 16 ), \r
-                SKP_SMULWB( SKP_FIX_CONST( HARM_HP_NOISE_COEF, 24 ), psEnc->speech_activity_Q8 ) );\r
-    } else {\r
-        b_Q14 = SKP_DIV32_16( 21299, psEnc->sCmn.fs_kHz ); // 1.3_Q0 = 21299_Q14\r
-        /* Pack two coefficients in one int32 */\r
-        psEncCtrl->LF_shp_Q14[ 0 ]  = SKP_LSHIFT( SKP_FIX_CONST( 1.0, 14 ) - b_Q14 - \r
-            SKP_SMULWB( strength_Q16, SKP_SMULWB( SKP_FIX_CONST( 0.6, 16 ), b_Q14 ) ), 16 );\r
-        psEncCtrl->LF_shp_Q14[ 0 ] |= (SKP_uint16)( b_Q14 - SKP_FIX_CONST( 1.0, 14 ) );\r
-        for( k = 1; k < NB_SUBFR; k++ ) {\r
-            psEncCtrl->LF_shp_Q14[ k ] = psEncCtrl->LF_shp_Q14[ 0 ];\r
-        }\r
-        Tilt_Q16 = -SKP_FIX_CONST( HP_NOISE_COEF, 16 );\r
-    }\r
-\r
-    /****************************/\r
-    /* HARMONIC SHAPING CONTROL */\r
-    /****************************/\r
-    /* Control boosting of harmonic frequencies */\r
-    HarmBoost_Q16 = SKP_SMULWB( SKP_SMULWB( SKP_FIX_CONST( 1.0, 17 ) - SKP_LSHIFT( psEncCtrl->coding_quality_Q14, 3 ), \r
-        psEnc->LTPCorr_Q15 ), SKP_FIX_CONST( LOW_RATE_HARMONIC_BOOST, 16 ) );\r
-\r
-    /* More harmonic boost for noisy input signals */\r
-    HarmBoost_Q16 = SKP_SMLAWB( HarmBoost_Q16, \r
-        SKP_FIX_CONST( 1.0, 16 ) - SKP_LSHIFT( psEncCtrl->input_quality_Q14, 2 ), SKP_FIX_CONST( LOW_INPUT_QUALITY_HARMONIC_BOOST, 16 ) );\r
-\r
-    if( USE_HARM_SHAPING && psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {\r
-        /* More harmonic noise shaping for high bitrates or noisy input */\r
-        HarmShapeGain_Q16 = SKP_SMLAWB( SKP_FIX_CONST( HARMONIC_SHAPING, 16 ), \r
-                SKP_FIX_CONST( 1.0, 16 ) - SKP_SMULWB( SKP_FIX_CONST( 1.0, 18 ) - SKP_LSHIFT( psEncCtrl->coding_quality_Q14, 4 ),\r
-                psEncCtrl->input_quality_Q14 ), SKP_FIX_CONST( HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING, 16 ) );\r
-\r
-        /* Less harmonic noise shaping for less periodic signals */\r
-        HarmShapeGain_Q16 = SKP_SMULWB( SKP_LSHIFT( HarmShapeGain_Q16, 1 ), \r
-            SKP_Silk_SQRT_APPROX( SKP_LSHIFT( psEnc->LTPCorr_Q15, 15 ) ) );\r
-    } else {\r
-        HarmShapeGain_Q16 = 0;\r
-    }\r
-\r
-    /*************************/\r
-    /* Smooth over subframes */\r
-    /*************************/\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        psShapeSt->HarmBoost_smth_Q16 =\r
-            SKP_SMLAWB( psShapeSt->HarmBoost_smth_Q16,     HarmBoost_Q16     - psShapeSt->HarmBoost_smth_Q16,     SKP_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );\r
-        psShapeSt->HarmShapeGain_smth_Q16 =\r
-            SKP_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 - psShapeSt->HarmShapeGain_smth_Q16, SKP_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );\r
-        psShapeSt->Tilt_smth_Q16 =\r
-            SKP_SMLAWB( psShapeSt->Tilt_smth_Q16,          Tilt_Q16          - psShapeSt->Tilt_smth_Q16,          SKP_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );\r
-\r
-        psEncCtrl->HarmBoost_Q14[ k ]     = ( SKP_int )SKP_RSHIFT_ROUND( psShapeSt->HarmBoost_smth_Q16,     2 );\r
-        psEncCtrl->HarmShapeGain_Q14[ k ] = ( SKP_int )SKP_RSHIFT_ROUND( psShapeSt->HarmShapeGain_smth_Q16, 2 );\r
-        psEncCtrl->Tilt_Q14[ k ]          = ( SKP_int )SKP_RSHIFT_ROUND( psShapeSt->Tilt_smth_Q16,          2 );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_tuning_parameters.h"
+
+/* Compute gain to make warped filter coefficients have a zero mean log frequency response on a     */
+/* non-warped frequency scale. (So that it can be implemented with a minimum-phase monic filter.)   */
+SKP_INLINE SKP_int32 warped_gain( // gain in Q16
+    const SKP_int32     *coefs_Q24, 
+    SKP_int             lambda_Q16, 
+    SKP_int             order 
+) {
+    SKP_int   i;
+    SKP_int32 gain_Q24;
+
+    lambda_Q16 = -lambda_Q16;
+    gain_Q24 = coefs_Q24[ order - 1 ];
+    for( i = order - 2; i >= 0; i-- ) {
+        gain_Q24 = SKP_SMLAWB( coefs_Q24[ i ], gain_Q24, lambda_Q16 );
+    }
+    gain_Q24  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), gain_Q24, -lambda_Q16 );
+    return SKP_INVERSE32_varQ( gain_Q24, 40 );
+}
+
+/* Convert warped filter coefficients to monic pseudo-warped coefficients and limit maximum     */
+/* amplitude of monic warped coefficients by using bandwidth expansion on the true coefficients */
+SKP_INLINE void limit_warped_coefs( 
+    SKP_int32           *coefs_syn_Q24,
+    SKP_int32           *coefs_ana_Q24,
+    SKP_int             lambda_Q16,
+    SKP_int32           limit_Q24,
+    SKP_int             order
+) {
+    SKP_int   i, iter, ind = 0;
+    SKP_int32 tmp, maxabs_Q24, chirp_Q16, gain_syn_Q16, gain_ana_Q16;
+    SKP_int32 nom_Q16, den_Q24;
+
+    /* Convert to monic coefficients */
+    lambda_Q16 = -lambda_Q16;
+    for( i = order - 1; i > 0; i-- ) {
+        coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 );
+        coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 );
+    }
+    lambda_Q16 = -lambda_Q16;
+    nom_Q16  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 16 ), -lambda_Q16,        lambda_Q16 );
+    den_Q24  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_syn_Q24[ 0 ], lambda_Q16 );
+    gain_syn_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );
+    den_Q24  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_ana_Q24[ 0 ], lambda_Q16 );
+    gain_ana_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );
+    for( i = 0; i < order; i++ ) {
+        coefs_syn_Q24[ i ] = SKP_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] );
+        coefs_ana_Q24[ i ] = SKP_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] );
+    }
+
+    for( iter = 0; iter < 10; iter++ ) {
+        /* Find maximum absolute value */
+        maxabs_Q24 = -1;
+        for( i = 0; i < order; i++ ) {
+            tmp = SKP_max( SKP_abs_int32( coefs_syn_Q24[ i ] ), SKP_abs_int32( coefs_ana_Q24[ i ] ) );
+            if( tmp > maxabs_Q24 ) {
+                maxabs_Q24 = tmp;
+                ind = i;
+            }
+        }
+        if( maxabs_Q24 <= limit_Q24 ) {
+            /* Coefficients are within range - done */
+            return;
+        }
+
+        /* Convert back to true warped coefficients */
+        for( i = 1; i < order; i++ ) {
+            coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 );
+            coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 );
+        }
+        gain_syn_Q16 = SKP_INVERSE32_varQ( gain_syn_Q16, 32 );
+        gain_ana_Q16 = SKP_INVERSE32_varQ( gain_ana_Q16, 32 );
+        for( i = 0; i < order; i++ ) {
+            coefs_syn_Q24[ i ] = SKP_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] );
+            coefs_ana_Q24[ i ] = SKP_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] );
+        }
+
+        /* Apply bandwidth expansion */
+        chirp_Q16 = SKP_FIX_CONST( 0.99, 16 ) - SKP_DIV32_varQ(
+            SKP_SMULWB( maxabs_Q24 - limit_Q24, SKP_SMLABB( SKP_FIX_CONST( 0.8, 10 ), SKP_FIX_CONST( 0.1, 10 ), iter ) ), 
+            SKP_MUL( maxabs_Q24, ind + 1 ), 22 );
+        SKP_Silk_bwexpander_32( coefs_syn_Q24, order, chirp_Q16 );
+        SKP_Silk_bwexpander_32( coefs_ana_Q24, order, chirp_Q16 );
+
+        /* Convert to monic warped coefficients */
+        lambda_Q16 = -lambda_Q16;
+        for( i = order - 1; i > 0; i-- ) {
+            coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 );
+            coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 );
+        }
+        lambda_Q16 = -lambda_Q16;
+        nom_Q16  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 16 ), -lambda_Q16,        lambda_Q16 );
+        den_Q24  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_syn_Q24[ 0 ], lambda_Q16 );
+        gain_syn_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );
+        den_Q24  = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_ana_Q24[ 0 ], lambda_Q16 );
+        gain_ana_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );
+        for( i = 0; i < order; i++ ) {
+            coefs_syn_Q24[ i ] = SKP_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] );
+            coefs_ana_Q24[ i ] = SKP_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] );
+        }
+    }
+       SKP_assert( 0 );
+}
+
+/**************************************************************/
+/* Compute noise shaping coefficients and initial gain values */
+/**************************************************************/
+void SKP_Silk_noise_shape_analysis_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Encoder state FIX                           */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  Encoder control FIX                         */
+    const SKP_int16                 *pitch_res,     /* I    LPC residual from pitch analysis            */
+    const SKP_int16                 *x              /* I    Input signal [ frame_length + la_shape ]    */
+)
+{
+    SKP_Silk_shape_state_FIX *psShapeSt = &psEnc->sShape;
+    SKP_int     k, i, nSamples, Qnrg, b_Q14, warping_Q16, scale = 0;
+    SKP_int32   SNR_adj_dB_Q7, HarmBoost_Q16, HarmShapeGain_Q16, Tilt_Q16, tmp32;
+    SKP_int32   nrg, pre_nrg_Q30, log_energy_Q7, log_energy_prev_Q7, energy_variation_Q7;
+    SKP_int32   delta_Q16, BWExp1_Q16, BWExp2_Q16, gain_mult_Q16, gain_add_Q16, strength_Q16, b_Q8;
+    SKP_int32   auto_corr[     MAX_SHAPE_LPC_ORDER + 1 ];
+    SKP_int32   refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ];
+    SKP_int32   AR1_Q24[       MAX_SHAPE_LPC_ORDER ];
+    SKP_int32   AR2_Q24[       MAX_SHAPE_LPC_ORDER ];
+    SKP_int16   x_windowed[    SHAPE_LPC_WIN_MAX ];
+    const SKP_int16 *x_ptr, *pitch_res_ptr;
+
+    SKP_int32   sqrt_nrg[ NB_SUBFR ], Qnrg_vec[ NB_SUBFR ];
+
+    /* Point to start of first LPC analysis block */
+    x_ptr = x - psEnc->sCmn.la_shape;
+
+    /****************/
+    /* CONTROL SNR  */
+    /****************/
+    /* Reduce SNR_dB values if recent bitstream has exceeded TargetRate */
+    psEncCtrl->current_SNR_dB_Q7 = psEnc->SNR_dB_Q7 - SKP_SMULWB( SKP_LSHIFT( ( SKP_int32 )psEnc->BufferedInChannel_ms, 7 ), 
+        SKP_FIX_CONST( 0.05, 16 ) );
+
+    /* Reduce SNR_dB if inband FEC used */
+    if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) ) {
+        psEncCtrl->current_SNR_dB_Q7 -= SKP_RSHIFT( psEnc->inBandFEC_SNR_comp_Q8, 1 );
+    }
+
+    /****************/
+    /* GAIN CONTROL */
+    /****************/
+    /* Input quality is the average of the quality in the lowest two VAD bands */
+    psEncCtrl->input_quality_Q14 = ( SKP_int )SKP_RSHIFT( ( SKP_int32 )psEncCtrl->input_quality_bands_Q15[ 0 ] 
+        + psEncCtrl->input_quality_bands_Q15[ 1 ], 2 );
+
+    /* Coding quality level, between 0.0_Q0 and 1.0_Q0, but in Q14 */
+    psEncCtrl->coding_quality_Q14 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->current_SNR_dB_Q7 - 
+        SKP_FIX_CONST( 18.0, 7 ), 4 ) ), 1 );
+
+    /* Reduce coding SNR during low speech activity */
+    b_Q8 = SKP_FIX_CONST( 1.0, 8 ) - psEnc->speech_activity_Q8;
+    b_Q8 = SKP_SMULWB( SKP_LSHIFT( b_Q8, 8 ), b_Q8 );
+    SNR_adj_dB_Q7 = SKP_SMLAWB( psEncCtrl->current_SNR_dB_Q7,
+        SKP_SMULBB( SKP_FIX_CONST( -BG_SNR_DECR_dB, 7 ) >> ( 4 + 1 ), b_Q8 ),                                       // Q11
+        SKP_SMULWB( SKP_FIX_CONST( 1.0, 14 ) + psEncCtrl->input_quality_Q14, psEncCtrl->coding_quality_Q14 ) );     // Q12
+
+    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
+        /* Reduce gains for periodic signals */
+        SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, SKP_FIX_CONST( HARM_SNR_INCR_dB, 8 ), psEnc->LTPCorr_Q15 );
+    } else { 
+        /* For unvoiced signals and low-quality input, adjust the quality slower than SNR_dB setting */
+        SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, 
+            SKP_SMLAWB( SKP_FIX_CONST( 6.0, 9 ), -SKP_FIX_CONST( 0.4, 18 ), psEncCtrl->current_SNR_dB_Q7 ),
+            SKP_FIX_CONST( 1.0, 14 ) - psEncCtrl->input_quality_Q14 );
+    }
+
+    /*************************/
+    /* SPARSENESS PROCESSING */
+    /*************************/
+    /* Set quantizer offset */
+    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
+        /* Initally set to 0; may be overruled in process_gains(..) */
+        psEncCtrl->sCmn.QuantOffsetType = 0;
+        psEncCtrl->sparseness_Q8 = 0;
+    } else {
+        /* Sparseness measure, based on relative fluctuations of energy per 2 milliseconds */
+        nSamples = SKP_LSHIFT( psEnc->sCmn.fs_kHz, 1 );
+        energy_variation_Q7 = 0;
+        log_energy_prev_Q7  = 0;
+        pitch_res_ptr = pitch_res;
+        for( k = 0; k < FRAME_LENGTH_MS / 2; k++ ) {    
+            SKP_Silk_sum_sqr_shift( &nrg, &scale, pitch_res_ptr, nSamples );
+            nrg += SKP_RSHIFT( nSamples, scale );           // Q(-scale)
+            
+            log_energy_Q7 = SKP_Silk_lin2log( nrg );
+            if( k > 0 ) {
+                energy_variation_Q7 += SKP_abs( log_energy_Q7 - log_energy_prev_Q7 );
+            }
+            log_energy_prev_Q7 = log_energy_Q7;
+            pitch_res_ptr += nSamples;
+        }
+
+        psEncCtrl->sparseness_Q8 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_SMULWB( energy_variation_Q7 - 
+            SKP_FIX_CONST( 5.0, 7 ), SKP_FIX_CONST( 0.1, 16 ) ) ), 7 );
+
+        /* Set quantization offset depending on sparseness measure */
+        if( psEncCtrl->sparseness_Q8 > SKP_FIX_CONST( SPARSENESS_THRESHOLD_QNT_OFFSET, 8 ) ) {
+            psEncCtrl->sCmn.QuantOffsetType = 0;
+        } else {
+            psEncCtrl->sCmn.QuantOffsetType = 1;
+        }
+        
+        /* Increase coding SNR for sparse signals */
+        SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, SKP_FIX_CONST( SPARSE_SNR_INCR_dB, 15 ), psEncCtrl->sparseness_Q8 - SKP_FIX_CONST( 0.5, 8 ) );
+    }
+
+    /*******************************/
+    /* Control bandwidth expansion */
+    /*******************************/
+    /* More BWE for signals with high prediction gain */
+    strength_Q16 = SKP_SMULWB( psEncCtrl->predGain_Q16, SKP_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) );
+    BWExp1_Q16 = BWExp2_Q16 = SKP_DIV32_varQ( SKP_FIX_CONST( BANDWIDTH_EXPANSION, 16 ), 
+        SKP_SMLAWW( SKP_FIX_CONST( 1.0, 16 ), strength_Q16, strength_Q16 ), 16 );
+    delta_Q16  = SKP_SMULWB( SKP_FIX_CONST( 1.0, 16 ) - SKP_SMULBB( 3, psEncCtrl->coding_quality_Q14 ), 
+        SKP_FIX_CONST( LOW_RATE_BANDWIDTH_EXPANSION_DELTA, 16 ) );
+    BWExp1_Q16 = SKP_SUB32( BWExp1_Q16, delta_Q16 );
+    BWExp2_Q16 = SKP_ADD32( BWExp2_Q16, delta_Q16 );
+    /* BWExp1 will be applied after BWExp2, so make it relative */
+    BWExp1_Q16 = SKP_DIV32_16( SKP_LSHIFT( BWExp1_Q16, 14 ), SKP_RSHIFT( BWExp2_Q16, 2 ) );
+
+    if( psEnc->sCmn.warping_Q16 > 0 ) {
+        /* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */
+        warping_Q16 = SKP_SMLAWB( psEnc->sCmn.warping_Q16, psEncCtrl->coding_quality_Q14, SKP_FIX_CONST( 0.01, 18 ) );
+    } else {
+        warping_Q16 = 0;
+    }
+
+    /********************************************/
+    /* Compute noise shaping AR coefs and gains */
+    /********************************************/
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        /* Apply window: sine slope followed by flat part followed by cosine slope */
+        SKP_int shift, slope_part, flat_part;
+        flat_part = psEnc->sCmn.fs_kHz * 5;
+        slope_part = SKP_RSHIFT( psEnc->sCmn.shapeWinLength - flat_part, 1 );
+
+        SKP_Silk_apply_sine_window_new( x_windowed, x_ptr, 1, slope_part );
+        shift = slope_part;
+        SKP_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(SKP_int16) );
+        shift += flat_part;
+        SKP_Silk_apply_sine_window_new( x_windowed + shift, x_ptr + shift, 2, slope_part );
+        
+        /* Update pointer: next LPC analysis block */
+        x_ptr += psEnc->sCmn.subfr_length;
+
+        if( psEnc->sCmn.warping_Q16 > 0 ) {
+            /* Calculate warped auto correlation */
+            SKP_Silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, warping_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder ); 
+        } else {
+            /* Calculate regular auto correlation */
+            SKP_Silk_autocorr( auto_corr, &scale, x_windowed, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder + 1 );
+        }
+
+        /* Add white noise, as a fraction of energy */
+        auto_corr[0] = SKP_ADD32( auto_corr[0], SKP_max_32( SKP_SMULWB( SKP_RSHIFT( auto_corr[ 0 ], 4 ), 
+            SKP_FIX_CONST( SHAPE_WHITE_NOISE_FRACTION, 20 ) ), 1 ) ); 
+
+        /* Calculate the reflection coefficients using schur */
+        nrg = SKP_Silk_schur64( refl_coef_Q16, auto_corr, psEnc->sCmn.shapingLPCOrder );
+        SKP_assert( nrg >= 0 );
+
+        /* Convert reflection coefficients to prediction coefficients */
+        SKP_Silk_k2a_Q16( AR2_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder );
+
+        Qnrg = -scale;          // range: -12...30
+        SKP_assert( Qnrg >= -12 );
+        SKP_assert( Qnrg <=  30 );
+
+        /* Make sure that Qnrg is an even number */
+        if( Qnrg & 1 ) {
+            Qnrg -= 1;
+            nrg >>= 1;
+        }
+
+        tmp32 = SKP_Silk_SQRT_APPROX( nrg );
+        Qnrg >>= 1;             // range: -6...15
+
+        sqrt_nrg[ k ] = tmp32;
+        Qnrg_vec[ k ] = Qnrg;
+
+        psEncCtrl->Gains_Q16[ k ] = SKP_LSHIFT_SAT32( tmp32, 16 - Qnrg );
+
+        if( psEnc->sCmn.warping_Q16 > 0 ) {
+            /* Adjust gain for warping */
+            gain_mult_Q16 = warped_gain( AR2_Q24, warping_Q16, psEnc->sCmn.shapingLPCOrder );
+            SKP_assert( psEncCtrl->Gains_Q16[ k ] >= 0 );
+            psEncCtrl->Gains_Q16[ k ] = SKP_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 );
+            if( psEncCtrl->Gains_Q16[ k ] < 0 ) {
+                psEncCtrl->Gains_Q16[ k ] = SKP_int32_MAX;
+            }
+        }
+
+        /* Bandwidth expansion for synthesis filter shaping */
+        SKP_Silk_bwexpander_32( AR2_Q24, psEnc->sCmn.shapingLPCOrder, BWExp2_Q16 );
+
+        /* Compute noise shaping filter coefficients */
+        SKP_memcpy( AR1_Q24, AR2_Q24, psEnc->sCmn.shapingLPCOrder * sizeof( SKP_int32 ) );
+
+        /* Bandwidth expansion for analysis filter shaping */
+        SKP_assert( BWExp1_Q16 <= SKP_FIX_CONST( 1.0, 16 ) );
+        SKP_Silk_bwexpander_32( AR1_Q24, psEnc->sCmn.shapingLPCOrder, BWExp1_Q16 );
+
+        /* Ratio of prediction gains, in energy domain */
+        SKP_Silk_LPC_inverse_pred_gain_Q24( &pre_nrg_Q30, AR2_Q24, psEnc->sCmn.shapingLPCOrder );
+        SKP_Silk_LPC_inverse_pred_gain_Q24( &nrg,         AR1_Q24, psEnc->sCmn.shapingLPCOrder );
+
+        //psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ) = 0.3f + 0.7f * pre_nrg / nrg;
+        pre_nrg_Q30 = SKP_LSHIFT32( SKP_SMULWB( pre_nrg_Q30, SKP_FIX_CONST( 0.7, 15 ) ), 1 );
+        psEncCtrl->GainsPre_Q14[ k ] = ( SKP_int ) SKP_FIX_CONST( 0.3, 14 ) + SKP_DIV32_varQ( pre_nrg_Q30, nrg, 14 );
+
+        /* Convert to monic warped prediction coefficients and limit absolute values */
+        limit_warped_coefs( AR2_Q24, AR1_Q24, warping_Q16, SKP_FIX_CONST( 3.999, 24 ), psEnc->sCmn.shapingLPCOrder );
+
+        /* Convert from Q24 to Q13 and store in int16 */
+        for( i = 0; i < psEnc->sCmn.shapingLPCOrder; i++ ) {
+            psEncCtrl->AR1_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( AR1_Q24[ i ], 11 ) );
+            psEncCtrl->AR2_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( AR2_Q24[ i ], 11 ) );
+        }
+    }
+
+    /*****************/
+    /* Gain tweaking */
+    /*****************/
+    /* Increase gains during low speech activity and put lower limit on gains */
+    gain_mult_Q16 = SKP_Silk_log2lin( -SKP_SMLAWB( -SKP_FIX_CONST( 16.0, 7 ), SNR_adj_dB_Q7,                            SKP_FIX_CONST( 0.16, 16 ) ) );
+    gain_add_Q16  = SKP_Silk_log2lin(  SKP_SMLAWB(  SKP_FIX_CONST( 16.0, 7 ), SKP_FIX_CONST( NOISE_FLOOR_dB, 7 ),       SKP_FIX_CONST( 0.16, 16 ) ) );
+    tmp32         = SKP_Silk_log2lin(  SKP_SMLAWB(  SKP_FIX_CONST( 16.0, 7 ), SKP_FIX_CONST( RELATIVE_MIN_GAIN_dB, 7 ), SKP_FIX_CONST( 0.16, 16 ) ) );
+    tmp32 = SKP_SMULWW( psEnc->avgGain_Q16, tmp32 );
+    gain_add_Q16 = SKP_ADD_SAT32( gain_add_Q16, tmp32 );
+    SKP_assert( gain_mult_Q16 >= 0 );
+
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        psEncCtrl->Gains_Q16[ k ] = SKP_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 );
+        if( psEncCtrl->Gains_Q16[ k ] < 0 ) {
+            psEncCtrl->Gains_Q16[ k ] = SKP_int32_MAX;
+        }
+    }
+
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        psEncCtrl->Gains_Q16[ k ] = SKP_ADD_POS_SAT32( psEncCtrl->Gains_Q16[ k ], gain_add_Q16 );
+        psEnc->avgGain_Q16 = SKP_ADD_SAT32( 
+            psEnc->avgGain_Q16, 
+            SKP_SMULWB(
+                psEncCtrl->Gains_Q16[ k ] - psEnc->avgGain_Q16, 
+                SKP_RSHIFT_ROUND( SKP_SMULBB( psEnc->speech_activity_Q8, SKP_FIX_CONST( GAIN_SMOOTHING_COEF, 10 ) ), 2 ) 
+            ) );
+    }
+
+    /************************************************/
+    /* Decrease level during fricatives (de-essing) */
+    /************************************************/
+    gain_mult_Q16 = SKP_FIX_CONST( 1.0, 16 ) + SKP_RSHIFT_ROUND( SKP_MLA( SKP_FIX_CONST( INPUT_TILT, 26 ), 
+        psEncCtrl->coding_quality_Q14, SKP_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) ), 10 );
+
+    if( psEncCtrl->input_tilt_Q15 <= 0 && psEncCtrl->sCmn.sigtype == SIG_TYPE_UNVOICED ) {
+        if( psEnc->sCmn.fs_kHz == 24 ) {
+            SKP_int32 essStrength_Q15 = SKP_SMULWW( -psEncCtrl->input_tilt_Q15, 
+                SKP_SMULBB( psEnc->speech_activity_Q8, SKP_FIX_CONST( 1.0, 8 ) - psEncCtrl->sparseness_Q8 ) );
+            tmp32 = SKP_Silk_log2lin( SKP_FIX_CONST( 16.0, 7 ) - SKP_SMULWB( essStrength_Q15, 
+                SKP_SMULWB( SKP_FIX_CONST( DE_ESSER_COEF_SWB_dB, 7 ), SKP_FIX_CONST( 0.16, 17 ) ) ) );
+            gain_mult_Q16 = SKP_SMULWW( gain_mult_Q16, tmp32 );
+        } else if( psEnc->sCmn.fs_kHz == 16 ) {
+            SKP_int32 essStrength_Q15 = SKP_SMULWW(-psEncCtrl->input_tilt_Q15, 
+                SKP_SMULBB( psEnc->speech_activity_Q8, SKP_FIX_CONST( 1.0, 8 ) - psEncCtrl->sparseness_Q8 ));
+            tmp32 = SKP_Silk_log2lin( SKP_FIX_CONST( 16.0, 7 ) - SKP_SMULWB( essStrength_Q15, 
+                SKP_SMULWB( SKP_FIX_CONST( DE_ESSER_COEF_WB_dB, 7 ), SKP_FIX_CONST( 0.16, 17 ) ) ) );
+            gain_mult_Q16 = SKP_SMULWW( gain_mult_Q16, tmp32 );
+        } else {
+            SKP_assert( psEnc->sCmn.fs_kHz == 12 || psEnc->sCmn.fs_kHz == 8 );
+        }
+    }
+
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        psEncCtrl->GainsPre_Q14[ k ] = SKP_SMULWB( gain_mult_Q16, psEncCtrl->GainsPre_Q14[ k ] );
+    }
+
+    /************************************************/
+    /* Control low-frequency shaping and noise tilt */
+    /************************************************/
+    /* Less low frequency shaping for noisy inputs */
+    strength_Q16 = SKP_MUL( SKP_FIX_CONST( LOW_FREQ_SHAPING, 0 ), SKP_FIX_CONST( 1.0, 16 ) + 
+        SKP_SMULBB( SKP_FIX_CONST( LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 1 ), psEncCtrl->input_quality_bands_Q15[ 0 ] - SKP_FIX_CONST( 1.0, 15 ) ) );
+    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
+        /* Reduce low frequencies quantization noise for periodic signals, depending on pitch lag */
+        /*f = 400; freqz([1, -0.98 + 2e-4 * f], [1, -0.97 + 7e-4 * f], 2^12, Fs); axis([0, 1000, -10, 1])*/
+        SKP_int fs_kHz_inv = SKP_DIV32_16( SKP_FIX_CONST( 0.2, 14 ), psEnc->sCmn.fs_kHz );
+        for( k = 0; k < NB_SUBFR; k++ ) {
+            b_Q14 = fs_kHz_inv + SKP_DIV32_16( SKP_FIX_CONST( 3.0, 14 ), psEncCtrl->sCmn.pitchL[ k ] ); 
+            /* Pack two coefficients in one int32 */
+            psEncCtrl->LF_shp_Q14[ k ]  = SKP_LSHIFT( SKP_FIX_CONST( 1.0, 14 ) - b_Q14 - SKP_SMULWB( strength_Q16, b_Q14 ), 16 );
+            psEncCtrl->LF_shp_Q14[ k ] |= (SKP_uint16)( b_Q14 - SKP_FIX_CONST( 1.0, 14 ) );
+        }
+        SKP_assert( SKP_FIX_CONST( HARM_HP_NOISE_COEF, 24 ) < SKP_FIX_CONST( 0.5, 24 ) ); // Guarantees that second argument to SMULWB() is within range of an SKP_int16
+        Tilt_Q16 = - SKP_FIX_CONST( HP_NOISE_COEF, 16 ) - 
+            SKP_SMULWB( SKP_FIX_CONST( 1.0, 16 ) - SKP_FIX_CONST( HP_NOISE_COEF, 16 ), 
+                SKP_SMULWB( SKP_FIX_CONST( HARM_HP_NOISE_COEF, 24 ), psEnc->speech_activity_Q8 ) );
+    } else {
+        b_Q14 = SKP_DIV32_16( 21299, psEnc->sCmn.fs_kHz ); // 1.3_Q0 = 21299_Q14
+        /* Pack two coefficients in one int32 */
+        psEncCtrl->LF_shp_Q14[ 0 ]  = SKP_LSHIFT( SKP_FIX_CONST( 1.0, 14 ) - b_Q14 - 
+            SKP_SMULWB( strength_Q16, SKP_SMULWB( SKP_FIX_CONST( 0.6, 16 ), b_Q14 ) ), 16 );
+        psEncCtrl->LF_shp_Q14[ 0 ] |= (SKP_uint16)( b_Q14 - SKP_FIX_CONST( 1.0, 14 ) );
+        for( k = 1; k < NB_SUBFR; k++ ) {
+            psEncCtrl->LF_shp_Q14[ k ] = psEncCtrl->LF_shp_Q14[ 0 ];
+        }
+        Tilt_Q16 = -SKP_FIX_CONST( HP_NOISE_COEF, 16 );
+    }
+
+    /****************************/
+    /* HARMONIC SHAPING CONTROL */
+    /****************************/
+    /* Control boosting of harmonic frequencies */
+    HarmBoost_Q16 = SKP_SMULWB( SKP_SMULWB( SKP_FIX_CONST( 1.0, 17 ) - SKP_LSHIFT( psEncCtrl->coding_quality_Q14, 3 ), 
+        psEnc->LTPCorr_Q15 ), SKP_FIX_CONST( LOW_RATE_HARMONIC_BOOST, 16 ) );
+
+    /* More harmonic boost for noisy input signals */
+    HarmBoost_Q16 = SKP_SMLAWB( HarmBoost_Q16, 
+        SKP_FIX_CONST( 1.0, 16 ) - SKP_LSHIFT( psEncCtrl->input_quality_Q14, 2 ), SKP_FIX_CONST( LOW_INPUT_QUALITY_HARMONIC_BOOST, 16 ) );
+
+    if( USE_HARM_SHAPING && psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
+        /* More harmonic noise shaping for high bitrates or noisy input */
+        HarmShapeGain_Q16 = SKP_SMLAWB( SKP_FIX_CONST( HARMONIC_SHAPING, 16 ), 
+                SKP_FIX_CONST( 1.0, 16 ) - SKP_SMULWB( SKP_FIX_CONST( 1.0, 18 ) - SKP_LSHIFT( psEncCtrl->coding_quality_Q14, 4 ),
+                psEncCtrl->input_quality_Q14 ), SKP_FIX_CONST( HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING, 16 ) );
+
+        /* Less harmonic noise shaping for less periodic signals */
+        HarmShapeGain_Q16 = SKP_SMULWB( SKP_LSHIFT( HarmShapeGain_Q16, 1 ), 
+            SKP_Silk_SQRT_APPROX( SKP_LSHIFT( psEnc->LTPCorr_Q15, 15 ) ) );
+    } else {
+        HarmShapeGain_Q16 = 0;
+    }
+
+    /*************************/
+    /* Smooth over subframes */
+    /*************************/
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        psShapeSt->HarmBoost_smth_Q16 =
+            SKP_SMLAWB( psShapeSt->HarmBoost_smth_Q16,     HarmBoost_Q16     - psShapeSt->HarmBoost_smth_Q16,     SKP_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );
+        psShapeSt->HarmShapeGain_smth_Q16 =
+            SKP_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 - psShapeSt->HarmShapeGain_smth_Q16, SKP_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );
+        psShapeSt->Tilt_smth_Q16 =
+            SKP_SMLAWB( psShapeSt->Tilt_smth_Q16,          Tilt_Q16          - psShapeSt->Tilt_smth_Q16,          SKP_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );
+
+        psEncCtrl->HarmBoost_Q14[ k ]     = ( SKP_int )SKP_RSHIFT_ROUND( psShapeSt->HarmBoost_smth_Q16,     2 );
+        psEncCtrl->HarmShapeGain_Q14[ k ] = ( SKP_int )SKP_RSHIFT_ROUND( psShapeSt->HarmShapeGain_smth_Q16, 2 );
+        psEncCtrl->Tilt_Q14[ k ]          = ( SKP_int )SKP_RSHIFT_ROUND( psShapeSt->Tilt_smth_Q16,          2 );
+    }
+}
index f62d222fcca3fd31f9d186a64de14d9d7743f3a7..1e9fbf3459334c451adfcb82cf648ee28b8aeb65 100644 (file)
-/***********************************************************************\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
-* Pitch analyser function\r
-********************************************************** */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_pitch_est_defines.h"\r
-#include "SKP_Silk_common_pitch_est_defines.h"\r
-\r
-#define SCRATCH_SIZE    22\r
-\r
-/************************************************************/\r
-/* Internally used functions                                */\r
-/************************************************************/\r
-void SKP_FIX_P_Ana_calc_corr_st3(\r
-    SKP_int32        cross_corr_st3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX][PITCH_EST_NB_STAGE3_LAGS],/* (O) 3 DIM correlation array */\r
-    const SKP_int16  signal[],                        /* I vector to correlate         */\r
-    SKP_int          start_lag,                       /* I lag offset to search around */\r
-    SKP_int          sf_length,                       /* I length of a 5 ms subframe   */\r
-    SKP_int          complexity                       /* I Complexity setting          */\r
-);\r
-\r
-void SKP_FIX_P_Ana_calc_energy_st3(\r
-    SKP_int32        energies_st3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX][PITCH_EST_NB_STAGE3_LAGS],/* (O) 3 DIM energy array */\r
-    const SKP_int16  signal[],                        /* I vector to calc energy in    */\r
-    SKP_int          start_lag,                       /* I lag offset to search around */\r
-    SKP_int          sf_length,                       /* I length of one 5 ms subframe */\r
-    SKP_int          complexity                       /* I Complexity setting          */\r
-);\r
-\r
-SKP_int32 SKP_FIX_P_Ana_find_scaling(\r
-    const SKP_int16  *signal,\r
-    const SKP_int    signal_length, \r
-    const SKP_int    sum_sqr_len\r
-);\r
-\r
-/*************************************************************/\r
-/*      FIXED POINT CORE PITCH ANALYSIS FUNCTION             */\r
-/*************************************************************/\r
-SKP_int SKP_Silk_pitch_analysis_core(  /* O    Voicing estimate: 0 voiced, 1 unvoiced                      */\r
-    const SKP_int16  *signal,            /* I    Signal of length PITCH_EST_FRAME_LENGTH_MS*Fs_kHz           */\r
-    SKP_int          *pitch_out,         /* O    4 pitch lag values                                          */\r
-    SKP_int          *lagIndex,          /* O    Lag Index                                                   */\r
-    SKP_int          *contourIndex,      /* O    Pitch contour Index                                         */\r
-    SKP_int          *LTPCorr_Q15,       /* I/O  Normalized correlation; input: value from previous frame    */\r
-    SKP_int          prevLag,            /* I    Last lag of previous frame; set to zero is unvoiced         */\r
-    const SKP_int32  search_thres1_Q16,  /* I    First stage threshold for lag candidates 0 - 1              */\r
-    const SKP_int    search_thres2_Q15,  /* I    Final threshold for lag candidates 0 - 1                    */\r
-    const SKP_int    Fs_kHz,             /* I    Sample frequency (kHz)                                      */\r
-    const SKP_int    complexity,         /* I   Complexity setting, 0-2, where 2 is highest                 */\r
-       const SKP_int    forLJC                      /* I        1 if this function is called from LJC code, 0 otherwise.  */\r
-)\r
-{\r
-    SKP_int16 signal_8kHz[ PITCH_EST_MAX_FRAME_LENGTH_ST_2 ];\r
-    SKP_int16 signal_4kHz[ PITCH_EST_MAX_FRAME_LENGTH_ST_1 ];\r
-    SKP_int32 scratch_mem[ 3 * PITCH_EST_MAX_FRAME_LENGTH ];\r
-    SKP_int16 *input_signal_ptr;\r
-    SKP_int32 filt_state[ PITCH_EST_MAX_DECIMATE_STATE_LENGTH ];\r
-    SKP_int   i, k, d, j;\r
-    SKP_int16 C[ PITCH_EST_NB_SUBFR ][ ( PITCH_EST_MAX_LAG >> 1 ) + 5 ];\r
-    const SKP_int16 *target_ptr, *basis_ptr;\r
-    SKP_int32 cross_corr, normalizer, energy, shift, energy_basis, energy_target;\r
-    SKP_int   d_srch[ PITCH_EST_D_SRCH_LENGTH ];\r
-    SKP_int16 d_comp[ ( PITCH_EST_MAX_LAG >> 1 ) + 5 ];\r
-    SKP_int   Cmax, length_d_srch, length_d_comp;\r
-    SKP_int32 sum, threshold, temp32;\r
-    SKP_int   CBimax, CBimax_new, CBimax_old, lag, start_lag, end_lag, lag_new;\r
-    SKP_int32 CC[ PITCH_EST_NB_CBKS_STAGE2_EXT ], CCmax, CCmax_b, CCmax_new_b, CCmax_new;\r
-    SKP_int32 energies_st3[  PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ];\r
-    SKP_int32 crosscorr_st3[ PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ];\r
-    SKP_int32 lag_counter;\r
-    SKP_int   frame_length, frame_length_8kHz, frame_length_4kHz, max_sum_sq_length;\r
-    SKP_int   sf_length, sf_length_8kHz, sf_length_4kHz;\r
-    SKP_int   min_lag, min_lag_8kHz, min_lag_4kHz;\r
-    SKP_int   max_lag, max_lag_8kHz, max_lag_4kHz;\r
-    SKP_int32 contour_bias, diff;\r
-    SKP_int32 lz, lshift;\r
-    SKP_int   cbk_offset, cbk_size, nb_cbks_stage2;\r
-    SKP_int32 delta_lag_log2_sqr_Q7, lag_log2_Q7, prevLag_log2_Q7, prev_lag_bias_Q15, corr_thres_Q15;\r
-\r
-    /* Check for valid sampling frequency */\r
-    SKP_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 || Fs_kHz == 24 );\r
-\r
-    /* Check for valid complexity setting */\r
-    SKP_assert( complexity >= SKP_Silk_PITCH_EST_MIN_COMPLEX );\r
-    SKP_assert( complexity <= SKP_Silk_PITCH_EST_MAX_COMPLEX );\r
-\r
-    SKP_assert( search_thres1_Q16 >= 0 && search_thres1_Q16 <= (1<<16) );\r
-    SKP_assert( search_thres2_Q15 >= 0 && search_thres2_Q15 <= (1<<15) );\r
-\r
-    /* Setup frame lengths max / min lag for the sampling frequency */\r
-    frame_length      = PITCH_EST_FRAME_LENGTH_MS * Fs_kHz;\r
-    frame_length_4kHz = PITCH_EST_FRAME_LENGTH_MS * 4;\r
-    frame_length_8kHz = PITCH_EST_FRAME_LENGTH_MS * 8;\r
-    sf_length         = SKP_RSHIFT( frame_length,      3 );\r
-    sf_length_4kHz    = SKP_RSHIFT( frame_length_4kHz, 3 );\r
-    sf_length_8kHz    = SKP_RSHIFT( frame_length_8kHz, 3 );\r
-    min_lag           = PITCH_EST_MIN_LAG_MS * Fs_kHz;\r
-    min_lag_4kHz      = PITCH_EST_MIN_LAG_MS * 4;\r
-    min_lag_8kHz      = PITCH_EST_MIN_LAG_MS * 8;\r
-    max_lag           = PITCH_EST_MAX_LAG_MS * Fs_kHz;\r
-    max_lag_4kHz      = PITCH_EST_MAX_LAG_MS * 4;\r
-    max_lag_8kHz      = PITCH_EST_MAX_LAG_MS * 8;\r
-\r
-    SKP_memset( C, 0, sizeof( SKP_int16 ) * PITCH_EST_NB_SUBFR * ( ( PITCH_EST_MAX_LAG >> 1 ) + 5) );\r
-    \r
-    /* Resample from input sampled at Fs_kHz to 8 kHz */\r
-    if( Fs_kHz == 16 ) {\r
-        SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) );\r
-        SKP_Silk_resampler_down2( filt_state, signal_8kHz, signal, frame_length );\r
-    } else if ( Fs_kHz == 12 ) {\r
-        SKP_int32 R23[ 6 ];\r
-        SKP_memset( R23, 0, 6 * sizeof( SKP_int32 ) );\r
-        SKP_Silk_resampler_down2_3( R23, signal_8kHz, signal, PITCH_EST_FRAME_LENGTH_MS * 12 );\r
-    } else if( Fs_kHz == 24 ) {\r
-        SKP_int32 filt_state_fix[ 8 ];\r
-        SKP_memset( filt_state_fix, 0, 8 * sizeof(SKP_int32) );\r
-        SKP_Silk_resampler_down3( filt_state_fix, signal_8kHz, signal, 24 * PITCH_EST_FRAME_LENGTH_MS );\r
-    } else {\r
-        SKP_assert( Fs_kHz == 8 );\r
-        SKP_memcpy( signal_8kHz, signal, frame_length_8kHz * sizeof(SKP_int16) );\r
-    }\r
-    /* Decimate again to 4 kHz */\r
-    SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) );/* Set state to zero */\r
-    SKP_Silk_resampler_down2( filt_state, signal_4kHz, signal_8kHz, frame_length_8kHz );\r
-\r
-    /* Low-pass filter */\r
-    for( i = frame_length_4kHz - 1; i > 0; i-- ) {\r
-        signal_4kHz[ i ] = SKP_ADD_SAT16( signal_4kHz[ i ], signal_4kHz[ i - 1 ] );\r
-    }\r
-\r
-    /*******************************************************************************\r
-    ** Scale 4 kHz signal down to prevent correlations measures from overflowing\r
-    ** find scaling as max scaling for each 8kHz(?) subframe\r
-    *******************************************************************************/\r
-    \r
-    /* Inner product is calculated with different lengths, so scale for the worst case */\r
-    max_sum_sq_length = SKP_max_32( sf_length_8kHz, SKP_RSHIFT( frame_length_4kHz, 1 ) );\r
-    shift = SKP_FIX_P_Ana_find_scaling( signal_4kHz, frame_length_4kHz, max_sum_sq_length );\r
-    if( shift > 0 ) {\r
-        for( i = 0; i < frame_length_4kHz; i++ ) {\r
-            signal_4kHz[ i ] = SKP_RSHIFT( signal_4kHz[ i ], shift );\r
-        }\r
-    }\r
-\r
-    /******************************************************************************\r
-    * FIRST STAGE, operating in 4 khz\r
-    ******************************************************************************/\r
-    target_ptr = &signal_4kHz[ SKP_RSHIFT( frame_length_4kHz, 1 ) ];\r
-    for( k = 0; k < 2; k++ ) {\r
-        /* Check that we are within range of the array */\r
-        SKP_assert( target_ptr >= signal_4kHz );\r
-        SKP_assert( target_ptr + sf_length_8kHz <= signal_4kHz + frame_length_4kHz );\r
-\r
-        basis_ptr = target_ptr - min_lag_4kHz;\r
-\r
-        /* Check that we are within range of the array */\r
-        SKP_assert( basis_ptr >= signal_4kHz );\r
-        SKP_assert( basis_ptr + sf_length_8kHz <= signal_4kHz + frame_length_4kHz );\r
-\r
-        normalizer = 0;\r
-        cross_corr = 0;\r
-        /* Calculate first vector products before loop */\r
-        cross_corr = SKP_Silk_inner_prod_aligned( target_ptr, basis_ptr, sf_length_8kHz );\r
-        normalizer = SKP_Silk_inner_prod_aligned( basis_ptr,  basis_ptr, sf_length_8kHz );\r
-        normalizer = SKP_ADD_SAT32( normalizer, SKP_SMULBB( sf_length_8kHz, 4000 ) );\r
-\r
-        temp32 = SKP_DIV32( cross_corr, SKP_Silk_SQRT_APPROX( normalizer ) + 1 );\r
-        C[ k ][ min_lag_4kHz ] = (SKP_int16)SKP_SAT16( temp32 );        /* Q0 */\r
-\r
-        /* From now on normalizer is computed recursively */\r
-        for( d = min_lag_4kHz + 1; d <= max_lag_4kHz; d++ ) {\r
-            basis_ptr--;\r
-\r
-            /* Check that we are within range of the array */\r
-            SKP_assert( basis_ptr >= signal_4kHz );\r
-            SKP_assert( basis_ptr + sf_length_8kHz <= signal_4kHz + frame_length_4kHz );\r
-\r
-            cross_corr = SKP_Silk_inner_prod_aligned( target_ptr, basis_ptr, sf_length_8kHz );\r
-\r
-            /* Add contribution of new sample and remove contribution from oldest sample */\r
-            normalizer +=\r
-                SKP_SMULBB( basis_ptr[ 0 ], basis_ptr[ 0 ] ) - \r
-                SKP_SMULBB( basis_ptr[ sf_length_8kHz ], basis_ptr[ sf_length_8kHz ] ); \r
-    \r
-            temp32 = SKP_DIV32( cross_corr, SKP_Silk_SQRT_APPROX( normalizer ) + 1 );\r
-            C[ k ][ d ] = (SKP_int16)SKP_SAT16( temp32 );                        /* Q0 */\r
-        }\r
-        /* Update target pointer */\r
-        target_ptr += sf_length_8kHz;\r
-    }\r
-\r
-    /* Combine two subframes into single correlation measure and apply short-lag bias */\r
-    for( i = max_lag_4kHz; i >= min_lag_4kHz; i-- ) {\r
-        sum = (SKP_int32)C[ 0 ][ i ] + (SKP_int32)C[ 1 ][ i ];                /* Q0 */\r
-        SKP_assert( SKP_RSHIFT( sum, 1 ) == SKP_SAT16( SKP_RSHIFT( sum, 1 ) ) );\r
-        sum = SKP_RSHIFT( sum, 1 );                                           /* Q-1 */\r
-        SKP_assert( SKP_LSHIFT( (SKP_int32)-i, 4 ) == SKP_SAT16( SKP_LSHIFT( (SKP_int32)-i, 4 ) ) );\r
-        sum = SKP_SMLAWB( sum, sum, SKP_LSHIFT( -i, 4 ) );                    /* Q-1 */\r
-        SKP_assert( sum == SKP_SAT16( sum ) );\r
-        C[ 0 ][ i ] = (SKP_int16)sum;                                         /* Q-1 */\r
-    }\r
-\r
-    /* Sort */\r
-    length_d_srch = 4 + 2 * complexity;\r
-    SKP_assert( 3 * length_d_srch <= PITCH_EST_D_SRCH_LENGTH );\r
-    SKP_Silk_insertion_sort_decreasing_int16( &C[ 0 ][ min_lag_4kHz ], d_srch, max_lag_4kHz - min_lag_4kHz + 1, length_d_srch );\r
-\r
-    /* Escape if correlation is very low already here */\r
-    target_ptr = &signal_4kHz[ SKP_RSHIFT( frame_length_4kHz, 1 ) ];\r
-    energy = SKP_Silk_inner_prod_aligned( target_ptr, target_ptr, SKP_RSHIFT( frame_length_4kHz, 1 ) );\r
-    energy = SKP_ADD_POS_SAT32( energy, 1000 );                              /* Q0 */\r
-    Cmax = (SKP_int)C[ 0 ][ min_lag_4kHz ];                                  /* Q-1 */\r
-    threshold = SKP_SMULBB( Cmax, Cmax );                                    /* Q-2 */\r
-    /* Compare in Q-2 domain */\r
-    if( SKP_RSHIFT( energy, 4 + 2 ) > threshold ) {                            \r
-        SKP_memset( pitch_out, 0, PITCH_EST_NB_SUBFR * sizeof( SKP_int ) );\r
-        *LTPCorr_Q15  = 0;\r
-        *lagIndex     = 0;\r
-        *contourIndex = 0;\r
-        return 1;\r
-    }\r
-\r
-    threshold = SKP_SMULWB( search_thres1_Q16, Cmax );\r
-    for( i = 0; i < length_d_srch; i++ ) {\r
-        /* Convert to 8 kHz indices for the sorted correlation that exceeds the threshold */\r
-        if( C[ 0 ][ min_lag_4kHz + i ] > threshold ) {\r
-            d_srch[ i ] = SKP_LSHIFT( d_srch[ i ] + min_lag_4kHz, 1 );\r
-        } else {\r
-            length_d_srch = i;\r
-            break;\r
-        }\r
-    }\r
-    SKP_assert( length_d_srch > 0 );\r
-\r
-    for( i = min_lag_8kHz - 5; i < max_lag_8kHz + 5; i++ ) {\r
-        d_comp[ i ] = 0;\r
-    }\r
-    for( i = 0; i < length_d_srch; i++ ) {\r
-        d_comp[ d_srch[ i ] ] = 1;\r
-    }\r
-\r
-    /* Convolution */\r
-    for( i = max_lag_8kHz + 3; i >= min_lag_8kHz; i-- ) {\r
-        d_comp[ i ] += d_comp[ i - 1 ] + d_comp[ i - 2 ];\r
-    }\r
-\r
-    length_d_srch = 0;\r
-    for( i = min_lag_8kHz; i < max_lag_8kHz + 1; i++ ) {    \r
-        if( d_comp[ i + 1 ] > 0 ) {\r
-            d_srch[ length_d_srch ] = i;\r
-            length_d_srch++;\r
-        }\r
-    }\r
-\r
-    /* Convolution */\r
-    for( i = max_lag_8kHz + 3; i >= min_lag_8kHz; i-- ) {\r
-        d_comp[ i ] += d_comp[ i - 1 ] + d_comp[ i - 2 ] + d_comp[ i - 3 ];\r
-    }\r
-\r
-    length_d_comp = 0;\r
-    for( i = min_lag_8kHz; i < max_lag_8kHz + 4; i++ ) {    \r
-        if( d_comp[ i ] > 0 ) {\r
-            d_comp[ length_d_comp ] = i - 2;\r
-            length_d_comp++;\r
-        }\r
-    }\r
-\r
-    /**********************************************************************************\r
-    ** SECOND STAGE, operating at 8 kHz, on lag sections with high correlation\r
-    *************************************************************************************/\r
-\r
-    /******************************************************************************\r
-    ** Scale signal down to avoid correlations measures from overflowing\r
-    *******************************************************************************/\r
-    /* find scaling as max scaling for each subframe */\r
-    shift = SKP_FIX_P_Ana_find_scaling( signal_8kHz, frame_length_8kHz, sf_length_8kHz );\r
-    if( shift > 0 ) {\r
-        for( i = 0; i < frame_length_8kHz; i++ ) {\r
-            signal_8kHz[ i ] = SKP_RSHIFT( signal_8kHz[ i ], shift );\r
-        }\r
-    }\r
-\r
-    /********************************************************************************* \r
-    * Find energy of each subframe projected onto its history, for a range of delays\r
-    *********************************************************************************/\r
-    SKP_memset( C, 0, PITCH_EST_NB_SUBFR * ( ( PITCH_EST_MAX_LAG >> 1 ) + 5 ) * sizeof( SKP_int16 ) );\r
-    \r
-    target_ptr = &signal_8kHz[ frame_length_4kHz ]; /* point to middle of frame */\r
-    for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {\r
-\r
-        /* Check that we are within range of the array */\r
-        SKP_assert( target_ptr >= signal_8kHz );\r
-        SKP_assert( target_ptr + sf_length_8kHz <= signal_8kHz + frame_length_8kHz );\r
-\r
-        energy_target = SKP_Silk_inner_prod_aligned( target_ptr, target_ptr, sf_length_8kHz );\r
-        // ToDo: Calculate 1 / energy_target here and save one division inside next for loop\r
-        for( j = 0; j < length_d_comp; j++ ) {\r
-            d = d_comp[ j ];\r
-            basis_ptr = target_ptr - d;\r
-\r
-            /* Check that we are within range of the array */\r
-            SKP_assert( basis_ptr >= signal_8kHz );\r
-            SKP_assert( basis_ptr + sf_length_8kHz <= signal_8kHz + frame_length_8kHz );\r
-        \r
-            cross_corr   = SKP_Silk_inner_prod_aligned( target_ptr, basis_ptr, sf_length_8kHz );\r
-            energy_basis = SKP_Silk_inner_prod_aligned( basis_ptr,  basis_ptr, sf_length_8kHz );\r
-            if( cross_corr > 0 ) {\r
-                energy = SKP_max( energy_target, energy_basis ); /* Find max to make sure first division < 1.0 */\r
-                lz = SKP_Silk_CLZ32( cross_corr );\r
-                lshift = SKP_LIMIT_32( lz - 1, 0, 15 );\r
-                temp32 = SKP_DIV32( SKP_LSHIFT( cross_corr, lshift ), SKP_RSHIFT( energy, 15 - lshift ) + 1 ); /* Q15 */\r
-                SKP_assert( temp32 == SKP_SAT16( temp32 ) );\r
-                temp32 = SKP_SMULWB( cross_corr, temp32 ); /* Q(-1), cc * ( cc / max(b, t) ) */\r
-                temp32 = SKP_ADD_SAT32( temp32, temp32 );  /* Q(0) */\r
-                lz = SKP_Silk_CLZ32( temp32 );\r
-                lshift = SKP_LIMIT_32( lz - 1, 0, 15 );\r
-                energy = SKP_min( energy_target, energy_basis );\r
-                C[ k ][ d ] = SKP_DIV32( SKP_LSHIFT( temp32, lshift ), SKP_RSHIFT( energy, 15 - lshift ) + 1 ); // Q15\r
-            } else {\r
-                C[ k ][ d ] = 0;\r
-            }\r
-        }\r
-        target_ptr += sf_length_8kHz;\r
-    }\r
-\r
-    /* search over lag range and lags codebook */\r
-    /* scale factor for lag codebook, as a function of center lag */\r
-\r
-    CCmax   = SKP_int32_MIN;\r
-    CCmax_b = SKP_int32_MIN;\r
-\r
-    CBimax = 0; /* To avoid returning undefined lag values */\r
-    lag = -1;   /* To check if lag with strong enough correlation has been found */\r
-\r
-    if( prevLag > 0 ) {\r
-        if( Fs_kHz == 12 ) {\r
-            prevLag = SKP_DIV32_16( SKP_LSHIFT( prevLag, 1 ), 3 );\r
-        } else if( Fs_kHz == 16 ) {\r
-            prevLag = SKP_RSHIFT( prevLag, 1 );\r
-        } else if( Fs_kHz == 24 ) {\r
-            prevLag = SKP_DIV32_16( prevLag, 3 );\r
-        }\r
-        prevLag_log2_Q7 = SKP_Silk_lin2log( (SKP_int32)prevLag );\r
-    } else {\r
-        prevLag_log2_Q7 = 0;\r
-    }\r
-    SKP_assert( search_thres2_Q15 == SKP_SAT16( search_thres2_Q15 ) );\r
-    corr_thres_Q15 = SKP_RSHIFT( SKP_SMULBB( search_thres2_Q15, search_thres2_Q15 ), 13 );\r
-\r
-    /* If input is 8 khz use a larger codebook here because it is last stage */\r
-    if( Fs_kHz == 8 && complexity > SKP_Silk_PITCH_EST_MIN_COMPLEX ) {\r
-        nb_cbks_stage2 = PITCH_EST_NB_CBKS_STAGE2_EXT;    \r
-    } else {\r
-        nb_cbks_stage2 = PITCH_EST_NB_CBKS_STAGE2;\r
-    }\r
-\r
-    for( k = 0; k < length_d_srch; k++ ) {\r
-        d = d_srch[ k ];\r
-        for( j = 0; j < nb_cbks_stage2; j++ ) {\r
-            CC[ j ] = 0;\r
-            for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) {\r
-                /* Try all codebooks */\r
-                CC[ j ] = CC[ j ] + (SKP_int32)C[ i ][ d + SKP_Silk_CB_lags_stage2[ i ][ j ] ];\r
-            }\r
-        }\r
-        /* Find best codebook */\r
-        CCmax_new = SKP_int32_MIN;\r
-        CBimax_new = 0;\r
-        for( i = 0; i < nb_cbks_stage2; i++ ) {\r
-            if( CC[ i ] > CCmax_new ) {\r
-                CCmax_new = CC[ i ];\r
-                CBimax_new = i;\r
-            }\r
-        }\r
-\r
-        /* Bias towards shorter lags */\r
-        lag_log2_Q7 = SKP_Silk_lin2log( (SKP_int32)d ); /* Q7 */\r
-           SKP_assert( lag_log2_Q7 == SKP_SAT16( lag_log2_Q7 ) );\r
-               SKP_assert( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15 == SKP_SAT16( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15 ) );\r
-\r
-               if (forLJC) {\r
-                       CCmax_new_b = CCmax_new;\r
-               } else {\r
-                       CCmax_new_b = CCmax_new - SKP_RSHIFT( SKP_SMULBB( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15, lag_log2_Q7 ), 7 ); /* Q15 */\r
-               }\r
-               \r
-        /* Bias towards previous lag */\r
-        SKP_assert( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15 == SKP_SAT16( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15 ) );\r
-        if( prevLag > 0 ) {\r
-            delta_lag_log2_sqr_Q7 = lag_log2_Q7 - prevLag_log2_Q7;\r
-            SKP_assert( delta_lag_log2_sqr_Q7 == SKP_SAT16( delta_lag_log2_sqr_Q7 ) );\r
-            delta_lag_log2_sqr_Q7 = SKP_RSHIFT( SKP_SMULBB( delta_lag_log2_sqr_Q7, delta_lag_log2_sqr_Q7 ), 7 );\r
-            prev_lag_bias_Q15 = SKP_RSHIFT( SKP_SMULBB( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15, ( *LTPCorr_Q15 ) ), 15 ); /* Q15 */\r
-            prev_lag_bias_Q15 = SKP_DIV32( SKP_MUL( prev_lag_bias_Q15, delta_lag_log2_sqr_Q7 ), delta_lag_log2_sqr_Q7 + ( 1 << 6 ) );\r
-            CCmax_new_b -= prev_lag_bias_Q15; /* Q15 */\r
-        }\r
-\r
-        if ( CCmax_new_b > CCmax_b                                          &&              /* Find maximum biased correlation                  */\r
-              CCmax_new > corr_thres_Q15                                    &&              /* Correlation needs to be high enough to be voiced */\r
-             SKP_Silk_CB_lags_stage2[ 0 ][ CBimax_new ] <= min_lag_8kHz                   /* Lag must be in range                             */\r
-            ) {\r
-            CCmax_b = CCmax_new_b;\r
-            CCmax   = CCmax_new;\r
-            lag     = d;\r
-            CBimax  = CBimax_new;\r
-        }\r
-    }\r
-\r
-    if( lag == -1 ) {\r
-        /* No suitable candidate found */\r
-        SKP_memset( pitch_out, 0, PITCH_EST_NB_SUBFR * sizeof( SKP_int ) );\r
-        *LTPCorr_Q15  = 0;\r
-        *lagIndex     = 0;\r
-        *contourIndex = 0;\r
-        return 1;\r
-    }\r
-\r
-    if( Fs_kHz > 8 ) {\r
-\r
-        /******************************************************************************\r
-        ** Scale input signal down to avoid correlations measures from overflowing\r
-        *******************************************************************************/\r
-        /* find scaling as max scaling for each subframe */\r
-        shift = SKP_FIX_P_Ana_find_scaling( signal, frame_length, sf_length );\r
-        if( shift > 0 ) {\r
-            /* Move signal to scratch mem because the input signal should be unchanged */\r
-            /* Reuse the 32 bit scratch mem vector, use a 16 bit pointer from now */\r
-            input_signal_ptr = (SKP_int16*)scratch_mem;\r
-            for( i = 0; i < frame_length; i++ ) {\r
-                input_signal_ptr[ i ] = SKP_RSHIFT( signal[ i ], shift );\r
-            }\r
-        } else {\r
-            input_signal_ptr = (SKP_int16*)signal;\r
-        }\r
-        /*********************************************************************************/\r
-\r
-        /* Search in original signal */\r
-                    \r
-        CBimax_old = CBimax;\r
-        /* Compensate for decimation */\r
-        SKP_assert( lag == SKP_SAT16( lag ) );\r
-        if( Fs_kHz == 12 ) {\r
-            lag = SKP_RSHIFT( SKP_SMULBB( lag, 3 ), 1 );\r
-        } else if( Fs_kHz == 16 ) {\r
-            lag = SKP_LSHIFT( lag, 1 );\r
-        } else {\r
-            lag = SKP_SMULBB( lag, 3 );\r
-        }\r
-\r
-        lag = SKP_LIMIT_int( lag, min_lag, max_lag );\r
-        start_lag = SKP_max_int( lag - 2, min_lag );\r
-        end_lag   = SKP_min_int( lag + 2, max_lag );\r
-        lag_new   = lag;                                    /* to avoid undefined lag */\r
-        CBimax    = 0;                                        /* to avoid undefined lag */\r
-        SKP_assert( SKP_LSHIFT( CCmax, 13 ) >= 0 ); \r
-        *LTPCorr_Q15 = (SKP_int)SKP_Silk_SQRT_APPROX( SKP_LSHIFT( CCmax, 13 ) ); /* Output normalized correlation */\r
-\r
-        CCmax = SKP_int32_MIN;\r
-        /* pitch lags according to second stage */\r
-        for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {\r
-            pitch_out[ k ] = lag + 2 * SKP_Silk_CB_lags_stage2[ k ][ CBimax_old ];\r
-        }\r
-        /* Calculate the correlations and energies needed in stage 3 */\r
-        SKP_FIX_P_Ana_calc_corr_st3(  crosscorr_st3, input_signal_ptr, start_lag, sf_length, complexity );\r
-        SKP_FIX_P_Ana_calc_energy_st3( energies_st3, input_signal_ptr, start_lag, sf_length, complexity );\r
-\r
-        lag_counter = 0;\r
-        SKP_assert( lag == SKP_SAT16( lag ) );\r
-        contour_bias = SKP_DIV32_16( PITCH_EST_FLATCONTOUR_BIAS_Q20, lag );\r
-\r
-        /* Setup cbk parameters acording to complexity setting */\r
-        cbk_size   = (SKP_int)SKP_Silk_cbk_sizes_stage3[   complexity ];\r
-        cbk_offset = (SKP_int)SKP_Silk_cbk_offsets_stage3[ complexity ];\r
-\r
-        for( d = start_lag; d <= end_lag; d++ ) {\r
-            for( j = cbk_offset; j < ( cbk_offset + cbk_size ); j++ ) {\r
-                cross_corr = 0;\r
-                energy     = 0;\r
-                for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {\r
-                    SKP_assert( PITCH_EST_NB_SUBFR == 4 );\r
-                    energy     += SKP_RSHIFT( energies_st3[  k ][ j ][ lag_counter ], 2 ); /* use mean, to avoid overflow */\r
-                    SKP_assert( energy >= 0 );\r
-                    cross_corr += SKP_RSHIFT( crosscorr_st3[ k ][ j ][ lag_counter ], 2 ); /* use mean, to avoid overflow */\r
-                }\r
-                if( cross_corr > 0 ) {\r
-                    /* Divide cross_corr / energy and get result in Q15 */\r
-                    lz = SKP_Silk_CLZ32( cross_corr );\r
-                    /* Divide with result in Q13, cross_corr could be larger than energy */\r
-                    lshift = SKP_LIMIT_32( lz - 1, 0, 13 );\r
-                    CCmax_new = SKP_DIV32( SKP_LSHIFT( cross_corr, lshift ), SKP_RSHIFT( energy, 13 - lshift ) + 1 );\r
-                    CCmax_new = SKP_SAT16( CCmax_new );\r
-                    CCmax_new = SKP_SMULWB( cross_corr, CCmax_new );\r
-                    /* Saturate */\r
-                    if( CCmax_new > SKP_RSHIFT( SKP_int32_MAX, 3 ) ) {\r
-                        CCmax_new = SKP_int32_MAX;\r
-                    } else {\r
-                        CCmax_new = SKP_LSHIFT( CCmax_new, 3 );\r
-                    }\r
-                    /* Reduce depending on flatness of contour */\r
-                    diff = j - SKP_RSHIFT( PITCH_EST_NB_CBKS_STAGE3_MAX, 1 );\r
-                    diff = SKP_MUL( diff, diff );\r
-                    diff = SKP_int16_MAX - SKP_RSHIFT( SKP_MUL( contour_bias, diff ), 5 ); /* Q20 -> Q15 */\r
-                    SKP_assert( diff == SKP_SAT16( diff ) );\r
-                    CCmax_new = SKP_LSHIFT( SKP_SMULWB( CCmax_new, diff ), 1 );\r
-                } else {\r
-                    CCmax_new = 0;\r
-                }\r
-\r
-                if( CCmax_new > CCmax                                               && \r
-                   ( d + (SKP_int)SKP_Silk_CB_lags_stage3[ 0 ][ j ] ) <= max_lag  \r
-                   ) {\r
-                    CCmax   = CCmax_new;\r
-                    lag_new = d;\r
-                    CBimax  = j;\r
-                }\r
-            }\r
-            lag_counter++;\r
-        }\r
-\r
-        for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {\r
-            pitch_out[ k ] = lag_new + SKP_Silk_CB_lags_stage3[ k ][ CBimax ];\r
-        }\r
-        *lagIndex = lag_new - min_lag;\r
-        *contourIndex = CBimax;\r
-    } else {\r
-        /* Save Lags and correlation */\r
-        CCmax = SKP_max( CCmax, 0 );\r
-        *LTPCorr_Q15 = (SKP_int)SKP_Silk_SQRT_APPROX( SKP_LSHIFT( CCmax, 13 ) ); /* Output normalized correlation */\r
-        for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {\r
-            pitch_out[ k ] = lag + SKP_Silk_CB_lags_stage2[ k ][ CBimax ];\r
-        }\r
-        *lagIndex = lag - min_lag_8kHz;\r
-        *contourIndex = CBimax;\r
-    }\r
-    SKP_assert( *lagIndex >= 0 );\r
-    /* return as voiced */\r
-    return 0;\r
-}\r
-\r
-/*************************************************************************/\r
-/* Calculates the correlations used in stage 3 search. In order to cover */\r
-/* the whole lag codebook for all the searched offset lags (lag +- 2),   */\r
-/*************************************************************************/\r
-void SKP_FIX_P_Ana_calc_corr_st3(\r
-    SKP_int32        cross_corr_st3[ PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ],/* (O) 3 DIM correlation array */\r
-    const SKP_int16  signal[],                        /* I vector to correlate         */\r
-    SKP_int          start_lag,                       /* I lag offset to search around */\r
-    SKP_int          sf_length,                       /* I length of a 5 ms subframe   */\r
-    SKP_int          complexity                       /* I Complexity setting          */\r
-)\r
-{\r
-    const SKP_int16 *target_ptr, *basis_ptr;\r
-    SKP_int32    cross_corr;\r
-    SKP_int        i, j, k, lag_counter;\r
-    SKP_int        cbk_offset, cbk_size, delta, idx;\r
-    SKP_int32    scratch_mem[ SCRATCH_SIZE ];\r
-\r
-    SKP_assert( complexity >= SKP_Silk_PITCH_EST_MIN_COMPLEX );\r
-    SKP_assert( complexity <= SKP_Silk_PITCH_EST_MAX_COMPLEX );\r
-\r
-    cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ];\r
-    cbk_size   = SKP_Silk_cbk_sizes_stage3[   complexity ];\r
-\r
-    target_ptr = &signal[ SKP_LSHIFT( sf_length, 2 ) ]; /* Pointer to middle of frame */\r
-    for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {\r
-        lag_counter = 0;\r
-\r
-        /* Calculate the correlations for each subframe */\r
-        for( j = SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ]; j <= SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 1 ]; j++ ) {\r
-            basis_ptr = target_ptr - ( start_lag + j );\r
-            cross_corr = SKP_Silk_inner_prod_aligned( (SKP_int16*)target_ptr, (SKP_int16*)basis_ptr, sf_length );\r
-            SKP_assert( lag_counter < SCRATCH_SIZE );\r
-            scratch_mem[ lag_counter ] = cross_corr;\r
-            lag_counter++;\r
-        }\r
-\r
-        delta = SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ];\r
-        for( i = cbk_offset; i < ( cbk_offset + cbk_size ); i++ ) { \r
-            /* Fill out the 3 dim array that stores the correlations for */\r
-            /* each code_book vector for each start lag */\r
-            idx = SKP_Silk_CB_lags_stage3[ k ][ i ] - delta;\r
-            for( j = 0; j < PITCH_EST_NB_STAGE3_LAGS; j++ ) {\r
-                SKP_assert( idx + j < SCRATCH_SIZE );\r
-                SKP_assert( idx + j < lag_counter );\r
-                cross_corr_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ];\r
-            }\r
-        }\r
-        target_ptr += sf_length;\r
-    }\r
-}\r
-\r
-/********************************************************************/\r
-/* Calculate the energies for first two subframes. The energies are */\r
-/* calculated recursively.                                          */\r
-/********************************************************************/\r
-void SKP_FIX_P_Ana_calc_energy_st3(\r
-    SKP_int32        energies_st3[ PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ],/* (O) 3 DIM energy array */\r
-    const SKP_int16  signal[],                        /* I vector to calc energy in    */\r
-    SKP_int          start_lag,                       /* I lag offset to search around */\r
-    SKP_int          sf_length,                       /* I length of one 5 ms subframe */\r
-    SKP_int          complexity                       /* I Complexity setting          */\r
-)\r
-{\r
-    const SKP_int16 *target_ptr, *basis_ptr;\r
-    SKP_int32    energy;\r
-    SKP_int        k, i, j, lag_counter;\r
-    SKP_int        cbk_offset, cbk_size, delta, idx;\r
-    SKP_int32    scratch_mem[ SCRATCH_SIZE ];\r
-\r
-    SKP_assert( complexity >= SKP_Silk_PITCH_EST_MIN_COMPLEX );\r
-    SKP_assert( complexity <= SKP_Silk_PITCH_EST_MAX_COMPLEX );\r
-\r
-    cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ];\r
-    cbk_size   = SKP_Silk_cbk_sizes_stage3[   complexity ];\r
-\r
-    target_ptr = &signal[ SKP_LSHIFT( sf_length, 2 ) ];\r
-    for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {\r
-        lag_counter = 0;\r
-\r
-        /* Calculate the energy for first lag */\r
-        basis_ptr = target_ptr - ( start_lag + SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ] );\r
-        energy = SKP_Silk_inner_prod_aligned( basis_ptr, basis_ptr, sf_length );\r
-        SKP_assert( energy >= 0 );\r
-        scratch_mem[ lag_counter ] = energy;\r
-        lag_counter++;\r
-\r
-        for( i = 1; i < ( SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 1 ] - SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ] + 1 ); i++ ) {\r
-            /* remove part outside new window */\r
-            energy -= SKP_SMULBB( basis_ptr[ sf_length - i ], basis_ptr[ sf_length - i ] );\r
-            SKP_assert( energy >= 0 );\r
-\r
-            /* add part that comes into window */\r
-            energy = SKP_ADD_SAT32( energy, SKP_SMULBB( basis_ptr[ -i ], basis_ptr[ -i ] ) );\r
-            SKP_assert( energy >= 0 );\r
-            SKP_assert( lag_counter < SCRATCH_SIZE );\r
-            scratch_mem[ lag_counter ] = energy;\r
-            lag_counter++;\r
-        }\r
-\r
-        delta = SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ];\r
-        for( i = cbk_offset; i < ( cbk_offset + cbk_size ); i++ ) { \r
-            /* Fill out the 3 dim array that stores the correlations for    */\r
-            /* each code_book vector for each start lag                        */\r
-            idx = SKP_Silk_CB_lags_stage3[ k ][ i ] - delta;\r
-            for( j = 0; j < PITCH_EST_NB_STAGE3_LAGS; j++ ) {\r
-                SKP_assert( idx + j < SCRATCH_SIZE );\r
-                SKP_assert( idx + j < lag_counter );\r
-                energies_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ];\r
-                SKP_assert( energies_st3[ k ][ i ][ j ] >= 0.0f );\r
-            }\r
-        }\r
-        target_ptr += sf_length;\r
-    }\r
-}\r
-\r
-SKP_int32 SKP_FIX_P_Ana_find_scaling(\r
-    const SKP_int16  *signal,\r
-    const SKP_int    signal_length, \r
-    const SKP_int    sum_sqr_len\r
-)\r
-{\r
-    SKP_int32 nbits, x_max;\r
-    \r
-    x_max = SKP_Silk_int16_array_maxabs( signal, signal_length );\r
-\r
-    if( x_max < SKP_int16_MAX ) {\r
-        /* Number of bits needed for the sum of the squares */\r
-        nbits = 32 - SKP_Silk_CLZ32( SKP_SMULBB( x_max, x_max ) ); \r
-    } else {\r
-        /* Here we don't know if x_max should have been SKP_int16_MAX + 1, so we expect the worst case */\r
-        nbits = 30;\r
-    }\r
-    nbits += 17 - SKP_Silk_CLZ16( sum_sqr_len );\r
-\r
-    /* Without a guarantee of saturation, we need to keep the 31st bit free */\r
-    if( nbits < 31 ) {\r
-        return 0;\r
-    } else {\r
-        return( nbits - 30 );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/***********************************************************
+* Pitch analyser function
+********************************************************** */
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_pitch_est_defines.h"
+#include "SKP_Silk_common_pitch_est_defines.h"
+
+#define SCRATCH_SIZE    22
+
+/************************************************************/
+/* Internally used functions                                */
+/************************************************************/
+void SKP_FIX_P_Ana_calc_corr_st3(
+    SKP_int32        cross_corr_st3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX][PITCH_EST_NB_STAGE3_LAGS],/* (O) 3 DIM correlation array */
+    const SKP_int16  signal[],                        /* I vector to correlate         */
+    SKP_int          start_lag,                       /* I lag offset to search around */
+    SKP_int          sf_length,                       /* I length of a 5 ms subframe   */
+    SKP_int          complexity                       /* I Complexity setting          */
+);
+
+void SKP_FIX_P_Ana_calc_energy_st3(
+    SKP_int32        energies_st3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX][PITCH_EST_NB_STAGE3_LAGS],/* (O) 3 DIM energy array */
+    const SKP_int16  signal[],                        /* I vector to calc energy in    */
+    SKP_int          start_lag,                       /* I lag offset to search around */
+    SKP_int          sf_length,                       /* I length of one 5 ms subframe */
+    SKP_int          complexity                       /* I Complexity setting          */
+);
+
+SKP_int32 SKP_FIX_P_Ana_find_scaling(
+    const SKP_int16  *signal,
+    const SKP_int    signal_length, 
+    const SKP_int    sum_sqr_len
+);
+
+/*************************************************************/
+/*      FIXED POINT CORE PITCH ANALYSIS FUNCTION             */
+/*************************************************************/
+SKP_int SKP_Silk_pitch_analysis_core(  /* O    Voicing estimate: 0 voiced, 1 unvoiced                      */
+    const SKP_int16  *signal,            /* I    Signal of length PITCH_EST_FRAME_LENGTH_MS*Fs_kHz           */
+    SKP_int          *pitch_out,         /* O    4 pitch lag values                                          */
+    SKP_int          *lagIndex,          /* O    Lag Index                                                   */
+    SKP_int          *contourIndex,      /* O    Pitch contour Index                                         */
+    SKP_int          *LTPCorr_Q15,       /* I/O  Normalized correlation; input: value from previous frame    */
+    SKP_int          prevLag,            /* I    Last lag of previous frame; set to zero is unvoiced         */
+    const SKP_int32  search_thres1_Q16,  /* I    First stage threshold for lag candidates 0 - 1              */
+    const SKP_int    search_thres2_Q15,  /* I    Final threshold for lag candidates 0 - 1                    */
+    const SKP_int    Fs_kHz,             /* I    Sample frequency (kHz)                                      */
+    const SKP_int    complexity,         /* I   Complexity setting, 0-2, where 2 is highest                 */
+       const SKP_int    forLJC                      /* I        1 if this function is called from LJC code, 0 otherwise.  */
+)
+{
+    SKP_int16 signal_8kHz[ PITCH_EST_MAX_FRAME_LENGTH_ST_2 ];
+    SKP_int16 signal_4kHz[ PITCH_EST_MAX_FRAME_LENGTH_ST_1 ];
+    SKP_int32 scratch_mem[ 3 * PITCH_EST_MAX_FRAME_LENGTH ];
+    SKP_int16 *input_signal_ptr;
+    SKP_int32 filt_state[ PITCH_EST_MAX_DECIMATE_STATE_LENGTH ];
+    SKP_int   i, k, d, j;
+    SKP_int16 C[ PITCH_EST_NB_SUBFR ][ ( PITCH_EST_MAX_LAG >> 1 ) + 5 ];
+    const SKP_int16 *target_ptr, *basis_ptr;
+    SKP_int32 cross_corr, normalizer, energy, shift, energy_basis, energy_target;
+    SKP_int   d_srch[ PITCH_EST_D_SRCH_LENGTH ];
+    SKP_int16 d_comp[ ( PITCH_EST_MAX_LAG >> 1 ) + 5 ];
+    SKP_int   Cmax, length_d_srch, length_d_comp;
+    SKP_int32 sum, threshold, temp32;
+    SKP_int   CBimax, CBimax_new, CBimax_old, lag, start_lag, end_lag, lag_new;
+    SKP_int32 CC[ PITCH_EST_NB_CBKS_STAGE2_EXT ], CCmax, CCmax_b, CCmax_new_b, CCmax_new;
+    SKP_int32 energies_st3[  PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ];
+    SKP_int32 crosscorr_st3[ PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ];
+    SKP_int32 lag_counter;
+    SKP_int   frame_length, frame_length_8kHz, frame_length_4kHz, max_sum_sq_length;
+    SKP_int   sf_length, sf_length_8kHz, sf_length_4kHz;
+    SKP_int   min_lag, min_lag_8kHz, min_lag_4kHz;
+    SKP_int   max_lag, max_lag_8kHz, max_lag_4kHz;
+    SKP_int32 contour_bias, diff;
+    SKP_int32 lz, lshift;
+    SKP_int   cbk_offset, cbk_size, nb_cbks_stage2;
+    SKP_int32 delta_lag_log2_sqr_Q7, lag_log2_Q7, prevLag_log2_Q7, prev_lag_bias_Q15, corr_thres_Q15;
+
+    /* Check for valid sampling frequency */
+    SKP_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 || Fs_kHz == 24 );
+
+    /* Check for valid complexity setting */
+    SKP_assert( complexity >= SKP_Silk_PITCH_EST_MIN_COMPLEX );
+    SKP_assert( complexity <= SKP_Silk_PITCH_EST_MAX_COMPLEX );
+
+    SKP_assert( search_thres1_Q16 >= 0 && search_thres1_Q16 <= (1<<16) );
+    SKP_assert( search_thres2_Q15 >= 0 && search_thres2_Q15 <= (1<<15) );
+
+    /* Setup frame lengths max / min lag for the sampling frequency */
+    frame_length      = PITCH_EST_FRAME_LENGTH_MS * Fs_kHz;
+    frame_length_4kHz = PITCH_EST_FRAME_LENGTH_MS * 4;
+    frame_length_8kHz = PITCH_EST_FRAME_LENGTH_MS * 8;
+    sf_length         = SKP_RSHIFT( frame_length,      3 );
+    sf_length_4kHz    = SKP_RSHIFT( frame_length_4kHz, 3 );
+    sf_length_8kHz    = SKP_RSHIFT( frame_length_8kHz, 3 );
+    min_lag           = PITCH_EST_MIN_LAG_MS * Fs_kHz;
+    min_lag_4kHz      = PITCH_EST_MIN_LAG_MS * 4;
+    min_lag_8kHz      = PITCH_EST_MIN_LAG_MS * 8;
+    max_lag           = PITCH_EST_MAX_LAG_MS * Fs_kHz;
+    max_lag_4kHz      = PITCH_EST_MAX_LAG_MS * 4;
+    max_lag_8kHz      = PITCH_EST_MAX_LAG_MS * 8;
+
+    SKP_memset( C, 0, sizeof( SKP_int16 ) * PITCH_EST_NB_SUBFR * ( ( PITCH_EST_MAX_LAG >> 1 ) + 5) );
+    
+    /* Resample from input sampled at Fs_kHz to 8 kHz */
+    if( Fs_kHz == 16 ) {
+        SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) );
+        SKP_Silk_resampler_down2( filt_state, signal_8kHz, signal, frame_length );
+    } else if ( Fs_kHz == 12 ) {
+        SKP_int32 R23[ 6 ];
+        SKP_memset( R23, 0, 6 * sizeof( SKP_int32 ) );
+        SKP_Silk_resampler_down2_3( R23, signal_8kHz, signal, PITCH_EST_FRAME_LENGTH_MS * 12 );
+    } else if( Fs_kHz == 24 ) {
+        SKP_int32 filt_state_fix[ 8 ];
+        SKP_memset( filt_state_fix, 0, 8 * sizeof(SKP_int32) );
+        SKP_Silk_resampler_down3( filt_state_fix, signal_8kHz, signal, 24 * PITCH_EST_FRAME_LENGTH_MS );
+    } else {
+        SKP_assert( Fs_kHz == 8 );
+        SKP_memcpy( signal_8kHz, signal, frame_length_8kHz * sizeof(SKP_int16) );
+    }
+    /* Decimate again to 4 kHz */
+    SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) );/* Set state to zero */
+    SKP_Silk_resampler_down2( filt_state, signal_4kHz, signal_8kHz, frame_length_8kHz );
+
+    /* Low-pass filter */
+    for( i = frame_length_4kHz - 1; i > 0; i-- ) {
+        signal_4kHz[ i ] = SKP_ADD_SAT16( signal_4kHz[ i ], signal_4kHz[ i - 1 ] );
+    }
+
+    /*******************************************************************************
+    ** Scale 4 kHz signal down to prevent correlations measures from overflowing
+    ** find scaling as max scaling for each 8kHz(?) subframe
+    *******************************************************************************/
+    
+    /* Inner product is calculated with different lengths, so scale for the worst case */
+    max_sum_sq_length = SKP_max_32( sf_length_8kHz, SKP_RSHIFT( frame_length_4kHz, 1 ) );
+    shift = SKP_FIX_P_Ana_find_scaling( signal_4kHz, frame_length_4kHz, max_sum_sq_length );
+    if( shift > 0 ) {
+        for( i = 0; i < frame_length_4kHz; i++ ) {
+            signal_4kHz[ i ] = SKP_RSHIFT( signal_4kHz[ i ], shift );
+        }
+    }
+
+    /******************************************************************************
+    * FIRST STAGE, operating in 4 khz
+    ******************************************************************************/
+    target_ptr = &signal_4kHz[ SKP_RSHIFT( frame_length_4kHz, 1 ) ];
+    for( k = 0; k < 2; k++ ) {
+        /* Check that we are within range of the array */
+        SKP_assert( target_ptr >= signal_4kHz );
+        SKP_assert( target_ptr + sf_length_8kHz <= signal_4kHz + frame_length_4kHz );
+
+        basis_ptr = target_ptr - min_lag_4kHz;
+
+        /* Check that we are within range of the array */
+        SKP_assert( basis_ptr >= signal_4kHz );
+        SKP_assert( basis_ptr + sf_length_8kHz <= signal_4kHz + frame_length_4kHz );
+
+        normalizer = 0;
+        cross_corr = 0;
+        /* Calculate first vector products before loop */
+        cross_corr = SKP_Silk_inner_prod_aligned( target_ptr, basis_ptr, sf_length_8kHz );
+        normalizer = SKP_Silk_inner_prod_aligned( basis_ptr,  basis_ptr, sf_length_8kHz );
+        normalizer = SKP_ADD_SAT32( normalizer, SKP_SMULBB( sf_length_8kHz, 4000 ) );
+
+        temp32 = SKP_DIV32( cross_corr, SKP_Silk_SQRT_APPROX( normalizer ) + 1 );
+        C[ k ][ min_lag_4kHz ] = (SKP_int16)SKP_SAT16( temp32 );        /* Q0 */
+
+        /* From now on normalizer is computed recursively */
+        for( d = min_lag_4kHz + 1; d <= max_lag_4kHz; d++ ) {
+            basis_ptr--;
+
+            /* Check that we are within range of the array */
+            SKP_assert( basis_ptr >= signal_4kHz );
+            SKP_assert( basis_ptr + sf_length_8kHz <= signal_4kHz + frame_length_4kHz );
+
+            cross_corr = SKP_Silk_inner_prod_aligned( target_ptr, basis_ptr, sf_length_8kHz );
+
+            /* Add contribution of new sample and remove contribution from oldest sample */
+            normalizer +=
+                SKP_SMULBB( basis_ptr[ 0 ], basis_ptr[ 0 ] ) - 
+                SKP_SMULBB( basis_ptr[ sf_length_8kHz ], basis_ptr[ sf_length_8kHz ] ); 
+    
+            temp32 = SKP_DIV32( cross_corr, SKP_Silk_SQRT_APPROX( normalizer ) + 1 );
+            C[ k ][ d ] = (SKP_int16)SKP_SAT16( temp32 );                        /* Q0 */
+        }
+        /* Update target pointer */
+        target_ptr += sf_length_8kHz;
+    }
+
+    /* Combine two subframes into single correlation measure and apply short-lag bias */
+    for( i = max_lag_4kHz; i >= min_lag_4kHz; i-- ) {
+        sum = (SKP_int32)C[ 0 ][ i ] + (SKP_int32)C[ 1 ][ i ];                /* Q0 */
+        SKP_assert( SKP_RSHIFT( sum, 1 ) == SKP_SAT16( SKP_RSHIFT( sum, 1 ) ) );
+        sum = SKP_RSHIFT( sum, 1 );                                           /* Q-1 */
+        SKP_assert( SKP_LSHIFT( (SKP_int32)-i, 4 ) == SKP_SAT16( SKP_LSHIFT( (SKP_int32)-i, 4 ) ) );
+        sum = SKP_SMLAWB( sum, sum, SKP_LSHIFT( -i, 4 ) );                    /* Q-1 */
+        SKP_assert( sum == SKP_SAT16( sum ) );
+        C[ 0 ][ i ] = (SKP_int16)sum;                                         /* Q-1 */
+    }
+
+    /* Sort */
+    length_d_srch = 4 + 2 * complexity;
+    SKP_assert( 3 * length_d_srch <= PITCH_EST_D_SRCH_LENGTH );
+    SKP_Silk_insertion_sort_decreasing_int16( &C[ 0 ][ min_lag_4kHz ], d_srch, max_lag_4kHz - min_lag_4kHz + 1, length_d_srch );
+
+    /* Escape if correlation is very low already here */
+    target_ptr = &signal_4kHz[ SKP_RSHIFT( frame_length_4kHz, 1 ) ];
+    energy = SKP_Silk_inner_prod_aligned( target_ptr, target_ptr, SKP_RSHIFT( frame_length_4kHz, 1 ) );
+    energy = SKP_ADD_POS_SAT32( energy, 1000 );                              /* Q0 */
+    Cmax = (SKP_int)C[ 0 ][ min_lag_4kHz ];                                  /* Q-1 */
+    threshold = SKP_SMULBB( Cmax, Cmax );                                    /* Q-2 */
+    /* Compare in Q-2 domain */
+    if( SKP_RSHIFT( energy, 4 + 2 ) > threshold ) {                            
+        SKP_memset( pitch_out, 0, PITCH_EST_NB_SUBFR * sizeof( SKP_int ) );
+        *LTPCorr_Q15  = 0;
+        *lagIndex     = 0;
+        *contourIndex = 0;
+        return 1;
+    }
+
+    threshold = SKP_SMULWB( search_thres1_Q16, Cmax );
+    for( i = 0; i < length_d_srch; i++ ) {
+        /* Convert to 8 kHz indices for the sorted correlation that exceeds the threshold */
+        if( C[ 0 ][ min_lag_4kHz + i ] > threshold ) {
+            d_srch[ i ] = SKP_LSHIFT( d_srch[ i ] + min_lag_4kHz, 1 );
+        } else {
+            length_d_srch = i;
+            break;
+        }
+    }
+    SKP_assert( length_d_srch > 0 );
+
+    for( i = min_lag_8kHz - 5; i < max_lag_8kHz + 5; i++ ) {
+        d_comp[ i ] = 0;
+    }
+    for( i = 0; i < length_d_srch; i++ ) {
+        d_comp[ d_srch[ i ] ] = 1;
+    }
+
+    /* Convolution */
+    for( i = max_lag_8kHz + 3; i >= min_lag_8kHz; i-- ) {
+        d_comp[ i ] += d_comp[ i - 1 ] + d_comp[ i - 2 ];
+    }
+
+    length_d_srch = 0;
+    for( i = min_lag_8kHz; i < max_lag_8kHz + 1; i++ ) {    
+        if( d_comp[ i + 1 ] > 0 ) {
+            d_srch[ length_d_srch ] = i;
+            length_d_srch++;
+        }
+    }
+
+    /* Convolution */
+    for( i = max_lag_8kHz + 3; i >= min_lag_8kHz; i-- ) {
+        d_comp[ i ] += d_comp[ i - 1 ] + d_comp[ i - 2 ] + d_comp[ i - 3 ];
+    }
+
+    length_d_comp = 0;
+    for( i = min_lag_8kHz; i < max_lag_8kHz + 4; i++ ) {    
+        if( d_comp[ i ] > 0 ) {
+            d_comp[ length_d_comp ] = i - 2;
+            length_d_comp++;
+        }
+    }
+
+    /**********************************************************************************
+    ** SECOND STAGE, operating at 8 kHz, on lag sections with high correlation
+    *************************************************************************************/
+
+    /******************************************************************************
+    ** Scale signal down to avoid correlations measures from overflowing
+    *******************************************************************************/
+    /* find scaling as max scaling for each subframe */
+    shift = SKP_FIX_P_Ana_find_scaling( signal_8kHz, frame_length_8kHz, sf_length_8kHz );
+    if( shift > 0 ) {
+        for( i = 0; i < frame_length_8kHz; i++ ) {
+            signal_8kHz[ i ] = SKP_RSHIFT( signal_8kHz[ i ], shift );
+        }
+    }
+
+    /********************************************************************************* 
+    * Find energy of each subframe projected onto its history, for a range of delays
+    *********************************************************************************/
+    SKP_memset( C, 0, PITCH_EST_NB_SUBFR * ( ( PITCH_EST_MAX_LAG >> 1 ) + 5 ) * sizeof( SKP_int16 ) );
+    
+    target_ptr = &signal_8kHz[ frame_length_4kHz ]; /* point to middle of frame */
+    for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {
+
+        /* Check that we are within range of the array */
+        SKP_assert( target_ptr >= signal_8kHz );
+        SKP_assert( target_ptr + sf_length_8kHz <= signal_8kHz + frame_length_8kHz );
+
+        energy_target = SKP_Silk_inner_prod_aligned( target_ptr, target_ptr, sf_length_8kHz );
+        // ToDo: Calculate 1 / energy_target here and save one division inside next for loop
+        for( j = 0; j < length_d_comp; j++ ) {
+            d = d_comp[ j ];
+            basis_ptr = target_ptr - d;
+
+            /* Check that we are within range of the array */
+            SKP_assert( basis_ptr >= signal_8kHz );
+            SKP_assert( basis_ptr + sf_length_8kHz <= signal_8kHz + frame_length_8kHz );
+        
+            cross_corr   = SKP_Silk_inner_prod_aligned( target_ptr, basis_ptr, sf_length_8kHz );
+            energy_basis = SKP_Silk_inner_prod_aligned( basis_ptr,  basis_ptr, sf_length_8kHz );
+            if( cross_corr > 0 ) {
+                energy = SKP_max( energy_target, energy_basis ); /* Find max to make sure first division < 1.0 */
+                lz = SKP_Silk_CLZ32( cross_corr );
+                lshift = SKP_LIMIT_32( lz - 1, 0, 15 );
+                temp32 = SKP_DIV32( SKP_LSHIFT( cross_corr, lshift ), SKP_RSHIFT( energy, 15 - lshift ) + 1 ); /* Q15 */
+                SKP_assert( temp32 == SKP_SAT16( temp32 ) );
+                temp32 = SKP_SMULWB( cross_corr, temp32 ); /* Q(-1), cc * ( cc / max(b, t) ) */
+                temp32 = SKP_ADD_SAT32( temp32, temp32 );  /* Q(0) */
+                lz = SKP_Silk_CLZ32( temp32 );
+                lshift = SKP_LIMIT_32( lz - 1, 0, 15 );
+                energy = SKP_min( energy_target, energy_basis );
+                C[ k ][ d ] = SKP_DIV32( SKP_LSHIFT( temp32, lshift ), SKP_RSHIFT( energy, 15 - lshift ) + 1 ); // Q15
+            } else {
+                C[ k ][ d ] = 0;
+            }
+        }
+        target_ptr += sf_length_8kHz;
+    }
+
+    /* search over lag range and lags codebook */
+    /* scale factor for lag codebook, as a function of center lag */
+
+    CCmax   = SKP_int32_MIN;
+    CCmax_b = SKP_int32_MIN;
+
+    CBimax = 0; /* To avoid returning undefined lag values */
+    lag = -1;   /* To check if lag with strong enough correlation has been found */
+
+    if( prevLag > 0 ) {
+        if( Fs_kHz == 12 ) {
+            prevLag = SKP_DIV32_16( SKP_LSHIFT( prevLag, 1 ), 3 );
+        } else if( Fs_kHz == 16 ) {
+            prevLag = SKP_RSHIFT( prevLag, 1 );
+        } else if( Fs_kHz == 24 ) {
+            prevLag = SKP_DIV32_16( prevLag, 3 );
+        }
+        prevLag_log2_Q7 = SKP_Silk_lin2log( (SKP_int32)prevLag );
+    } else {
+        prevLag_log2_Q7 = 0;
+    }
+    SKP_assert( search_thres2_Q15 == SKP_SAT16( search_thres2_Q15 ) );
+    corr_thres_Q15 = SKP_RSHIFT( SKP_SMULBB( search_thres2_Q15, search_thres2_Q15 ), 13 );
+
+    /* If input is 8 khz use a larger codebook here because it is last stage */
+    if( Fs_kHz == 8 && complexity > SKP_Silk_PITCH_EST_MIN_COMPLEX ) {
+        nb_cbks_stage2 = PITCH_EST_NB_CBKS_STAGE2_EXT;    
+    } else {
+        nb_cbks_stage2 = PITCH_EST_NB_CBKS_STAGE2;
+    }
+
+    for( k = 0; k < length_d_srch; k++ ) {
+        d = d_srch[ k ];
+        for( j = 0; j < nb_cbks_stage2; j++ ) {
+            CC[ j ] = 0;
+            for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) {
+                /* Try all codebooks */
+                CC[ j ] = CC[ j ] + (SKP_int32)C[ i ][ d + SKP_Silk_CB_lags_stage2[ i ][ j ] ];
+            }
+        }
+        /* Find best codebook */
+        CCmax_new = SKP_int32_MIN;
+        CBimax_new = 0;
+        for( i = 0; i < nb_cbks_stage2; i++ ) {
+            if( CC[ i ] > CCmax_new ) {
+                CCmax_new = CC[ i ];
+                CBimax_new = i;
+            }
+        }
+
+        /* Bias towards shorter lags */
+        lag_log2_Q7 = SKP_Silk_lin2log( (SKP_int32)d ); /* Q7 */
+           SKP_assert( lag_log2_Q7 == SKP_SAT16( lag_log2_Q7 ) );
+               SKP_assert( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15 == SKP_SAT16( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15 ) );
+
+               if (forLJC) {
+                       CCmax_new_b = CCmax_new;
+               } else {
+                       CCmax_new_b = CCmax_new - SKP_RSHIFT( SKP_SMULBB( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15, lag_log2_Q7 ), 7 ); /* Q15 */
+               }
+               
+        /* Bias towards previous lag */
+        SKP_assert( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15 == SKP_SAT16( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15 ) );
+        if( prevLag > 0 ) {
+            delta_lag_log2_sqr_Q7 = lag_log2_Q7 - prevLag_log2_Q7;
+            SKP_assert( delta_lag_log2_sqr_Q7 == SKP_SAT16( delta_lag_log2_sqr_Q7 ) );
+            delta_lag_log2_sqr_Q7 = SKP_RSHIFT( SKP_SMULBB( delta_lag_log2_sqr_Q7, delta_lag_log2_sqr_Q7 ), 7 );
+            prev_lag_bias_Q15 = SKP_RSHIFT( SKP_SMULBB( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15, ( *LTPCorr_Q15 ) ), 15 ); /* Q15 */
+            prev_lag_bias_Q15 = SKP_DIV32( SKP_MUL( prev_lag_bias_Q15, delta_lag_log2_sqr_Q7 ), delta_lag_log2_sqr_Q7 + ( 1 << 6 ) );
+            CCmax_new_b -= prev_lag_bias_Q15; /* Q15 */
+        }
+
+        if ( CCmax_new_b > CCmax_b                                          &&              /* Find maximum biased correlation                  */
+              CCmax_new > corr_thres_Q15                                    &&              /* Correlation needs to be high enough to be voiced */
+             SKP_Silk_CB_lags_stage2[ 0 ][ CBimax_new ] <= min_lag_8kHz                   /* Lag must be in range                             */
+            ) {
+            CCmax_b = CCmax_new_b;
+            CCmax   = CCmax_new;
+            lag     = d;
+            CBimax  = CBimax_new;
+        }
+    }
+
+    if( lag == -1 ) {
+        /* No suitable candidate found */
+        SKP_memset( pitch_out, 0, PITCH_EST_NB_SUBFR * sizeof( SKP_int ) );
+        *LTPCorr_Q15  = 0;
+        *lagIndex     = 0;
+        *contourIndex = 0;
+        return 1;
+    }
+
+    if( Fs_kHz > 8 ) {
+
+        /******************************************************************************
+        ** Scale input signal down to avoid correlations measures from overflowing
+        *******************************************************************************/
+        /* find scaling as max scaling for each subframe */
+        shift = SKP_FIX_P_Ana_find_scaling( signal, frame_length, sf_length );
+        if( shift > 0 ) {
+            /* Move signal to scratch mem because the input signal should be unchanged */
+            /* Reuse the 32 bit scratch mem vector, use a 16 bit pointer from now */
+            input_signal_ptr = (SKP_int16*)scratch_mem;
+            for( i = 0; i < frame_length; i++ ) {
+                input_signal_ptr[ i ] = SKP_RSHIFT( signal[ i ], shift );
+            }
+        } else {
+            input_signal_ptr = (SKP_int16*)signal;
+        }
+        /*********************************************************************************/
+
+        /* Search in original signal */
+                    
+        CBimax_old = CBimax;
+        /* Compensate for decimation */
+        SKP_assert( lag == SKP_SAT16( lag ) );
+        if( Fs_kHz == 12 ) {
+            lag = SKP_RSHIFT( SKP_SMULBB( lag, 3 ), 1 );
+        } else if( Fs_kHz == 16 ) {
+            lag = SKP_LSHIFT( lag, 1 );
+        } else {
+            lag = SKP_SMULBB( lag, 3 );
+        }
+
+        lag = SKP_LIMIT_int( lag, min_lag, max_lag );
+        start_lag = SKP_max_int( lag - 2, min_lag );
+        end_lag   = SKP_min_int( lag + 2, max_lag );
+        lag_new   = lag;                                    /* to avoid undefined lag */
+        CBimax    = 0;                                        /* to avoid undefined lag */
+        SKP_assert( SKP_LSHIFT( CCmax, 13 ) >= 0 ); 
+        *LTPCorr_Q15 = (SKP_int)SKP_Silk_SQRT_APPROX( SKP_LSHIFT( CCmax, 13 ) ); /* Output normalized correlation */
+
+        CCmax = SKP_int32_MIN;
+        /* pitch lags according to second stage */
+        for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {
+            pitch_out[ k ] = lag + 2 * SKP_Silk_CB_lags_stage2[ k ][ CBimax_old ];
+        }
+        /* Calculate the correlations and energies needed in stage 3 */
+        SKP_FIX_P_Ana_calc_corr_st3(  crosscorr_st3, input_signal_ptr, start_lag, sf_length, complexity );
+        SKP_FIX_P_Ana_calc_energy_st3( energies_st3, input_signal_ptr, start_lag, sf_length, complexity );
+
+        lag_counter = 0;
+        SKP_assert( lag == SKP_SAT16( lag ) );
+        contour_bias = SKP_DIV32_16( PITCH_EST_FLATCONTOUR_BIAS_Q20, lag );
+
+        /* Setup cbk parameters acording to complexity setting */
+        cbk_size   = (SKP_int)SKP_Silk_cbk_sizes_stage3[   complexity ];
+        cbk_offset = (SKP_int)SKP_Silk_cbk_offsets_stage3[ complexity ];
+
+        for( d = start_lag; d <= end_lag; d++ ) {
+            for( j = cbk_offset; j < ( cbk_offset + cbk_size ); j++ ) {
+                cross_corr = 0;
+                energy     = 0;
+                for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {
+                    SKP_assert( PITCH_EST_NB_SUBFR == 4 );
+                    energy     += SKP_RSHIFT( energies_st3[  k ][ j ][ lag_counter ], 2 ); /* use mean, to avoid overflow */
+                    SKP_assert( energy >= 0 );
+                    cross_corr += SKP_RSHIFT( crosscorr_st3[ k ][ j ][ lag_counter ], 2 ); /* use mean, to avoid overflow */
+                }
+                if( cross_corr > 0 ) {
+                    /* Divide cross_corr / energy and get result in Q15 */
+                    lz = SKP_Silk_CLZ32( cross_corr );
+                    /* Divide with result in Q13, cross_corr could be larger than energy */
+                    lshift = SKP_LIMIT_32( lz - 1, 0, 13 );
+                    CCmax_new = SKP_DIV32( SKP_LSHIFT( cross_corr, lshift ), SKP_RSHIFT( energy, 13 - lshift ) + 1 );
+                    CCmax_new = SKP_SAT16( CCmax_new );
+                    CCmax_new = SKP_SMULWB( cross_corr, CCmax_new );
+                    /* Saturate */
+                    if( CCmax_new > SKP_RSHIFT( SKP_int32_MAX, 3 ) ) {
+                        CCmax_new = SKP_int32_MAX;
+                    } else {
+                        CCmax_new = SKP_LSHIFT( CCmax_new, 3 );
+                    }
+                    /* Reduce depending on flatness of contour */
+                    diff = j - SKP_RSHIFT( PITCH_EST_NB_CBKS_STAGE3_MAX, 1 );
+                    diff = SKP_MUL( diff, diff );
+                    diff = SKP_int16_MAX - SKP_RSHIFT( SKP_MUL( contour_bias, diff ), 5 ); /* Q20 -> Q15 */
+                    SKP_assert( diff == SKP_SAT16( diff ) );
+                    CCmax_new = SKP_LSHIFT( SKP_SMULWB( CCmax_new, diff ), 1 );
+                } else {
+                    CCmax_new = 0;
+                }
+
+                if( CCmax_new > CCmax                                               && 
+                   ( d + (SKP_int)SKP_Silk_CB_lags_stage3[ 0 ][ j ] ) <= max_lag  
+                   ) {
+                    CCmax   = CCmax_new;
+                    lag_new = d;
+                    CBimax  = j;
+                }
+            }
+            lag_counter++;
+        }
+
+        for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {
+            pitch_out[ k ] = lag_new + SKP_Silk_CB_lags_stage3[ k ][ CBimax ];
+        }
+        *lagIndex = lag_new - min_lag;
+        *contourIndex = CBimax;
+    } else {
+        /* Save Lags and correlation */
+        CCmax = SKP_max( CCmax, 0 );
+        *LTPCorr_Q15 = (SKP_int)SKP_Silk_SQRT_APPROX( SKP_LSHIFT( CCmax, 13 ) ); /* Output normalized correlation */
+        for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {
+            pitch_out[ k ] = lag + SKP_Silk_CB_lags_stage2[ k ][ CBimax ];
+        }
+        *lagIndex = lag - min_lag_8kHz;
+        *contourIndex = CBimax;
+    }
+    SKP_assert( *lagIndex >= 0 );
+    /* return as voiced */
+    return 0;
+}
+
+/*************************************************************************/
+/* Calculates the correlations used in stage 3 search. In order to cover */
+/* the whole lag codebook for all the searched offset lags (lag +- 2),   */
+/*************************************************************************/
+void SKP_FIX_P_Ana_calc_corr_st3(
+    SKP_int32        cross_corr_st3[ PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ],/* (O) 3 DIM correlation array */
+    const SKP_int16  signal[],                        /* I vector to correlate         */
+    SKP_int          start_lag,                       /* I lag offset to search around */
+    SKP_int          sf_length,                       /* I length of a 5 ms subframe   */
+    SKP_int          complexity                       /* I Complexity setting          */
+)
+{
+    const SKP_int16 *target_ptr, *basis_ptr;
+    SKP_int32    cross_corr;
+    SKP_int        i, j, k, lag_counter;
+    SKP_int        cbk_offset, cbk_size, delta, idx;
+    SKP_int32    scratch_mem[ SCRATCH_SIZE ];
+
+    SKP_assert( complexity >= SKP_Silk_PITCH_EST_MIN_COMPLEX );
+    SKP_assert( complexity <= SKP_Silk_PITCH_EST_MAX_COMPLEX );
+
+    cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ];
+    cbk_size   = SKP_Silk_cbk_sizes_stage3[   complexity ];
+
+    target_ptr = &signal[ SKP_LSHIFT( sf_length, 2 ) ]; /* Pointer to middle of frame */
+    for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {
+        lag_counter = 0;
+
+        /* Calculate the correlations for each subframe */
+        for( j = SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ]; j <= SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 1 ]; j++ ) {
+            basis_ptr = target_ptr - ( start_lag + j );
+            cross_corr = SKP_Silk_inner_prod_aligned( (SKP_int16*)target_ptr, (SKP_int16*)basis_ptr, sf_length );
+            SKP_assert( lag_counter < SCRATCH_SIZE );
+            scratch_mem[ lag_counter ] = cross_corr;
+            lag_counter++;
+        }
+
+        delta = SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ];
+        for( i = cbk_offset; i < ( cbk_offset + cbk_size ); i++ ) { 
+            /* Fill out the 3 dim array that stores the correlations for */
+            /* each code_book vector for each start lag */
+            idx = SKP_Silk_CB_lags_stage3[ k ][ i ] - delta;
+            for( j = 0; j < PITCH_EST_NB_STAGE3_LAGS; j++ ) {
+                SKP_assert( idx + j < SCRATCH_SIZE );
+                SKP_assert( idx + j < lag_counter );
+                cross_corr_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ];
+            }
+        }
+        target_ptr += sf_length;
+    }
+}
+
+/********************************************************************/
+/* Calculate the energies for first two subframes. The energies are */
+/* calculated recursively.                                          */
+/********************************************************************/
+void SKP_FIX_P_Ana_calc_energy_st3(
+    SKP_int32        energies_st3[ PITCH_EST_NB_SUBFR ][ PITCH_EST_NB_CBKS_STAGE3_MAX ][ PITCH_EST_NB_STAGE3_LAGS ],/* (O) 3 DIM energy array */
+    const SKP_int16  signal[],                        /* I vector to calc energy in    */
+    SKP_int          start_lag,                       /* I lag offset to search around */
+    SKP_int          sf_length,                       /* I length of one 5 ms subframe */
+    SKP_int          complexity                       /* I Complexity setting          */
+)
+{
+    const SKP_int16 *target_ptr, *basis_ptr;
+    SKP_int32    energy;
+    SKP_int        k, i, j, lag_counter;
+    SKP_int        cbk_offset, cbk_size, delta, idx;
+    SKP_int32    scratch_mem[ SCRATCH_SIZE ];
+
+    SKP_assert( complexity >= SKP_Silk_PITCH_EST_MIN_COMPLEX );
+    SKP_assert( complexity <= SKP_Silk_PITCH_EST_MAX_COMPLEX );
+
+    cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ];
+    cbk_size   = SKP_Silk_cbk_sizes_stage3[   complexity ];
+
+    target_ptr = &signal[ SKP_LSHIFT( sf_length, 2 ) ];
+    for( k = 0; k < PITCH_EST_NB_SUBFR; k++ ) {
+        lag_counter = 0;
+
+        /* Calculate the energy for first lag */
+        basis_ptr = target_ptr - ( start_lag + SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ] );
+        energy = SKP_Silk_inner_prod_aligned( basis_ptr, basis_ptr, sf_length );
+        SKP_assert( energy >= 0 );
+        scratch_mem[ lag_counter ] = energy;
+        lag_counter++;
+
+        for( i = 1; i < ( SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 1 ] - SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ] + 1 ); i++ ) {
+            /* remove part outside new window */
+            energy -= SKP_SMULBB( basis_ptr[ sf_length - i ], basis_ptr[ sf_length - i ] );
+            SKP_assert( energy >= 0 );
+
+            /* add part that comes into window */
+            energy = SKP_ADD_SAT32( energy, SKP_SMULBB( basis_ptr[ -i ], basis_ptr[ -i ] ) );
+            SKP_assert( energy >= 0 );
+            SKP_assert( lag_counter < SCRATCH_SIZE );
+            scratch_mem[ lag_counter ] = energy;
+            lag_counter++;
+        }
+
+        delta = SKP_Silk_Lag_range_stage3[ complexity ][ k ][ 0 ];
+        for( i = cbk_offset; i < ( cbk_offset + cbk_size ); i++ ) { 
+            /* Fill out the 3 dim array that stores the correlations for    */
+            /* each code_book vector for each start lag                        */
+            idx = SKP_Silk_CB_lags_stage3[ k ][ i ] - delta;
+            for( j = 0; j < PITCH_EST_NB_STAGE3_LAGS; j++ ) {
+                SKP_assert( idx + j < SCRATCH_SIZE );
+                SKP_assert( idx + j < lag_counter );
+                energies_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ];
+                SKP_assert( energies_st3[ k ][ i ][ j ] >= 0.0f );
+            }
+        }
+        target_ptr += sf_length;
+    }
+}
+
+SKP_int32 SKP_FIX_P_Ana_find_scaling(
+    const SKP_int16  *signal,
+    const SKP_int    signal_length, 
+    const SKP_int    sum_sqr_len
+)
+{
+    SKP_int32 nbits, x_max;
+    
+    x_max = SKP_Silk_int16_array_maxabs( signal, signal_length );
+
+    if( x_max < SKP_int16_MAX ) {
+        /* Number of bits needed for the sum of the squares */
+        nbits = 32 - SKP_Silk_CLZ32( SKP_SMULBB( x_max, x_max ) ); 
+    } else {
+        /* Here we don't know if x_max should have been SKP_int16_MAX + 1, so we expect the worst case */
+        nbits = 30;
+    }
+    nbits += 17 - SKP_Silk_CLZ16( sum_sqr_len );
+
+    /* Without a guarantee of saturation, we need to keep the 31st bit free */
+    if( nbits < 31 ) {
+        return 0;
+    } else {
+        return( nbits - 30 );
+    }
+}
index 5f1c456958a1e3eaca78df34a6c240b2cfad45d7..5397ce2745b93ccc38a5de3432c675fcb3a23175 100644 (file)
@@ -1,40 +1,40 @@
-/***********************************************************************\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
-#ifndef SIGPROCFIX_PITCH_EST_DEFINES_H\r
-#define SIGPROCFIX_PITCH_EST_DEFINES_H\r
-\r
-/************************************************************/\r
-/* Definitions For Fix pitch estimator                      */\r
-/************************************************************/\r
-\r
-#define PITCH_EST_SHORTLAG_BIAS_Q15         6554    /* 0.2f. for logarithmic weighting    */\r
-#define PITCH_EST_PREVLAG_BIAS_Q15          6554    /* Prev lag bias    */\r
-#define PITCH_EST_FLATCONTOUR_BIAS_Q20      52429   /* 0.05f */\r
-\r
-#endif\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SIGPROCFIX_PITCH_EST_DEFINES_H
+#define SIGPROCFIX_PITCH_EST_DEFINES_H
+
+/************************************************************/
+/* Definitions For Fix pitch estimator                      */
+/************************************************************/
+
+#define PITCH_EST_SHORTLAG_BIAS_Q15         6554    /* 0.2f. for logarithmic weighting    */
+#define PITCH_EST_PREVLAG_BIAS_Q15          6554    /* Prev lag bias    */
+#define PITCH_EST_FLATCONTOUR_BIAS_Q20      52429   /* 0.05f */
+
+#endif
+
index 6ff96a77177f0b46017a349b4f28ecc9a47dd3b8..d281849aae9239ba1ed8f31c4937ba38f22415fd 100644 (file)
@@ -1,89 +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_typedef.h"\r
-#include "SKP_Silk_common_pitch_est_defines.h"\r
-\r
-/********************************************************/\r
-/* Auto Generated File from generate_pitch_est_tables.m */\r
-/********************************************************/\r
-\r
-const SKP_int16 SKP_Silk_CB_lags_stage2[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE2_EXT] =\r
-{\r
-    {0, 2,-1,-1,-1, 0, 0, 1, 1, 0, 1},\r
-    {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0},\r
-    {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0},\r
-    {0,-1, 2, 1, 0, 1, 1, 0, 0,-1,-1} \r
-};\r
-\r
-const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX] =\r
-{\r
-    {-9,-7,-6,-5,-5,-4,-4,-3,-3,-2,-2,-2,-1,-1,-1, 0, 0, 0, 1, 1, 0, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 5, 6, 8},\r
-    {-3,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0,-1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 2, 1, 2, 2, 2, 2, 3},\r
-    { 3, 3, 2, 2, 2, 2, 1, 2, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,-1, 0, 0,-1,-1,-1,-1,-1,-2,-2,-2},\r
-    { 9, 8, 6, 5, 6, 5, 4, 4, 3, 3, 2, 2, 2, 1, 0, 1, 1, 0, 0, 0,-1,-1,-1,-2,-2,-2,-3,-3,-4,-4,-5,-5,-6,-7}\r
- };\r
-\r
-const SKP_int16 SKP_Silk_Lag_range_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ] =\r
-{\r
-    /* Lags to search for low number of stage3 cbks */\r
-    {\r
-        {-2,6},\r
-        {-1,5},\r
-        {-1,5},\r
-        {-2,7}\r
-    },\r
-    /* Lags to search for middle number of stage3 cbks */\r
-    {\r
-        {-4,8},\r
-        {-1,6},\r
-        {-1,6},\r
-        {-4,9}\r
-    },\r
-    /* Lags to search for max number of stage3 cbks */\r
-    {\r
-        {-9,12},\r
-        {-3,7},\r
-        {-2,7},\r
-        {-7,13}\r
-    }\r
-};\r
-\r
-const SKP_int16 SKP_Silk_cbk_sizes_stage3[SKP_Silk_PITCH_EST_MAX_COMPLEX + 1] = \r
-{\r
-    PITCH_EST_NB_CBKS_STAGE3_MIN,\r
-    PITCH_EST_NB_CBKS_STAGE3_MID,\r
-    PITCH_EST_NB_CBKS_STAGE3_MAX\r
-};\r
-\r
-const SKP_int16 SKP_Silk_cbk_offsets_stage3[SKP_Silk_PITCH_EST_MAX_COMPLEX + 1] = \r
-{\r
-    ((PITCH_EST_NB_CBKS_STAGE3_MAX - PITCH_EST_NB_CBKS_STAGE3_MIN) >> 1),\r
-    ((PITCH_EST_NB_CBKS_STAGE3_MAX - PITCH_EST_NB_CBKS_STAGE3_MID) >> 1),\r
-    0\r
-};\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_typedef.h"
+#include "SKP_Silk_common_pitch_est_defines.h"
+
+/********************************************************/
+/* Auto Generated File from generate_pitch_est_tables.m */
+/********************************************************/
+
+const SKP_int16 SKP_Silk_CB_lags_stage2[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE2_EXT] =
+{
+    {0, 2,-1,-1,-1, 0, 0, 1, 1, 0, 1},
+    {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0},
+    {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0},
+    {0,-1, 2, 1, 0, 1, 1, 0, 0,-1,-1} 
+};
+
+const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX] =
+{
+    {-9,-7,-6,-5,-5,-4,-4,-3,-3,-2,-2,-2,-1,-1,-1, 0, 0, 0, 1, 1, 0, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 5, 6, 8},
+    {-3,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0,-1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 2, 1, 2, 2, 2, 2, 3},
+    { 3, 3, 2, 2, 2, 2, 1, 2, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,-1, 0, 0,-1,-1,-1,-1,-1,-2,-2,-2},
+    { 9, 8, 6, 5, 6, 5, 4, 4, 3, 3, 2, 2, 2, 1, 0, 1, 1, 0, 0, 0,-1,-1,-1,-2,-2,-2,-3,-3,-4,-4,-5,-5,-6,-7}
+ };
+
+const SKP_int16 SKP_Silk_Lag_range_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ] =
+{
+    /* Lags to search for low number of stage3 cbks */
+    {
+        {-2,6},
+        {-1,5},
+        {-1,5},
+        {-2,7}
+    },
+    /* Lags to search for middle number of stage3 cbks */
+    {
+        {-4,8},
+        {-1,6},
+        {-1,6},
+        {-4,9}
+    },
+    /* Lags to search for max number of stage3 cbks */
+    {
+        {-9,12},
+        {-3,7},
+        {-2,7},
+        {-7,13}
+    }
+};
+
+const SKP_int16 SKP_Silk_cbk_sizes_stage3[SKP_Silk_PITCH_EST_MAX_COMPLEX + 1] = 
+{
+    PITCH_EST_NB_CBKS_STAGE3_MIN,
+    PITCH_EST_NB_CBKS_STAGE3_MID,
+    PITCH_EST_NB_CBKS_STAGE3_MAX
+};
+
+const SKP_int16 SKP_Silk_cbk_offsets_stage3[SKP_Silk_PITCH_EST_MAX_COMPLEX + 1] = 
+{
+    ((PITCH_EST_NB_CBKS_STAGE3_MAX - PITCH_EST_NB_CBKS_STAGE3_MIN) >> 1),
+    ((PITCH_EST_NB_CBKS_STAGE3_MAX - PITCH_EST_NB_CBKS_STAGE3_MID) >> 1),
+    0
+};
+
index d3fd9c5297a44b220b5e70efce95bab326349fa0..772278d7540943fd3cdfa8c5575eb69e7c798480 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-#include "SKP_Silk_tuning_parameters.h"\r
-\r
-/* SKP_Silk_prefilter. Prefilter for finding Quantizer input signal */\r
-SKP_INLINE void SKP_Silk_prefilt_FIX(\r
-    SKP_Silk_prefilter_state_FIX *P,                    /* I/O state                          */\r
-    SKP_int32   st_res_Q12[],                           /* I short term residual signal       */\r
-    SKP_int16   xw[],                                   /* O prefiltered signal               */\r
-    SKP_int32   HarmShapeFIRPacked_Q12,                 /* I Harmonic shaping coeficients     */\r
-    SKP_int     Tilt_Q14,                               /* I Tilt shaping coeficient          */\r
-    SKP_int32   LF_shp_Q14,                             /* I Low-frequancy shaping coeficients*/\r
-    SKP_int     lag,                                    /* I Lag for harmonic shaping         */\r
-    SKP_int     length                                  /* I Length of signals                */\r
-);\r
-void SKP_Silk_warped_LPC_analysis_filter_FIX(\r
-          SKP_int32                 state[],            /* I/O  State [order + 1]                       */\r
-          SKP_int16                 res[],              /* O    Residual signal [length]                */\r
-    const SKP_int16                 coef_Q13[],         /* I    Coefficients [order]                    */\r
-    const SKP_int16                 input[],            /* I    Input signal [length]                   */\r
-    const SKP_int16                 lambda_Q16,         /* I    Warping factor                          */\r
-    const SKP_int                   length,             /* I    Length of input signal                  */\r
-    const SKP_int                   order               /* I    Filter order (even)                     */\r
-)\r
-{\r
-    SKP_int     n, i;\r
-    SKP_int32   acc_Q11, tmp1, tmp2;\r
-\r
-    /* Order must be even */\r
-    SKP_assert( ( order & 1 ) == 0 );\r
-\r
-    for( n = 0; n < length; n++ ) {\r
-        /* Output of lowpass section */  \r
-        tmp2 = SKP_SMLAWB( state[ 0 ], state[ 1 ], lambda_Q16 );\r
-        state[ 0 ] = SKP_LSHIFT( input[ n ], 14 );\r
-        /* Output of allpass section */\r
-        tmp1 = SKP_SMLAWB( state[ 1 ], state[ 2 ] - tmp2, lambda_Q16 );\r
-        state[ 1 ] = tmp2;\r
-        acc_Q11 = SKP_SMULWB( tmp2, coef_Q13[ 0 ] );\r
-        /* Loop over allpass sections */\r
-        for( i = 2; i < order; i += 2 ) {\r
-            /* Output of allpass section */\r
-            tmp2 = SKP_SMLAWB( state[ i ], state[ i + 1 ] - tmp1, lambda_Q16 );\r
-            state[ i ] = tmp1;\r
-            acc_Q11 = SKP_SMLAWB( acc_Q11, tmp1, coef_Q13[ i - 1 ] );\r
-            /* Output of allpass section */\r
-            tmp1 = SKP_SMLAWB( state[ i + 1 ], state[ i + 2 ] - tmp2, lambda_Q16 );\r
-            state[ i + 1 ] = tmp2;\r
-            acc_Q11 = SKP_SMLAWB( acc_Q11, tmp2, coef_Q13[ i ] );\r
-        }\r
-        state[ order ] = tmp1;\r
-        acc_Q11 = SKP_SMLAWB( acc_Q11, tmp1, coef_Q13[ order - 1 ] );\r
-        res[ n ] = ( SKP_int16 )SKP_SAT16( ( SKP_int32 )input[ n ] - SKP_RSHIFT_ROUND( acc_Q11, 11 ) );\r
-    }\r
-}\r
-\r
-void SKP_Silk_prefilter_FIX(\r
-    SKP_Silk_encoder_state_FIX          *psEnc,         /* I/O  Encoder state FIX                           */\r
-    const SKP_Silk_encoder_control_FIX  *psEncCtrl,     /* I    Encoder control FIX                         */\r
-    SKP_int16                           xw[],           /* O    Weighted signal                             */\r
-    const SKP_int16                     x[]             /* I    Speech signal                               */\r
-)\r
-{\r
-    SKP_Silk_prefilter_state_FIX *P = &psEnc->sPrefilt;\r
-    SKP_int   j, k, lag;\r
-    SKP_int32 tmp_32;\r
-    const SKP_int16 *AR1_shp_Q13;\r
-    const SKP_int16 *px;\r
-    SKP_int16 *pxw;\r
-    SKP_int   HarmShapeGain_Q12, Tilt_Q14;\r
-    SKP_int32 HarmShapeFIRPacked_Q12, LF_shp_Q14;\r
-    SKP_int32 x_filt_Q12[ MAX_FRAME_LENGTH / NB_SUBFR ];\r
-    SKP_int16 st_res[ ( MAX_FRAME_LENGTH / NB_SUBFR ) + MAX_SHAPE_LPC_ORDER ];\r
-    SKP_int16 B_Q12[ 2 ];\r
-\r
-    /* Setup pointers */\r
-    px  = x;\r
-    pxw = xw;\r
-    lag = P->lagPrev;\r
-    for( k = 0; k < NB_SUBFR; k++ ) {\r
-        /* Update Variables that change per sub frame */\r
-        if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {\r
-            lag = psEncCtrl->sCmn.pitchL[ k ];\r
-        }\r
-\r
-        /* Noise shape parameters */\r
-        HarmShapeGain_Q12 = SKP_SMULWB( psEncCtrl->HarmShapeGain_Q14[ k ], 16384 - psEncCtrl->HarmBoost_Q14[ k ] );\r
-        SKP_assert( HarmShapeGain_Q12 >= 0 );\r
-        HarmShapeFIRPacked_Q12  =                          SKP_RSHIFT( HarmShapeGain_Q12, 2 );\r
-        HarmShapeFIRPacked_Q12 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q12, 1 ), 16 );\r
-        Tilt_Q14    = psEncCtrl->Tilt_Q14[   k ];\r
-        LF_shp_Q14  = psEncCtrl->LF_shp_Q14[ k ];\r
-        AR1_shp_Q13 = &psEncCtrl->AR1_Q13[   k * MAX_SHAPE_LPC_ORDER ];\r
-\r
-        /* Short term FIR filtering*/\r
-        SKP_Silk_warped_LPC_analysis_filter_FIX( P->sAR_shp, st_res, AR1_shp_Q13, px, \r
-            psEnc->sCmn.warping_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.shapingLPCOrder );\r
-\r
-        /* reduce (mainly) low frequencies during harmonic emphasis */\r
-        B_Q12[ 0 ] = SKP_RSHIFT_ROUND( psEncCtrl->GainsPre_Q14[ k ], 2 );\r
-        tmp_32 = SKP_SMLABB( SKP_FIX_CONST( INPUT_TILT, 26 ), psEncCtrl->HarmBoost_Q14[ k ], HarmShapeGain_Q12 );   /* Q26 */\r
-        tmp_32 = SKP_SMLABB( tmp_32, psEncCtrl->coding_quality_Q14, SKP_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) );    /* Q26 */\r
-        tmp_32 = SKP_SMULWB( tmp_32, -psEncCtrl->GainsPre_Q14[ k ] );                                               /* Q24 */\r
-        tmp_32 = SKP_RSHIFT_ROUND( tmp_32, 12 );                                                                    /* Q12 */\r
-        B_Q12[ 1 ]= SKP_SAT16( tmp_32 );\r
-\r
-        x_filt_Q12[ 0 ] = SKP_SMLABB( SKP_SMULBB( st_res[ 0 ], B_Q12[ 0 ] ), P->sHarmHP, B_Q12[ 1 ] );\r
-        for( j = 1; j < psEnc->sCmn.subfr_length; j++ ) {\r
-            x_filt_Q12[ j ] = SKP_SMLABB( SKP_SMULBB( st_res[ j ], B_Q12[ 0 ] ), st_res[ j - 1 ], B_Q12[ 1 ] );\r
-        }\r
-        P->sHarmHP = st_res[ psEnc->sCmn.subfr_length - 1 ];\r
-\r
-        SKP_Silk_prefilt_FIX( P, x_filt_Q12, pxw, HarmShapeFIRPacked_Q12, Tilt_Q14, \r
-            LF_shp_Q14, lag, psEnc->sCmn.subfr_length );\r
-\r
-        px  += psEnc->sCmn.subfr_length;\r
-        pxw += psEnc->sCmn.subfr_length;\r
-    }\r
-\r
-    P->lagPrev = psEncCtrl->sCmn.pitchL[ NB_SUBFR - 1 ];\r
-}\r
-\r
-/* SKP_Silk_prefilter. Prefilter for finding Quantizer input signal                           */\r
-SKP_INLINE void SKP_Silk_prefilt_FIX(\r
-    SKP_Silk_prefilter_state_FIX *P,                    /* I/O state                          */\r
-    SKP_int32   st_res_Q12[],                           /* I short term residual signal       */\r
-    SKP_int16   xw[],                                   /* O prefiltered signal               */\r
-    SKP_int32   HarmShapeFIRPacked_Q12,                 /* I Harmonic shaping coeficients     */\r
-    SKP_int     Tilt_Q14,                               /* I Tilt shaping coeficient          */\r
-    SKP_int32   LF_shp_Q14,                             /* I Low-frequancy shaping coeficients*/\r
-    SKP_int     lag,                                    /* I Lag for harmonic shaping         */\r
-    SKP_int     length                                  /* I Length of signals                */\r
-)\r
-{\r
-    SKP_int   i, idx, LTP_shp_buf_idx;\r
-    SKP_int32 n_LTP_Q12, n_Tilt_Q10, n_LF_Q10;\r
-    SKP_int32 sLF_MA_shp_Q12, sLF_AR_shp_Q12;\r
-    SKP_int16 *LTP_shp_buf;\r
-\r
-    /* To speed up use temp variables instead of using the struct */\r
-    LTP_shp_buf     = P->sLTP_shp;\r
-    LTP_shp_buf_idx = P->sLTP_shp_buf_idx;\r
-    sLF_AR_shp_Q12  = P->sLF_AR_shp_Q12;\r
-    sLF_MA_shp_Q12  = P->sLF_MA_shp_Q12;\r
-\r
-    for( i = 0; i < length; i++ ) {\r
-        if( lag > 0 ) {\r
-            /* unrolled loop */\r
-            SKP_assert( HARM_SHAPE_FIR_TAPS == 3 );\r
-            idx = lag + LTP_shp_buf_idx;\r
-            n_LTP_Q12 = SKP_SMULBB(            LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 - 1) & LTP_MASK ], HarmShapeFIRPacked_Q12 );\r
-            n_LTP_Q12 = SKP_SMLABT( n_LTP_Q12, LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2    ) & LTP_MASK ], HarmShapeFIRPacked_Q12 );\r
-            n_LTP_Q12 = SKP_SMLABB( n_LTP_Q12, LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 + 1) & LTP_MASK ], HarmShapeFIRPacked_Q12 );\r
-        } else {\r
-            n_LTP_Q12 = 0;\r
-        }\r
-\r
-        n_Tilt_Q10 = SKP_SMULWB( sLF_AR_shp_Q12, Tilt_Q14 );\r
-        n_LF_Q10   = SKP_SMLAWB( SKP_SMULWT( sLF_AR_shp_Q12, LF_shp_Q14 ), sLF_MA_shp_Q12, LF_shp_Q14 );\r
-\r
-        sLF_AR_shp_Q12 = SKP_SUB32( st_res_Q12[ i ], SKP_LSHIFT( n_Tilt_Q10, 2 ) );\r
-        sLF_MA_shp_Q12 = SKP_SUB32( sLF_AR_shp_Q12,  SKP_LSHIFT( n_LF_Q10,   2 ) );\r
-\r
-        LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK;\r
-        LTP_shp_buf[ LTP_shp_buf_idx ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( sLF_MA_shp_Q12, 12 ) );\r
-\r
-        xw[i] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SUB32( sLF_MA_shp_Q12, n_LTP_Q12 ), 12 ) );\r
-    }\r
-\r
-    /* Copy temp variable back to state */\r
-    P->sLF_AR_shp_Q12   = sLF_AR_shp_Q12;\r
-    P->sLF_MA_shp_Q12   = sLF_MA_shp_Q12;\r
-    P->sLTP_shp_buf_idx = LTP_shp_buf_idx;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_tuning_parameters.h"
+
+/* SKP_Silk_prefilter. Prefilter for finding Quantizer input signal */
+SKP_INLINE void SKP_Silk_prefilt_FIX(
+    SKP_Silk_prefilter_state_FIX *P,                    /* I/O state                          */
+    SKP_int32   st_res_Q12[],                           /* I short term residual signal       */
+    SKP_int16   xw[],                                   /* O prefiltered signal               */
+    SKP_int32   HarmShapeFIRPacked_Q12,                 /* I Harmonic shaping coeficients     */
+    SKP_int     Tilt_Q14,                               /* I Tilt shaping coeficient          */
+    SKP_int32   LF_shp_Q14,                             /* I Low-frequancy shaping coeficients*/
+    SKP_int     lag,                                    /* I Lag for harmonic shaping         */
+    SKP_int     length                                  /* I Length of signals                */
+);
+void SKP_Silk_warped_LPC_analysis_filter_FIX(
+          SKP_int32                 state[],            /* I/O  State [order + 1]                       */
+          SKP_int16                 res[],              /* O    Residual signal [length]                */
+    const SKP_int16                 coef_Q13[],         /* I    Coefficients [order]                    */
+    const SKP_int16                 input[],            /* I    Input signal [length]                   */
+    const SKP_int16                 lambda_Q16,         /* I    Warping factor                          */
+    const SKP_int                   length,             /* I    Length of input signal                  */
+    const SKP_int                   order               /* I    Filter order (even)                     */
+)
+{
+    SKP_int     n, i;
+    SKP_int32   acc_Q11, tmp1, tmp2;
+
+    /* Order must be even */
+    SKP_assert( ( order & 1 ) == 0 );
+
+    for( n = 0; n < length; n++ ) {
+        /* Output of lowpass section */  
+        tmp2 = SKP_SMLAWB( state[ 0 ], state[ 1 ], lambda_Q16 );
+        state[ 0 ] = SKP_LSHIFT( input[ n ], 14 );
+        /* Output of allpass section */
+        tmp1 = SKP_SMLAWB( state[ 1 ], state[ 2 ] - tmp2, lambda_Q16 );
+        state[ 1 ] = tmp2;
+        acc_Q11 = SKP_SMULWB( tmp2, coef_Q13[ 0 ] );
+        /* Loop over allpass sections */
+        for( i = 2; i < order; i += 2 ) {
+            /* Output of allpass section */
+            tmp2 = SKP_SMLAWB( state[ i ], state[ i + 1 ] - tmp1, lambda_Q16 );
+            state[ i ] = tmp1;
+            acc_Q11 = SKP_SMLAWB( acc_Q11, tmp1, coef_Q13[ i - 1 ] );
+            /* Output of allpass section */
+            tmp1 = SKP_SMLAWB( state[ i + 1 ], state[ i + 2 ] - tmp2, lambda_Q16 );
+            state[ i + 1 ] = tmp2;
+            acc_Q11 = SKP_SMLAWB( acc_Q11, tmp2, coef_Q13[ i ] );
+        }
+        state[ order ] = tmp1;
+        acc_Q11 = SKP_SMLAWB( acc_Q11, tmp1, coef_Q13[ order - 1 ] );
+        res[ n ] = ( SKP_int16 )SKP_SAT16( ( SKP_int32 )input[ n ] - SKP_RSHIFT_ROUND( acc_Q11, 11 ) );
+    }
+}
+
+void SKP_Silk_prefilter_FIX(
+    SKP_Silk_encoder_state_FIX          *psEnc,         /* I/O  Encoder state FIX                           */
+    const SKP_Silk_encoder_control_FIX  *psEncCtrl,     /* I    Encoder control FIX                         */
+    SKP_int16                           xw[],           /* O    Weighted signal                             */
+    const SKP_int16                     x[]             /* I    Speech signal                               */
+)
+{
+    SKP_Silk_prefilter_state_FIX *P = &psEnc->sPrefilt;
+    SKP_int   j, k, lag;
+    SKP_int32 tmp_32;
+    const SKP_int16 *AR1_shp_Q13;
+    const SKP_int16 *px;
+    SKP_int16 *pxw;
+    SKP_int   HarmShapeGain_Q12, Tilt_Q14;
+    SKP_int32 HarmShapeFIRPacked_Q12, LF_shp_Q14;
+    SKP_int32 x_filt_Q12[ MAX_FRAME_LENGTH / NB_SUBFR ];
+    SKP_int16 st_res[ ( MAX_FRAME_LENGTH / NB_SUBFR ) + MAX_SHAPE_LPC_ORDER ];
+    SKP_int16 B_Q12[ 2 ];
+
+    /* Setup pointers */
+    px  = x;
+    pxw = xw;
+    lag = P->lagPrev;
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        /* Update Variables that change per sub frame */
+        if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
+            lag = psEncCtrl->sCmn.pitchL[ k ];
+        }
+
+        /* Noise shape parameters */
+        HarmShapeGain_Q12 = SKP_SMULWB( psEncCtrl->HarmShapeGain_Q14[ k ], 16384 - psEncCtrl->HarmBoost_Q14[ k ] );
+        SKP_assert( HarmShapeGain_Q12 >= 0 );
+        HarmShapeFIRPacked_Q12  =                          SKP_RSHIFT( HarmShapeGain_Q12, 2 );
+        HarmShapeFIRPacked_Q12 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q12, 1 ), 16 );
+        Tilt_Q14    = psEncCtrl->Tilt_Q14[   k ];
+        LF_shp_Q14  = psEncCtrl->LF_shp_Q14[ k ];
+        AR1_shp_Q13 = &psEncCtrl->AR1_Q13[   k * MAX_SHAPE_LPC_ORDER ];
+
+        /* Short term FIR filtering*/
+        SKP_Silk_warped_LPC_analysis_filter_FIX( P->sAR_shp, st_res, AR1_shp_Q13, px, 
+            psEnc->sCmn.warping_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.shapingLPCOrder );
+
+        /* reduce (mainly) low frequencies during harmonic emphasis */
+        B_Q12[ 0 ] = SKP_RSHIFT_ROUND( psEncCtrl->GainsPre_Q14[ k ], 2 );
+        tmp_32 = SKP_SMLABB( SKP_FIX_CONST( INPUT_TILT, 26 ), psEncCtrl->HarmBoost_Q14[ k ], HarmShapeGain_Q12 );   /* Q26 */
+        tmp_32 = SKP_SMLABB( tmp_32, psEncCtrl->coding_quality_Q14, SKP_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) );    /* Q26 */
+        tmp_32 = SKP_SMULWB( tmp_32, -psEncCtrl->GainsPre_Q14[ k ] );                                               /* Q24 */
+        tmp_32 = SKP_RSHIFT_ROUND( tmp_32, 12 );                                                                    /* Q12 */
+        B_Q12[ 1 ]= SKP_SAT16( tmp_32 );
+
+        x_filt_Q12[ 0 ] = SKP_SMLABB( SKP_SMULBB( st_res[ 0 ], B_Q12[ 0 ] ), P->sHarmHP, B_Q12[ 1 ] );
+        for( j = 1; j < psEnc->sCmn.subfr_length; j++ ) {
+            x_filt_Q12[ j ] = SKP_SMLABB( SKP_SMULBB( st_res[ j ], B_Q12[ 0 ] ), st_res[ j - 1 ], B_Q12[ 1 ] );
+        }
+        P->sHarmHP = st_res[ psEnc->sCmn.subfr_length - 1 ];
+
+        SKP_Silk_prefilt_FIX( P, x_filt_Q12, pxw, HarmShapeFIRPacked_Q12, Tilt_Q14, 
+            LF_shp_Q14, lag, psEnc->sCmn.subfr_length );
+
+        px  += psEnc->sCmn.subfr_length;
+        pxw += psEnc->sCmn.subfr_length;
+    }
+
+    P->lagPrev = psEncCtrl->sCmn.pitchL[ NB_SUBFR - 1 ];
+}
+
+/* SKP_Silk_prefilter. Prefilter for finding Quantizer input signal                           */
+SKP_INLINE void SKP_Silk_prefilt_FIX(
+    SKP_Silk_prefilter_state_FIX *P,                    /* I/O state                          */
+    SKP_int32   st_res_Q12[],                           /* I short term residual signal       */
+    SKP_int16   xw[],                                   /* O prefiltered signal               */
+    SKP_int32   HarmShapeFIRPacked_Q12,                 /* I Harmonic shaping coeficients     */
+    SKP_int     Tilt_Q14,                               /* I Tilt shaping coeficient          */
+    SKP_int32   LF_shp_Q14,                             /* I Low-frequancy shaping coeficients*/
+    SKP_int     lag,                                    /* I Lag for harmonic shaping         */
+    SKP_int     length                                  /* I Length of signals                */
+)
+{
+    SKP_int   i, idx, LTP_shp_buf_idx;
+    SKP_int32 n_LTP_Q12, n_Tilt_Q10, n_LF_Q10;
+    SKP_int32 sLF_MA_shp_Q12, sLF_AR_shp_Q12;
+    SKP_int16 *LTP_shp_buf;
+
+    /* To speed up use temp variables instead of using the struct */
+    LTP_shp_buf     = P->sLTP_shp;
+    LTP_shp_buf_idx = P->sLTP_shp_buf_idx;
+    sLF_AR_shp_Q12  = P->sLF_AR_shp_Q12;
+    sLF_MA_shp_Q12  = P->sLF_MA_shp_Q12;
+
+    for( i = 0; i < length; i++ ) {
+        if( lag > 0 ) {
+            /* unrolled loop */
+            SKP_assert( HARM_SHAPE_FIR_TAPS == 3 );
+            idx = lag + LTP_shp_buf_idx;
+            n_LTP_Q12 = SKP_SMULBB(            LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 - 1) & LTP_MASK ], HarmShapeFIRPacked_Q12 );
+            n_LTP_Q12 = SKP_SMLABT( n_LTP_Q12, LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2    ) & LTP_MASK ], HarmShapeFIRPacked_Q12 );
+            n_LTP_Q12 = SKP_SMLABB( n_LTP_Q12, LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 + 1) & LTP_MASK ], HarmShapeFIRPacked_Q12 );
+        } else {
+            n_LTP_Q12 = 0;
+        }
+
+        n_Tilt_Q10 = SKP_SMULWB( sLF_AR_shp_Q12, Tilt_Q14 );
+        n_LF_Q10   = SKP_SMLAWB( SKP_SMULWT( sLF_AR_shp_Q12, LF_shp_Q14 ), sLF_MA_shp_Q12, LF_shp_Q14 );
+
+        sLF_AR_shp_Q12 = SKP_SUB32( st_res_Q12[ i ], SKP_LSHIFT( n_Tilt_Q10, 2 ) );
+        sLF_MA_shp_Q12 = SKP_SUB32( sLF_AR_shp_Q12,  SKP_LSHIFT( n_LF_Q10,   2 ) );
+
+        LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK;
+        LTP_shp_buf[ LTP_shp_buf_idx ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( sLF_MA_shp_Q12, 12 ) );
+
+        xw[i] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SUB32( sLF_MA_shp_Q12, n_LTP_Q12 ), 12 ) );
+    }
+
+    /* Copy temp variable back to state */
+    P->sLF_AR_shp_Q12   = sLF_AR_shp_Q12;
+    P->sLF_MA_shp_Q12   = sLF_MA_shp_Q12;
+    P->sLTP_shp_buf_idx = LTP_shp_buf_idx;
+}
index 84b8a885662ef3cb6a42fdd3ecc2cebf543871ac..7f1708c19e34011034e58351d209e83a9f2570f8 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-\r
-/* Limit, stabilize, convert and quantize NLSFs.    */ \r
-void SKP_Silk_process_NLSFs_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
-    SKP_int                         *pNLSF_Q15          /* I/O  Normalized LSFs (quant out) (0 - (2^15-1))  */\r
-)\r
-{\r
-    SKP_int     doInterpolate;\r
-    SKP_int     pNLSFW_Q6[ MAX_LPC_ORDER ];\r
-    SKP_int     NLSF_mu_Q15, NLSF_mu_fluc_red_Q16;\r
-    SKP_int32   i_sqr_Q15;\r
-    const SKP_Silk_NLSF_CB_struct *psNLSF_CB;\r
-\r
-    /* Used only for NLSF interpolation */\r
-    SKP_int     pNLSF0_temp_Q15[ MAX_LPC_ORDER ];\r
-    SKP_int     pNLSFW0_temp_Q6[ MAX_LPC_ORDER ];\r
-    SKP_int     i;\r
-\r
-    SKP_assert( psEnc->speech_activity_Q8 >=   0 );\r
-    SKP_assert( psEnc->speech_activity_Q8 <= 256 );\r
-    SKP_assert( psEncCtrl->sparseness_Q8  >=   0 );\r
-    SKP_assert( psEncCtrl->sparseness_Q8  <= 256 );\r
-    SKP_assert( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED || psEncCtrl->sCmn.sigtype == SIG_TYPE_UNVOICED );\r
-\r
-    /***********************/\r
-    /* Calculate mu values */\r
-    /***********************/\r
-    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {\r
-        /* NLSF_mu           = 0.002f - 0.001f * psEnc->speech_activity; */\r
-        /* NLSF_mu_fluc_red  = 0.1f   - 0.05f  * psEnc->speech_activity; */\r
-        NLSF_mu_Q15          = SKP_SMLAWB(   66,   -8388, psEnc->speech_activity_Q8 );\r
-        NLSF_mu_fluc_red_Q16 = SKP_SMLAWB( 6554, -838848, psEnc->speech_activity_Q8 );\r
-    } else { \r
-        /* NLSF_mu           = 0.005f - 0.004f * psEnc->speech_activity; */\r
-        /* NLSF_mu_fluc_red  = 0.2f   - 0.1f   * psEnc->speech_activity - 0.1f * psEncCtrl->sparseness; */\r
-        NLSF_mu_Q15          = SKP_SMLAWB(   164,   -33554, psEnc->speech_activity_Q8 );\r
-        NLSF_mu_fluc_red_Q16 = SKP_SMLAWB( 13107, -1677696, psEnc->speech_activity_Q8 + psEncCtrl->sparseness_Q8 ); \r
-    }\r
-    SKP_assert( NLSF_mu_Q15          >= 0     );\r
-    SKP_assert( NLSF_mu_Q15          <= 164   );\r
-    SKP_assert( NLSF_mu_fluc_red_Q16 >= 0     );\r
-    SKP_assert( NLSF_mu_fluc_red_Q16 <= 13107 );\r
-\r
-    NLSF_mu_Q15 = SKP_max( NLSF_mu_Q15, 1 );\r
-\r
-    /* Calculate NLSF weights */\r
-    TIC(NLSF_weights_FIX)\r
-    SKP_Silk_NLSF_VQ_weights_laroia( pNLSFW_Q6, pNLSF_Q15, psEnc->sCmn.predictLPCOrder );\r
-    TOC(NLSF_weights_FIX)\r
-\r
-    /* Update NLSF weights for interpolated NLSFs */\r
-    doInterpolate = ( psEnc->sCmn.useInterpolatedNLSFs == 1 ) && ( psEncCtrl->sCmn.NLSFInterpCoef_Q2 < ( 1 << 2 ) );\r
-    if( doInterpolate ) {\r
-\r
-        /* Calculate the interpolated NLSF vector for the first half */\r
-        SKP_Silk_interpolate( pNLSF0_temp_Q15, psEnc->sPred.prev_NLSFq_Q15, pNLSF_Q15, \r
-            psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sCmn.predictLPCOrder );\r
-\r
-        /* Calculate first half NLSF weights for the interpolated NLSFs */\r
-        TIC(NLSF_weights_FIX)\r
-        SKP_Silk_NLSF_VQ_weights_laroia( pNLSFW0_temp_Q6, pNLSF0_temp_Q15, psEnc->sCmn.predictLPCOrder );\r
-        TOC(NLSF_weights_FIX)\r
-\r
-        /* Update NLSF weights with contribution from first half */\r
-        i_sqr_Q15 = SKP_LSHIFT( SKP_SMULBB( psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->sCmn.NLSFInterpCoef_Q2 ), 11 );\r
-        for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) {\r
-            pNLSFW_Q6[ i ] = SKP_SMLAWB( SKP_RSHIFT( pNLSFW_Q6[ i ], 1 ), pNLSFW0_temp_Q6[ i ], i_sqr_Q15 );\r
-            SKP_assert( pNLSFW_Q6[ i ] <= SKP_int16_MAX );\r
-            SKP_assert( pNLSFW_Q6[ i ] >= 1 );\r
-        }\r
-    }\r
-\r
-    /* Set pointer to the NLSF codebook for the current signal type and LPC order */\r
-    psNLSF_CB = psEnc->sCmn.psNLSF_CB[ psEncCtrl->sCmn.sigtype ];\r
-\r
-    /* Quantize NLSF parameters given the trained NLSF codebooks */\r
-    TIC(MSVQ_encode_FIX)\r
-    SKP_Silk_NLSF_MSVQ_encode_FIX( psEncCtrl->sCmn.NLSFIndices, pNLSF_Q15, psNLSF_CB, \r
-        psEnc->sPred.prev_NLSFq_Q15, pNLSFW_Q6, NLSF_mu_Q15, NLSF_mu_fluc_red_Q16, \r
-        psEnc->sCmn.NLSF_MSVQ_Survivors, psEnc->sCmn.predictLPCOrder, psEnc->sCmn.first_frame_after_reset );\r
-    TOC(MSVQ_encode_FIX)\r
-\r
-    /* Convert quantized NLSFs back to LPC coefficients */\r
-    SKP_Silk_NLSF2A_stable( psEncCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psEnc->sCmn.predictLPCOrder );\r
-\r
-    if( doInterpolate ) {\r
-        /* Calculate the interpolated, quantized LSF vector for the first half */\r
-        SKP_Silk_interpolate( pNLSF0_temp_Q15, psEnc->sPred.prev_NLSFq_Q15, pNLSF_Q15, \r
-            psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sCmn.predictLPCOrder );\r
-\r
-        /* Convert back to LPC coefficients */\r
-        SKP_Silk_NLSF2A_stable( psEncCtrl->PredCoef_Q12[ 0 ], pNLSF0_temp_Q15, psEnc->sCmn.predictLPCOrder );\r
-\r
-    } else {\r
-        /* Copy LPC coefficients for first half from second half */\r
-        SKP_memcpy( psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->PredCoef_Q12[ 1 ], psEnc->sCmn.predictLPCOrder * sizeof( SKP_int16 ) );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+/* Limit, stabilize, convert and quantize NLSFs.    */ 
+void SKP_Silk_process_NLSFs_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Encoder state FIX                           */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,         /* I/O  Encoder control FIX                         */
+    SKP_int                         *pNLSF_Q15          /* I/O  Normalized LSFs (quant out) (0 - (2^15-1))  */
+)
+{
+    SKP_int     doInterpolate;
+    SKP_int     pNLSFW_Q6[ MAX_LPC_ORDER ];
+    SKP_int     NLSF_mu_Q15, NLSF_mu_fluc_red_Q16;
+    SKP_int32   i_sqr_Q15;
+    const SKP_Silk_NLSF_CB_struct *psNLSF_CB;
+
+    /* Used only for NLSF interpolation */
+    SKP_int     pNLSF0_temp_Q15[ MAX_LPC_ORDER ];
+    SKP_int     pNLSFW0_temp_Q6[ MAX_LPC_ORDER ];
+    SKP_int     i;
+
+    SKP_assert( psEnc->speech_activity_Q8 >=   0 );
+    SKP_assert( psEnc->speech_activity_Q8 <= 256 );
+    SKP_assert( psEncCtrl->sparseness_Q8  >=   0 );
+    SKP_assert( psEncCtrl->sparseness_Q8  <= 256 );
+    SKP_assert( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED || psEncCtrl->sCmn.sigtype == SIG_TYPE_UNVOICED );
+
+    /***********************/
+    /* Calculate mu values */
+    /***********************/
+    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
+        /* NLSF_mu           = 0.002f - 0.001f * psEnc->speech_activity; */
+        /* NLSF_mu_fluc_red  = 0.1f   - 0.05f  * psEnc->speech_activity; */
+        NLSF_mu_Q15          = SKP_SMLAWB(   66,   -8388, psEnc->speech_activity_Q8 );
+        NLSF_mu_fluc_red_Q16 = SKP_SMLAWB( 6554, -838848, psEnc->speech_activity_Q8 );
+    } else { 
+        /* NLSF_mu           = 0.005f - 0.004f * psEnc->speech_activity; */
+        /* NLSF_mu_fluc_red  = 0.2f   - 0.1f   * psEnc->speech_activity - 0.1f * psEncCtrl->sparseness; */
+        NLSF_mu_Q15          = SKP_SMLAWB(   164,   -33554, psEnc->speech_activity_Q8 );
+        NLSF_mu_fluc_red_Q16 = SKP_SMLAWB( 13107, -1677696, psEnc->speech_activity_Q8 + psEncCtrl->sparseness_Q8 ); 
+    }
+    SKP_assert( NLSF_mu_Q15          >= 0     );
+    SKP_assert( NLSF_mu_Q15          <= 164   );
+    SKP_assert( NLSF_mu_fluc_red_Q16 >= 0     );
+    SKP_assert( NLSF_mu_fluc_red_Q16 <= 13107 );
+
+    NLSF_mu_Q15 = SKP_max( NLSF_mu_Q15, 1 );
+
+    /* Calculate NLSF weights */
+    TIC(NLSF_weights_FIX)
+    SKP_Silk_NLSF_VQ_weights_laroia( pNLSFW_Q6, pNLSF_Q15, psEnc->sCmn.predictLPCOrder );
+    TOC(NLSF_weights_FIX)
+
+    /* Update NLSF weights for interpolated NLSFs */
+    doInterpolate = ( psEnc->sCmn.useInterpolatedNLSFs == 1 ) && ( psEncCtrl->sCmn.NLSFInterpCoef_Q2 < ( 1 << 2 ) );
+    if( doInterpolate ) {
+
+        /* Calculate the interpolated NLSF vector for the first half */
+        SKP_Silk_interpolate( pNLSF0_temp_Q15, psEnc->sPred.prev_NLSFq_Q15, pNLSF_Q15, 
+            psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sCmn.predictLPCOrder );
+
+        /* Calculate first half NLSF weights for the interpolated NLSFs */
+        TIC(NLSF_weights_FIX)
+        SKP_Silk_NLSF_VQ_weights_laroia( pNLSFW0_temp_Q6, pNLSF0_temp_Q15, psEnc->sCmn.predictLPCOrder );
+        TOC(NLSF_weights_FIX)
+
+        /* Update NLSF weights with contribution from first half */
+        i_sqr_Q15 = SKP_LSHIFT( SKP_SMULBB( psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->sCmn.NLSFInterpCoef_Q2 ), 11 );
+        for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) {
+            pNLSFW_Q6[ i ] = SKP_SMLAWB( SKP_RSHIFT( pNLSFW_Q6[ i ], 1 ), pNLSFW0_temp_Q6[ i ], i_sqr_Q15 );
+            SKP_assert( pNLSFW_Q6[ i ] <= SKP_int16_MAX );
+            SKP_assert( pNLSFW_Q6[ i ] >= 1 );
+        }
+    }
+
+    /* Set pointer to the NLSF codebook for the current signal type and LPC order */
+    psNLSF_CB = psEnc->sCmn.psNLSF_CB[ psEncCtrl->sCmn.sigtype ];
+
+    /* Quantize NLSF parameters given the trained NLSF codebooks */
+    TIC(MSVQ_encode_FIX)
+    SKP_Silk_NLSF_MSVQ_encode_FIX( psEncCtrl->sCmn.NLSFIndices, pNLSF_Q15, psNLSF_CB, 
+        psEnc->sPred.prev_NLSFq_Q15, pNLSFW_Q6, NLSF_mu_Q15, NLSF_mu_fluc_red_Q16, 
+        psEnc->sCmn.NLSF_MSVQ_Survivors, psEnc->sCmn.predictLPCOrder, psEnc->sCmn.first_frame_after_reset );
+    TOC(MSVQ_encode_FIX)
+
+    /* Convert quantized NLSFs back to LPC coefficients */
+    SKP_Silk_NLSF2A_stable( psEncCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psEnc->sCmn.predictLPCOrder );
+
+    if( doInterpolate ) {
+        /* Calculate the interpolated, quantized LSF vector for the first half */
+        SKP_Silk_interpolate( pNLSF0_temp_Q15, psEnc->sPred.prev_NLSFq_Q15, pNLSF_Q15, 
+            psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEnc->sCmn.predictLPCOrder );
+
+        /* Convert back to LPC coefficients */
+        SKP_Silk_NLSF2A_stable( psEncCtrl->PredCoef_Q12[ 0 ], pNLSF0_temp_Q15, psEnc->sCmn.predictLPCOrder );
+
+    } else {
+        /* Copy LPC coefficients for first half from second half */
+        SKP_memcpy( psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->PredCoef_Q12[ 1 ], psEnc->sCmn.predictLPCOrder * sizeof( SKP_int16 ) );
+    }
+}
index 2e0853c5cebde914458f2aeeee7c2cec2a53e827..10c9869fec46d2438ccb231d851d0f7350fbc64b 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-#include "SKP_Silk_tuning_parameters.h"\r
-\r
-/* Processing of gains */\r
-void SKP_Silk_process_gains_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_Silk_shape_state_FIX    *psShapeSt = &psEnc->sShape;\r
-    SKP_int     k;\r
-    SKP_int32   s_Q16, InvMaxSqrVal_Q16, gain, gain_squared, ResNrg, ResNrgPart, quant_offset_Q10;\r
-\r
-    /* Gain reduction when LTP coding gain is high */\r
-    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {\r
-        /*s = -0.5f * SKP_sigmoid( 0.25f * ( psEncCtrl->LTPredCodGain - 12.0f ) ); */\r
-        s_Q16 = -SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->LTPredCodGain_Q7 - SKP_FIX_CONST( 12.0, 7 ), 4 ) );\r
-        for( k = 0; k < NB_SUBFR; k++ ) {\r
-            psEncCtrl->Gains_Q16[ k ] = SKP_SMLAWB( psEncCtrl->Gains_Q16[ k ], psEncCtrl->Gains_Q16[ k ], s_Q16 );\r
-        }\r
-    }\r
-\r
-    /* Limit the quantized signal */\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
-\r
-    for( k = 0; k < 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_int32_MAX;\r
-            } else {\r
-                ResNrgPart = SKP_LSHIFT( ResNrgPart, -psEncCtrl->ResNrgQ[ k ] );\r
-            }\r
-        }\r
-        gain = psEncCtrl->Gains_Q16[ k ];\r
-        gain_squared = SKP_ADD_SAT32( ResNrgPart, SKP_SMMUL( gain, gain ) );\r
-        if( gain_squared < SKP_int16_MAX ) {\r
-            /* recalculate with higher precision */\r
-            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
-            psEncCtrl->Gains_Q16[ k ] = SKP_LSHIFT_SAT32( gain, 8 );        /* Q16  */\r
-        } else {\r
-            gain = SKP_Silk_SQRT_APPROX( gain_squared );                  /* Q0   */\r
-            psEncCtrl->Gains_Q16[ k ] = SKP_LSHIFT_SAT32( gain, 16 );       /* Q16  */\r
-        }\r
-    }\r
-\r
-    /* Noise shaping quantization */\r
-    SKP_Silk_gains_quant( psEncCtrl->sCmn.GainsIndices, psEncCtrl->Gains_Q16, \r
-        &psShapeSt->LastGainIndex, psEnc->sCmn.nFramesInPayloadBuf );\r
-    /* Set quantizer offset for voiced signals. Larger offset when LTP coding gain is low or tilt is high (ie low-pass) */\r
-    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {\r
-        if( psEncCtrl->LTPredCodGain_Q7 + SKP_RSHIFT( psEncCtrl->input_tilt_Q15, 8 ) > SKP_FIX_CONST( 1.0, 7 ) ) {\r
-            psEncCtrl->sCmn.QuantOffsetType = 0;\r
-        } else {\r
-            psEncCtrl->sCmn.QuantOffsetType = 1;\r
-        }\r
-    }\r
-\r
-    /* Quantizer boundary adjustment */\r
-    quant_offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrl->sCmn.sigtype ][ psEncCtrl->sCmn.QuantOffsetType ];\r
-    psEncCtrl->Lambda_Q10 = SKP_FIX_CONST( LAMBDA_OFFSET, 10 )\r
-                          + SKP_SMULBB( SKP_FIX_CONST( LAMBDA_DELAYED_DECISIONS, 10 ), psEnc->sCmn.nStatesDelayedDecision )\r
-                          + SKP_SMULWB( SKP_FIX_CONST( LAMBDA_SPEECH_ACT,        18 ), psEnc->speech_activity_Q8          )\r
-                          + SKP_SMULWB( SKP_FIX_CONST( LAMBDA_INPUT_QUALITY,     12 ), psEncCtrl->input_quality_Q14       )\r
-                          + SKP_SMULWB( SKP_FIX_CONST( LAMBDA_CODING_QUALITY,    12 ), psEncCtrl->coding_quality_Q14      )\r
-                          + SKP_SMULWB( SKP_FIX_CONST( LAMBDA_QUANT_OFFSET,      16 ), quant_offset_Q10                   );\r
-\r
-    SKP_assert( psEncCtrl->Lambda_Q10 > 0 );\r
-    SKP_assert( psEncCtrl->Lambda_Q10 < SKP_FIX_CONST( 2, 10 ) );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_tuning_parameters.h"
+
+/* Processing of gains */
+void SKP_Silk_process_gains_FIX(
+    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Encoder state_FIX                           */
+    SKP_Silk_encoder_control_FIX    *psEncCtrl      /* I/O  Encoder control_FIX                         */
+)
+{
+    SKP_Silk_shape_state_FIX    *psShapeSt = &psEnc->sShape;
+    SKP_int     k;
+    SKP_int32   s_Q16, InvMaxSqrVal_Q16, gain, gain_squared, ResNrg, ResNrgPart, quant_offset_Q10;
+
+    /* Gain reduction when LTP coding gain is high */
+    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
+        /*s = -0.5f * SKP_sigmoid( 0.25f * ( psEncCtrl->LTPredCodGain - 12.0f ) ); */
+        s_Q16 = -SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->LTPredCodGain_Q7 - SKP_FIX_CONST( 12.0, 7 ), 4 ) );
+        for( k = 0; k < NB_SUBFR; k++ ) {
+            psEncCtrl->Gains_Q16[ k ] = SKP_SMLAWB( psEncCtrl->Gains_Q16[ k ], psEncCtrl->Gains_Q16[ k ], s_Q16 );
+        }
+    }
+
+    /* Limit the quantized signal */
+    InvMaxSqrVal_Q16 = SKP_DIV32_16( SKP_Silk_log2lin( 
+        SKP_SMULWB( SKP_FIX_CONST( 70.0, 7 ) - psEncCtrl->current_SNR_dB_Q7, SKP_FIX_CONST( 0.33, 16 ) ) ), psEnc->sCmn.subfr_length );
+
+    for( k = 0; k < NB_SUBFR; k++ ) {
+        /* Soft limit on ratio residual energy and squared gains */
+        ResNrg     = psEncCtrl->ResNrg[ k ];
+        ResNrgPart = SKP_SMULWW( ResNrg, InvMaxSqrVal_Q16 );
+        if( psEncCtrl->ResNrgQ[ k ] > 0 ) {
+            if( psEncCtrl->ResNrgQ[ k ] < 32 ) {
+                ResNrgPart = SKP_RSHIFT_ROUND( ResNrgPart, psEncCtrl->ResNrgQ[ k ] );
+            } else {
+                ResNrgPart = 0;
+            }
+        } else if( psEncCtrl->ResNrgQ[k] != 0 ) {
+            if( ResNrgPart > SKP_RSHIFT( SKP_int32_MAX, -psEncCtrl->ResNrgQ[ k ] ) ) {
+                ResNrgPart = SKP_int32_MAX;
+            } else {
+                ResNrgPart = SKP_LSHIFT( ResNrgPart, -psEncCtrl->ResNrgQ[ k ] );
+            }
+        }
+        gain = psEncCtrl->Gains_Q16[ k ];
+        gain_squared = SKP_ADD_SAT32( ResNrgPart, SKP_SMMUL( gain, gain ) );
+        if( gain_squared < SKP_int16_MAX ) {
+            /* recalculate with higher precision */
+            gain_squared = SKP_SMLAWW( SKP_LSHIFT( ResNrgPart, 16 ), gain, gain );
+            SKP_assert( gain_squared > 0 );
+            gain = SKP_Silk_SQRT_APPROX( gain_squared );                  /* Q8   */
+            psEncCtrl->Gains_Q16[ k ] = SKP_LSHIFT_SAT32( gain, 8 );        /* Q16  */
+        } else {
+            gain = SKP_Silk_SQRT_APPROX( gain_squared );                  /* Q0   */
+            psEncCtrl->Gains_Q16[ k ] = SKP_LSHIFT_SAT32( gain, 16 );       /* Q16  */
+        }
+    }
+
+    /* Noise shaping quantization */
+    SKP_Silk_gains_quant( psEncCtrl->sCmn.GainsIndices, psEncCtrl->Gains_Q16, 
+        &psShapeSt->LastGainIndex, psEnc->sCmn.nFramesInPayloadBuf );
+    /* Set quantizer offset for voiced signals. Larger offset when LTP coding gain is low or tilt is high (ie low-pass) */
+    if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
+        if( psEncCtrl->LTPredCodGain_Q7 + SKP_RSHIFT( psEncCtrl->input_tilt_Q15, 8 ) > SKP_FIX_CONST( 1.0, 7 ) ) {
+            psEncCtrl->sCmn.QuantOffsetType = 0;
+        } else {
+            psEncCtrl->sCmn.QuantOffsetType = 1;
+        }
+    }
+
+    /* Quantizer boundary adjustment */
+    quant_offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrl->sCmn.sigtype ][ psEncCtrl->sCmn.QuantOffsetType ];
+    psEncCtrl->Lambda_Q10 = SKP_FIX_CONST( LAMBDA_OFFSET, 10 )
+                          + SKP_SMULBB( SKP_FIX_CONST( LAMBDA_DELAYED_DECISIONS, 10 ), psEnc->sCmn.nStatesDelayedDecision )
+                          + SKP_SMULWB( SKP_FIX_CONST( LAMBDA_SPEECH_ACT,        18 ), psEnc->speech_activity_Q8          )
+                          + SKP_SMULWB( SKP_FIX_CONST( LAMBDA_INPUT_QUALITY,     12 ), psEncCtrl->input_quality_Q14       )
+                          + SKP_SMULWB( SKP_FIX_CONST( LAMBDA_CODING_QUALITY,    12 ), psEncCtrl->coding_quality_Q14      )
+                          + SKP_SMULWB( SKP_FIX_CONST( LAMBDA_QUANT_OFFSET,      16 ), quant_offset_Q10                   );
+
+    SKP_assert( psEncCtrl->Lambda_Q10 > 0 );
+    SKP_assert( psEncCtrl->Lambda_Q10 < SKP_FIX_CONST( 2, 10 ) );
+}
index d0c4055d702f6d5de1b1d729a922393be739001c..cc2742b21533be2bce6e9fd5e1aabb22e64fb815 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-\r
-void SKP_Silk_quant_LTP_gains_FIX(\r
-    SKP_int16               B_Q14[],                /* I/O  (un)quantized LTP gains     */\r
-    SKP_int                 cbk_index[],            /* O    Codebook Index              */\r
-    SKP_int                 *periodicity_index,     /* O    Periodicity Index           */\r
-    const SKP_int32         W_Q18[],                /* I    Error Weights in Q18        */\r
-    SKP_int                 mu_Q8,                  /* I    Mu value (R/D tradeoff)     */\r
-    SKP_int                 lowComplexity           /* I    Flag for low complexity     */\r
-)\r
-{\r
-    SKP_int             j, k, temp_idx[ NB_SUBFR ], cbk_size;\r
-    const SKP_uint16    *cdf_ptr;\r
-    const SKP_int16     *cl_ptr;\r
-    const SKP_int16     *cbk_ptr_Q14;\r
-    const SKP_int16     *b_Q14_ptr;\r
-    const SKP_int32     *W_Q18_ptr;\r
-    SKP_int32           rate_dist_subfr, rate_dist, min_rate_dist;\r
-\r
-\r
-\r
-    /***************************************************/\r
-    /* iterate over different codebooks with different */\r
-    /* rates/distortions, and choose best */\r
-    /***************************************************/\r
-    min_rate_dist = SKP_int32_MAX;\r
-    for( k = 0; k < 3; k++ ) {\r
-        cdf_ptr     = SKP_Silk_LTP_gain_CDF_ptrs[     k ];\r
-        cl_ptr      = SKP_Silk_LTP_gain_BITS_Q6_ptrs[ k ];\r
-        cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[       k ];\r
-        cbk_size    = SKP_Silk_LTP_vq_sizes[          k ];\r
-\r
-        /* Setup pointer to first subframe */\r
-        W_Q18_ptr = W_Q18;\r
-        b_Q14_ptr = B_Q14;\r
-\r
-        rate_dist = 0;\r
-        for( j = 0; j < NB_SUBFR; j++ ) {\r
-\r
-            SKP_Silk_VQ_WMat_EC_FIX(\r
-                &temp_idx[ j ],         /* O    index of best codebook vector                           */\r
-                &rate_dist_subfr,       /* O    best weighted quantization error + mu * rate            */\r
-                b_Q14_ptr,              /* I    input vector to be quantized                            */\r
-                W_Q18_ptr,              /* I    weighting matrix                                        */\r
-                cbk_ptr_Q14,            /* I    codebook                                                */\r
-                cl_ptr,                 /* I    code length for each codebook vector                    */\r
-                mu_Q8,                  /* I    tradeoff between weighted error and rate                */\r
-                cbk_size                /* I    number of vectors in codebook                           */\r
-            );\r
-\r
-            rate_dist = SKP_ADD_POS_SAT32( rate_dist, rate_dist_subfr );\r
-\r
-            b_Q14_ptr += LTP_ORDER;\r
-            W_Q18_ptr += LTP_ORDER * LTP_ORDER;\r
-        }\r
-\r
-        /* Avoid never finding a codebook */\r
-        rate_dist = SKP_min( SKP_int32_MAX - 1, rate_dist );\r
-\r
-        if( rate_dist < min_rate_dist ) {\r
-            min_rate_dist = rate_dist;\r
-            SKP_memcpy( cbk_index, temp_idx, NB_SUBFR * sizeof( SKP_int ) );\r
-            *periodicity_index = k;\r
-        }\r
-\r
-        /* Break early in low-complexity mode if rate distortion is below threshold */\r
-        if( lowComplexity && ( rate_dist < SKP_Silk_LTP_gain_middle_avg_RD_Q14 ) ) {\r
-            break;\r
-        }\r
-    }\r
-\r
-    cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ *periodicity_index ];\r
-    for( j = 0; j < NB_SUBFR; j++ ) {\r
-        for( k = 0; k < LTP_ORDER; k++ ) { \r
-            B_Q14[ j * LTP_ORDER + k ] = cbk_ptr_Q14[ SKP_MLA( k, cbk_index[ j ], LTP_ORDER ) ];\r
-        }\r
-    }\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+void SKP_Silk_quant_LTP_gains_FIX(
+    SKP_int16               B_Q14[],                /* I/O  (un)quantized LTP gains     */
+    SKP_int                 cbk_index[],            /* O    Codebook Index              */
+    SKP_int                 *periodicity_index,     /* O    Periodicity Index           */
+    const SKP_int32         W_Q18[],                /* I    Error Weights in Q18        */
+    SKP_int                 mu_Q8,                  /* I    Mu value (R/D tradeoff)     */
+    SKP_int                 lowComplexity           /* I    Flag for low complexity     */
+)
+{
+    SKP_int             j, k, temp_idx[ NB_SUBFR ], cbk_size;
+    const SKP_uint16    *cdf_ptr;
+    const SKP_int16     *cl_ptr;
+    const SKP_int16     *cbk_ptr_Q14;
+    const SKP_int16     *b_Q14_ptr;
+    const SKP_int32     *W_Q18_ptr;
+    SKP_int32           rate_dist_subfr, rate_dist, min_rate_dist;
+
+
+
+    /***************************************************/
+    /* iterate over different codebooks with different */
+    /* rates/distortions, and choose best */
+    /***************************************************/
+    min_rate_dist = SKP_int32_MAX;
+    for( k = 0; k < 3; k++ ) {
+        cdf_ptr     = SKP_Silk_LTP_gain_CDF_ptrs[     k ];
+        cl_ptr      = SKP_Silk_LTP_gain_BITS_Q6_ptrs[ k ];
+        cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[       k ];
+        cbk_size    = SKP_Silk_LTP_vq_sizes[          k ];
+
+        /* Setup pointer to first subframe */
+        W_Q18_ptr = W_Q18;
+        b_Q14_ptr = B_Q14;
+
+        rate_dist = 0;
+        for( j = 0; j < NB_SUBFR; j++ ) {
+
+            SKP_Silk_VQ_WMat_EC_FIX(
+                &temp_idx[ j ],         /* O    index of best codebook vector                           */
+                &rate_dist_subfr,       /* O    best weighted quantization error + mu * rate            */
+                b_Q14_ptr,              /* I    input vector to be quantized                            */
+                W_Q18_ptr,              /* I    weighting matrix                                        */
+                cbk_ptr_Q14,            /* I    codebook                                                */
+                cl_ptr,                 /* I    code length for each codebook vector                    */
+                mu_Q8,                  /* I    tradeoff between weighted error and rate                */
+                cbk_size                /* I    number of vectors in codebook                           */
+            );
+
+            rate_dist = SKP_ADD_POS_SAT32( rate_dist, rate_dist_subfr );
+
+            b_Q14_ptr += LTP_ORDER;
+            W_Q18_ptr += LTP_ORDER * LTP_ORDER;
+        }
+
+        /* Avoid never finding a codebook */
+        rate_dist = SKP_min( SKP_int32_MAX - 1, rate_dist );
+
+        if( rate_dist < min_rate_dist ) {
+            min_rate_dist = rate_dist;
+            SKP_memcpy( cbk_index, temp_idx, NB_SUBFR * sizeof( SKP_int ) );
+            *periodicity_index = k;
+        }
+
+        /* Break early in low-complexity mode if rate distortion is below threshold */
+        if( lowComplexity && ( rate_dist < SKP_Silk_LTP_gain_middle_avg_RD_Q14 ) ) {
+            break;
+        }
+    }
+
+    cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ *periodicity_index ];
+    for( j = 0; j < NB_SUBFR; j++ ) {
+        for( k = 0; k < LTP_ORDER; k++ ) { 
+            B_Q14[ j * LTP_ORDER + k ] = cbk_ptr_Q14[ SKP_MLA( k, cbk_index[ j ], LTP_ORDER ) ];
+        }
+    }
+}
+
index b3aad5b3091ada1fdc6ae42475b30d6ad0aa59a8..b33400d5da38ceb323ac67c585a37eab84172813 100644 (file)
-/***********************************************************************\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
-/* Range encoder for one symbol */\r
-void SKP_Silk_range_encoder(\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int                   data,               /* I    uncompressed data                           */\r
-    const SKP_uint16                prob[]              /* I    cumulative density functions                */\r
-)\r
-{\r
-    SKP_uint32 low_Q16, high_Q16;\r
-    SKP_uint32 base_tmp, range_Q32;\r
-\r
-    /* Copy structure data */\r
-    SKP_uint32 base_Q32  = psRC->base_Q32;\r
-    SKP_uint32 range_Q16 = psRC->range_Q16;\r
-    SKP_int32  bufferIx  = psRC->bufferIx;\r
-    SKP_uint8  *buffer   = psRC->buffer;\r
-\r
-    if( psRC->error ) {\r
-        return;\r
-    }\r
-\r
-    /* Update interval */\r
-    low_Q16  = prob[ data ];\r
-    high_Q16 = prob[ data + 1 ];\r
-    base_tmp = base_Q32; /* save current base, to test for carry */\r
-    base_Q32 += SKP_MUL_uint( range_Q16, low_Q16 );\r
-    range_Q32 = SKP_MUL_uint( range_Q16, high_Q16 - low_Q16 );\r
-\r
-    /* Check for carry */\r
-    if( base_Q32 < base_tmp ) {\r
-        /* Propagate carry in buffer */\r
-        SKP_int bufferIx_tmp = bufferIx;\r
-        while( ( ++buffer[ --bufferIx_tmp ] ) == 0 );\r
-    }\r
-\r
-    /* Check normalization */\r
-    if( range_Q32 & 0xFF000000 ) {\r
-        /* No normalization */\r
-        range_Q16 = SKP_RSHIFT_uint( range_Q32, 16 );\r
-    } else {\r
-        if( range_Q32 & 0xFFFF0000 ) {\r
-            /* Normalization of 8 bits shift */\r
-            range_Q16 = SKP_RSHIFT_uint( range_Q32, 8 );\r
-        } else {\r
-            /* Normalization of 16 bits shift */\r
-            range_Q16 = range_Q32;\r
-            /* Make sure not to write beyond buffer */\r
-            if( bufferIx >= psRC->bufferLength ) {\r
-                psRC->error = RANGE_CODER_WRITE_BEYOND_BUFFER;\r
-                return;\r
-            }\r
-            /* Write one byte to buffer */\r
-            buffer[ bufferIx++ ] = (SKP_uint8)( SKP_RSHIFT_uint( base_Q32, 24 ) );\r
-            base_Q32 = SKP_LSHIFT_ovflw( base_Q32, 8 );\r
-        }\r
-        /* Make sure not to write beyond buffer */\r
-        if( bufferIx >= psRC->bufferLength ) {\r
-            psRC->error = RANGE_CODER_WRITE_BEYOND_BUFFER;\r
-            return;\r
-        }\r
-        /* Write one byte to buffer */\r
-        buffer[ bufferIx++ ] = (SKP_uint8)( SKP_RSHIFT_uint( base_Q32, 24 ) );\r
-        base_Q32 = SKP_LSHIFT_ovflw( base_Q32, 8 );\r
-    }\r
-\r
-    /* Copy structure data back */\r
-    psRC->base_Q32  = base_Q32;\r
-    psRC->range_Q16 = range_Q16;\r
-    psRC->bufferIx  = bufferIx;\r
-}\r
-\r
-/* Range encoder for multiple symbols */\r
-void SKP_Silk_range_encoder_multi(\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int                   data[],             /* I    uncompressed data    [nSymbols]             */\r
-    const SKP_uint16 * const        prob[],             /* I    cumulative density functions                */\r
-    const SKP_int                   nSymbols            /* I    number of data symbols                      */\r
-)\r
-{\r
-    SKP_int k;\r
-    for( k = 0; k < nSymbols; k++ ) {\r
-        SKP_Silk_range_encoder( psRC, data[ k ], prob[ k ] );\r
-    }\r
-}\r
-\r
-/* Range decoder for one symbol */\r
-void SKP_Silk_range_decoder(\r
-    SKP_int                         data[],             /* O    uncompressed data                           */\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_uint16                prob[],             /* I    cumulative density function                 */\r
-    SKP_int                         probIx              /* I    initial (middle) entry of cdf               */\r
-)\r
-{\r
-    SKP_uint32 low_Q16, high_Q16;\r
-    SKP_uint32 base_tmp, range_Q32;\r
-\r
-    /* Copy structure data */\r
-    SKP_uint32 base_Q32  = psRC->base_Q32;\r
-    SKP_uint32 range_Q16 = psRC->range_Q16;\r
-    SKP_int32  bufferIx  = psRC->bufferIx;\r
-    SKP_uint8  *buffer   = &psRC->buffer[ 4 ];\r
-\r
-    if( psRC->error ) {\r
-        /* Set output to zero */\r
-        *data = 0;\r
-        return;\r
-    }\r
-\r
-    high_Q16 = prob[ probIx ];\r
-    base_tmp = SKP_MUL_uint( range_Q16, high_Q16 );\r
-    if( base_tmp > base_Q32 ) {\r
-        while( 1 ) {\r
-            low_Q16 = prob[ --probIx ];\r
-            base_tmp = SKP_MUL_uint( range_Q16, low_Q16 );\r
-            if( base_tmp <= base_Q32 ) {\r
-                break;\r
-            }\r
-            high_Q16 = low_Q16;\r
-            /* Test for out of range */\r
-            if( high_Q16 == 0 ) {\r
-                psRC->error = RANGE_CODER_CDF_OUT_OF_RANGE;\r
-                /* Set output to zero */\r
-                *data = 0;\r
-                return;\r
-            }\r
-        }\r
-    } else {\r
-        while( 1 ) {\r
-            low_Q16  = high_Q16;\r
-            high_Q16 = prob[ ++probIx ];\r
-            base_tmp = SKP_MUL_uint( range_Q16, high_Q16 );\r
-            if( base_tmp > base_Q32 ) {\r
-                probIx--;\r
-                break;\r
-            }\r
-            /* Test for out of range */\r
-            if( high_Q16 == 0xFFFF ) {\r
-                psRC->error = RANGE_CODER_CDF_OUT_OF_RANGE;\r
-                /* Set output to zero */\r
-                *data = 0;\r
-                return;\r
-            }\r
-        }\r
-    }\r
-    *data = probIx;\r
-    base_Q32 -= SKP_MUL_uint( range_Q16, low_Q16 );\r
-    range_Q32 = SKP_MUL_uint( range_Q16, high_Q16 - low_Q16 );\r
-\r
-    /* Check normalization */\r
-    if( range_Q32 & 0xFF000000 ) {\r
-        /* No normalization */\r
-        range_Q16 = SKP_RSHIFT_uint( range_Q32, 16 );\r
-    } else {\r
-        if( range_Q32 & 0xFFFF0000 ) {\r
-            /* Normalization of 8 bits shift */\r
-            range_Q16 = SKP_RSHIFT_uint( range_Q32, 8 );\r
-            /* Check for errors */\r
-            if( SKP_RSHIFT_uint( base_Q32, 24 ) ) {\r
-                psRC->error = RANGE_CODER_NORMALIZATION_FAILED;\r
-                /* Set output to zero */\r
-                *data = 0;\r
-                return;\r
-            }\r
-        } else {\r
-            /* Normalization of 16 bits shift */\r
-            range_Q16 = range_Q32;\r
-            /* Check for errors */\r
-            if( SKP_RSHIFT( base_Q32, 16 ) ) {\r
-                psRC->error = RANGE_CODER_NORMALIZATION_FAILED;\r
-                /* Set output to zero */\r
-                *data = 0;\r
-                return;\r
-            }\r
-            /* Update base */\r
-            base_Q32 = SKP_LSHIFT_uint( base_Q32, 8 );\r
-            /* Make sure not to read beyond buffer */\r
-            if( bufferIx < psRC->bufferLength ) {\r
-                /* Read one byte from buffer */\r
-                base_Q32 |= (SKP_uint32)buffer[ bufferIx++ ];\r
-            }\r
-        }\r
-        /* Update base */\r
-        base_Q32 = SKP_LSHIFT_uint( base_Q32, 8 );\r
-        /* Make sure not to read beyond buffer */\r
-        if( bufferIx < psRC->bufferLength ) {\r
-            /* Read one byte from buffer */\r
-            base_Q32 |= (SKP_uint32)buffer[ bufferIx++ ];\r
-        }\r
-    }\r
-\r
-    /* Check for zero interval length */\r
-    if( range_Q16 == 0 ) {\r
-        psRC->error = RANGE_CODER_ZERO_INTERVAL_WIDTH;\r
-        /* Set output to zero */\r
-        *data = 0;\r
-        return;\r
-    }\r
-\r
-    /* Copy structure data back */\r
-    psRC->base_Q32  = base_Q32;\r
-    psRC->range_Q16 = range_Q16;\r
-    psRC->bufferIx  = bufferIx;\r
-}\r
-\r
-/* Range decoder for multiple symbols */\r
-void SKP_Silk_range_decoder_multi(\r
-    SKP_int                         data[],             /* O    uncompressed data                [nSymbols] */\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_uint16 * const        prob[],             /* I    cumulative density functions                */\r
-    const SKP_int                   probStartIx[],      /* I    initial (middle) entries of cdfs [nSymbols] */\r
-    const SKP_int                   nSymbols            /* I    number of data symbols                      */\r
-)\r
-{\r
-    SKP_int k;\r
-    for( k = 0; k < nSymbols; k++ ) {\r
-        SKP_Silk_range_decoder( &data[ k ], psRC, prob[ k ], probStartIx[ k ] );\r
-    }\r
-}\r
-\r
-/* Initialize range encoder */\r
-void SKP_Silk_range_enc_init(\r
-    SKP_Silk_range_coder_state      *psRC               /* O    compressor data structure                   */\r
-)\r
-{\r
-    /* Initialize structure */\r
-    psRC->bufferLength = MAX_ARITHM_BYTES;\r
-    psRC->range_Q16    = 0x0000FFFF;\r
-    psRC->bufferIx     = 0;\r
-    psRC->base_Q32     = 0;\r
-    psRC->error        = 0;\r
-}\r
-\r
-/* Initialize range decoder */\r
-void SKP_Silk_range_dec_init(\r
-    SKP_Silk_range_coder_state      *psRC,              /* O    compressor data structure                   */\r
-    const SKP_uint8                 buffer[],           /* I    buffer for compressed data [bufferLength]   */\r
-    const SKP_int32                 bufferLength        /* I    buffer length (in bytes)                    */\r
-)\r
-{\r
-    /* check input */\r
-    if( bufferLength > MAX_ARITHM_BYTES ) {\r
-        psRC->error = RANGE_CODER_DEC_PAYLOAD_TOO_LONG;\r
-        return;\r
-    }\r
-    /* Initialize structure */\r
-    /* Copy to internal buffer */\r
-    SKP_memcpy( psRC->buffer, buffer, bufferLength * sizeof( SKP_uint8 ) ); \r
-    psRC->bufferLength = bufferLength;\r
-    psRC->bufferIx = 0;\r
-    psRC->base_Q32 = \r
-        SKP_LSHIFT_uint( (SKP_uint32)buffer[ 0 ], 24 ) | \r
-        SKP_LSHIFT_uint( (SKP_uint32)buffer[ 1 ], 16 ) | \r
-        SKP_LSHIFT_uint( (SKP_uint32)buffer[ 2 ],  8 ) | \r
-                         (SKP_uint32)buffer[ 3 ];\r
-    psRC->range_Q16 = 0x0000FFFF;\r
-    psRC->error     = 0;\r
-}\r
-\r
-/* Determine length of bitstream */\r
-SKP_int SKP_Silk_range_coder_get_length(                /* O    returns number of BITS in stream            */\r
-    const SKP_Silk_range_coder_state    *psRC,          /* I    compressed data structure                   */\r
-    SKP_int                             *nBytes         /* O    number of BYTES in stream                   */\r
-)\r
-{\r
-    SKP_int nBits;\r
-\r
-    /* Number of bits in stream */\r
-    nBits = SKP_LSHIFT( psRC->bufferIx, 3 ) + SKP_Silk_CLZ32( psRC->range_Q16 - 1 ) - 14;\r
-\r
-    *nBytes = SKP_RSHIFT( nBits + 7, 3 );\r
-\r
-    /* Return number of bits in bitstream */\r
-    return nBits;\r
-}\r
-\r
-/* Write shortest uniquely decodable stream to buffer, and determine its length */\r
-void SKP_Silk_range_enc_wrap_up(\r
-    SKP_Silk_range_coder_state      *psRC               /* I/O  compressed data structure                   */\r
-)\r
-{\r
-    SKP_int bufferIx_tmp, bits_to_store, bits_in_stream, nBytes, mask;\r
-    SKP_uint32 base_Q24;\r
-\r
-    /* Lower limit of interval, shifted 8 bits to the right */\r
-    base_Q24 = SKP_RSHIFT_uint( psRC->base_Q32, 8 );\r
-\r
-    bits_in_stream = SKP_Silk_range_coder_get_length( psRC, &nBytes );\r
-\r
-    /* Number of additional bits (1..9) required to be stored to stream */\r
-    bits_to_store = bits_in_stream - SKP_LSHIFT( psRC->bufferIx, 3 );\r
-    /* Round up to required resolution */\r
-    base_Q24 += SKP_RSHIFT_uint(  0x00800000, bits_to_store - 1 );\r
-    base_Q24 &= SKP_LSHIFT_ovflw( 0xFFFFFFFF, 24 - bits_to_store );\r
-\r
-    /* Check for carry */\r
-    if( base_Q24 & 0x01000000 ) {\r
-        /* Propagate carry in buffer */\r
-        bufferIx_tmp = psRC->bufferIx;\r
-        while( ( ++( psRC->buffer[ --bufferIx_tmp ] ) ) == 0 );\r
-    }\r
-\r
-    /* Store to stream, making sure not to write beyond buffer */\r
-    if( psRC->bufferIx < psRC->bufferLength ) {\r
-        psRC->buffer[ psRC->bufferIx++ ] = (SKP_uint8)SKP_RSHIFT_uint( base_Q24, 16 );\r
-        if( bits_to_store > 8 ) {\r
-            if( psRC->bufferIx < psRC->bufferLength ) {\r
-                psRC->buffer[ psRC->bufferIx++ ] = (SKP_uint8)SKP_RSHIFT_uint( base_Q24, 8 );\r
-            }\r
-        }\r
-    }\r
-\r
-    /* Fill up any remaining bits in the last byte with 1s */\r
-    if( bits_in_stream & 7 ) {\r
-        mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 );\r
-        if( nBytes - 1 < psRC->bufferLength ) {\r
-            psRC->buffer[ nBytes - 1 ] |= mask;\r
-        }\r
-    }\r
-}\r
-\r
-/* Check that any remaining bits in the last byte are set to 1 */\r
-void SKP_Silk_range_coder_check_after_decoding(\r
-    SKP_Silk_range_coder_state      *psRC               /* I/O  compressed data structure                   */\r
-)\r
-{\r
-    SKP_int bits_in_stream, nBytes, mask;\r
-\r
-    bits_in_stream = SKP_Silk_range_coder_get_length( psRC, &nBytes );\r
-\r
-    /* Make sure not to read beyond buffer */\r
-    if( nBytes - 1 >= psRC->bufferLength ) {\r
-        psRC->error = RANGE_CODER_DECODER_CHECK_FAILED;\r
-        return;\r
-    }\r
-\r
-    /* Test any remaining bits in last byte */\r
-    if( bits_in_stream & 7 ) {\r
-        mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 );\r
-        if( ( psRC->buffer[ nBytes - 1 ] & mask ) != mask ) {\r
-            psRC->error = RANGE_CODER_DECODER_CHECK_FAILED;\r
-            return;\r
-        }\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Range encoder for one symbol */
+void SKP_Silk_range_encoder(
+    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
+    const SKP_int                   data,               /* I    uncompressed data                           */
+    const SKP_uint16                prob[]              /* I    cumulative density functions                */
+)
+{
+    SKP_uint32 low_Q16, high_Q16;
+    SKP_uint32 base_tmp, range_Q32;
+
+    /* Copy structure data */
+    SKP_uint32 base_Q32  = psRC->base_Q32;
+    SKP_uint32 range_Q16 = psRC->range_Q16;
+    SKP_int32  bufferIx  = psRC->bufferIx;
+    SKP_uint8  *buffer   = psRC->buffer;
+
+    if( psRC->error ) {
+        return;
+    }
+
+    /* Update interval */
+    low_Q16  = prob[ data ];
+    high_Q16 = prob[ data + 1 ];
+    base_tmp = base_Q32; /* save current base, to test for carry */
+    base_Q32 += SKP_MUL_uint( range_Q16, low_Q16 );
+    range_Q32 = SKP_MUL_uint( range_Q16, high_Q16 - low_Q16 );
+
+    /* Check for carry */
+    if( base_Q32 < base_tmp ) {
+        /* Propagate carry in buffer */
+        SKP_int bufferIx_tmp = bufferIx;
+        while( ( ++buffer[ --bufferIx_tmp ] ) == 0 );
+    }
+
+    /* Check normalization */
+    if( range_Q32 & 0xFF000000 ) {
+        /* No normalization */
+        range_Q16 = SKP_RSHIFT_uint( range_Q32, 16 );
+    } else {
+        if( range_Q32 & 0xFFFF0000 ) {
+            /* Normalization of 8 bits shift */
+            range_Q16 = SKP_RSHIFT_uint( range_Q32, 8 );
+        } else {
+            /* Normalization of 16 bits shift */
+            range_Q16 = range_Q32;
+            /* Make sure not to write beyond buffer */
+            if( bufferIx >= psRC->bufferLength ) {
+                psRC->error = RANGE_CODER_WRITE_BEYOND_BUFFER;
+                return;
+            }
+            /* Write one byte to buffer */
+            buffer[ bufferIx++ ] = (SKP_uint8)( SKP_RSHIFT_uint( base_Q32, 24 ) );
+            base_Q32 = SKP_LSHIFT_ovflw( base_Q32, 8 );
+        }
+        /* Make sure not to write beyond buffer */
+        if( bufferIx >= psRC->bufferLength ) {
+            psRC->error = RANGE_CODER_WRITE_BEYOND_BUFFER;
+            return;
+        }
+        /* Write one byte to buffer */
+        buffer[ bufferIx++ ] = (SKP_uint8)( SKP_RSHIFT_uint( base_Q32, 24 ) );
+        base_Q32 = SKP_LSHIFT_ovflw( base_Q32, 8 );
+    }
+
+    /* Copy structure data back */
+    psRC->base_Q32  = base_Q32;
+    psRC->range_Q16 = range_Q16;
+    psRC->bufferIx  = bufferIx;
+}
+
+/* Range encoder for multiple symbols */
+void SKP_Silk_range_encoder_multi(
+    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
+    const SKP_int                   data[],             /* I    uncompressed data    [nSymbols]             */
+    const SKP_uint16 * const        prob[],             /* I    cumulative density functions                */
+    const SKP_int                   nSymbols            /* I    number of data symbols                      */
+)
+{
+    SKP_int k;
+    for( k = 0; k < nSymbols; k++ ) {
+        SKP_Silk_range_encoder( psRC, data[ k ], prob[ k ] );
+    }
+}
+
+/* Range decoder for one symbol */
+void SKP_Silk_range_decoder(
+    SKP_int                         data[],             /* O    uncompressed data                           */
+    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
+    const SKP_uint16                prob[],             /* I    cumulative density function                 */
+    SKP_int                         probIx              /* I    initial (middle) entry of cdf               */
+)
+{
+    SKP_uint32 low_Q16, high_Q16;
+    SKP_uint32 base_tmp, range_Q32;
+
+    /* Copy structure data */
+    SKP_uint32 base_Q32  = psRC->base_Q32;
+    SKP_uint32 range_Q16 = psRC->range_Q16;
+    SKP_int32  bufferIx  = psRC->bufferIx;
+    SKP_uint8  *buffer   = &psRC->buffer[ 4 ];
+
+    if( psRC->error ) {
+        /* Set output to zero */
+        *data = 0;
+        return;
+    }
+
+    high_Q16 = prob[ probIx ];
+    base_tmp = SKP_MUL_uint( range_Q16, high_Q16 );
+    if( base_tmp > base_Q32 ) {
+        while( 1 ) {
+            low_Q16 = prob[ --probIx ];
+            base_tmp = SKP_MUL_uint( range_Q16, low_Q16 );
+            if( base_tmp <= base_Q32 ) {
+                break;
+            }
+            high_Q16 = low_Q16;
+            /* Test for out of range */
+            if( high_Q16 == 0 ) {
+                psRC->error = RANGE_CODER_CDF_OUT_OF_RANGE;
+                /* Set output to zero */
+                *data = 0;
+                return;
+            }
+        }
+    } else {
+        while( 1 ) {
+            low_Q16  = high_Q16;
+            high_Q16 = prob[ ++probIx ];
+            base_tmp = SKP_MUL_uint( range_Q16, high_Q16 );
+            if( base_tmp > base_Q32 ) {
+                probIx--;
+                break;
+            }
+            /* Test for out of range */
+            if( high_Q16 == 0xFFFF ) {
+                psRC->error = RANGE_CODER_CDF_OUT_OF_RANGE;
+                /* Set output to zero */
+                *data = 0;
+                return;
+            }
+        }
+    }
+    *data = probIx;
+    base_Q32 -= SKP_MUL_uint( range_Q16, low_Q16 );
+    range_Q32 = SKP_MUL_uint( range_Q16, high_Q16 - low_Q16 );
+
+    /* Check normalization */
+    if( range_Q32 & 0xFF000000 ) {
+        /* No normalization */
+        range_Q16 = SKP_RSHIFT_uint( range_Q32, 16 );
+    } else {
+        if( range_Q32 & 0xFFFF0000 ) {
+            /* Normalization of 8 bits shift */
+            range_Q16 = SKP_RSHIFT_uint( range_Q32, 8 );
+            /* Check for errors */
+            if( SKP_RSHIFT_uint( base_Q32, 24 ) ) {
+                psRC->error = RANGE_CODER_NORMALIZATION_FAILED;
+                /* Set output to zero */
+                *data = 0;
+                return;
+            }
+        } else {
+            /* Normalization of 16 bits shift */
+            range_Q16 = range_Q32;
+            /* Check for errors */
+            if( SKP_RSHIFT( base_Q32, 16 ) ) {
+                psRC->error = RANGE_CODER_NORMALIZATION_FAILED;
+                /* Set output to zero */
+                *data = 0;
+                return;
+            }
+            /* Update base */
+            base_Q32 = SKP_LSHIFT_uint( base_Q32, 8 );
+            /* Make sure not to read beyond buffer */
+            if( bufferIx < psRC->bufferLength ) {
+                /* Read one byte from buffer */
+                base_Q32 |= (SKP_uint32)buffer[ bufferIx++ ];
+            }
+        }
+        /* Update base */
+        base_Q32 = SKP_LSHIFT_uint( base_Q32, 8 );
+        /* Make sure not to read beyond buffer */
+        if( bufferIx < psRC->bufferLength ) {
+            /* Read one byte from buffer */
+            base_Q32 |= (SKP_uint32)buffer[ bufferIx++ ];
+        }
+    }
+
+    /* Check for zero interval length */
+    if( range_Q16 == 0 ) {
+        psRC->error = RANGE_CODER_ZERO_INTERVAL_WIDTH;
+        /* Set output to zero */
+        *data = 0;
+        return;
+    }
+
+    /* Copy structure data back */
+    psRC->base_Q32  = base_Q32;
+    psRC->range_Q16 = range_Q16;
+    psRC->bufferIx  = bufferIx;
+}
+
+/* Range decoder for multiple symbols */
+void SKP_Silk_range_decoder_multi(
+    SKP_int                         data[],             /* O    uncompressed data                [nSymbols] */
+    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
+    const SKP_uint16 * const        prob[],             /* I    cumulative density functions                */
+    const SKP_int                   probStartIx[],      /* I    initial (middle) entries of cdfs [nSymbols] */
+    const SKP_int                   nSymbols            /* I    number of data symbols                      */
+)
+{
+    SKP_int k;
+    for( k = 0; k < nSymbols; k++ ) {
+        SKP_Silk_range_decoder( &data[ k ], psRC, prob[ k ], probStartIx[ k ] );
+    }
+}
+
+/* Initialize range encoder */
+void SKP_Silk_range_enc_init(
+    SKP_Silk_range_coder_state      *psRC               /* O    compressor data structure                   */
+)
+{
+    /* Initialize structure */
+    psRC->bufferLength = MAX_ARITHM_BYTES;
+    psRC->range_Q16    = 0x0000FFFF;
+    psRC->bufferIx     = 0;
+    psRC->base_Q32     = 0;
+    psRC->error        = 0;
+}
+
+/* Initialize range decoder */
+void SKP_Silk_range_dec_init(
+    SKP_Silk_range_coder_state      *psRC,              /* O    compressor data structure                   */
+    const SKP_uint8                 buffer[],           /* I    buffer for compressed data [bufferLength]   */
+    const SKP_int32                 bufferLength        /* I    buffer length (in bytes)                    */
+)
+{
+    /* check input */
+    if( bufferLength > MAX_ARITHM_BYTES ) {
+        psRC->error = RANGE_CODER_DEC_PAYLOAD_TOO_LONG;
+        return;
+    }
+    /* Initialize structure */
+    /* Copy to internal buffer */
+    SKP_memcpy( psRC->buffer, buffer, bufferLength * sizeof( SKP_uint8 ) ); 
+    psRC->bufferLength = bufferLength;
+    psRC->bufferIx = 0;
+    psRC->base_Q32 = 
+        SKP_LSHIFT_uint( (SKP_uint32)buffer[ 0 ], 24 ) | 
+        SKP_LSHIFT_uint( (SKP_uint32)buffer[ 1 ], 16 ) | 
+        SKP_LSHIFT_uint( (SKP_uint32)buffer[ 2 ],  8 ) | 
+                         (SKP_uint32)buffer[ 3 ];
+    psRC->range_Q16 = 0x0000FFFF;
+    psRC->error     = 0;
+}
+
+/* Determine length of bitstream */
+SKP_int SKP_Silk_range_coder_get_length(                /* O    returns number of BITS in stream            */
+    const SKP_Silk_range_coder_state    *psRC,          /* I    compressed data structure                   */
+    SKP_int                             *nBytes         /* O    number of BYTES in stream                   */
+)
+{
+    SKP_int nBits;
+
+    /* Number of bits in stream */
+    nBits = SKP_LSHIFT( psRC->bufferIx, 3 ) + SKP_Silk_CLZ32( psRC->range_Q16 - 1 ) - 14;
+
+    *nBytes = SKP_RSHIFT( nBits + 7, 3 );
+
+    /* Return number of bits in bitstream */
+    return nBits;
+}
+
+/* Write shortest uniquely decodable stream to buffer, and determine its length */
+void SKP_Silk_range_enc_wrap_up(
+    SKP_Silk_range_coder_state      *psRC               /* I/O  compressed data structure                   */
+)
+{
+    SKP_int bufferIx_tmp, bits_to_store, bits_in_stream, nBytes, mask;
+    SKP_uint32 base_Q24;
+
+    /* Lower limit of interval, shifted 8 bits to the right */
+    base_Q24 = SKP_RSHIFT_uint( psRC->base_Q32, 8 );
+
+    bits_in_stream = SKP_Silk_range_coder_get_length( psRC, &nBytes );
+
+    /* Number of additional bits (1..9) required to be stored to stream */
+    bits_to_store = bits_in_stream - SKP_LSHIFT( psRC->bufferIx, 3 );
+    /* Round up to required resolution */
+    base_Q24 += SKP_RSHIFT_uint(  0x00800000, bits_to_store - 1 );
+    base_Q24 &= SKP_LSHIFT_ovflw( 0xFFFFFFFF, 24 - bits_to_store );
+
+    /* Check for carry */
+    if( base_Q24 & 0x01000000 ) {
+        /* Propagate carry in buffer */
+        bufferIx_tmp = psRC->bufferIx;
+        while( ( ++( psRC->buffer[ --bufferIx_tmp ] ) ) == 0 );
+    }
+
+    /* Store to stream, making sure not to write beyond buffer */
+    if( psRC->bufferIx < psRC->bufferLength ) {
+        psRC->buffer[ psRC->bufferIx++ ] = (SKP_uint8)SKP_RSHIFT_uint( base_Q24, 16 );
+        if( bits_to_store > 8 ) {
+            if( psRC->bufferIx < psRC->bufferLength ) {
+                psRC->buffer[ psRC->bufferIx++ ] = (SKP_uint8)SKP_RSHIFT_uint( base_Q24, 8 );
+            }
+        }
+    }
+
+    /* Fill up any remaining bits in the last byte with 1s */
+    if( bits_in_stream & 7 ) {
+        mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 );
+        if( nBytes - 1 < psRC->bufferLength ) {
+            psRC->buffer[ nBytes - 1 ] |= mask;
+        }
+    }
+}
+
+/* Check that any remaining bits in the last byte are set to 1 */
+void SKP_Silk_range_coder_check_after_decoding(
+    SKP_Silk_range_coder_state      *psRC               /* I/O  compressed data structure                   */
+)
+{
+    SKP_int bits_in_stream, nBytes, mask;
+
+    bits_in_stream = SKP_Silk_range_coder_get_length( psRC, &nBytes );
+
+    /* Make sure not to read beyond buffer */
+    if( nBytes - 1 >= psRC->bufferLength ) {
+        psRC->error = RANGE_CODER_DECODER_CHECK_FAILED;
+        return;
+    }
+
+    /* Test any remaining bits in last byte */
+    if( bits_in_stream & 7 ) {
+        mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 );
+        if( ( psRC->buffer[ nBytes - 1 ] & mask ) != mask ) {
+            psRC->error = RANGE_CODER_DECODER_CHECK_FAILED;
+            return;
+        }
+    }
+}
index f30f631cf8f76b413ec217da9a11330e059ad437..3c168e971a4d571ce51adb44fd8d32c7d176e975 100644 (file)
@@ -1,43 +1,43 @@
-/***********************************************************************\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_FIX.h"\r
-\r
-/* Add noise to matrix diagonal */\r
-void SKP_Silk_regularize_correlations_FIX(\r
-    SKP_int32                       *XX,                /* I/O  Correlation matrices                        */\r
-    SKP_int32                       *xx,                /* I/O  Correlation values                          */\r
-    SKP_int32                       noise,              /* I    Noise to add                                */\r
-    SKP_int                         D                   /* I    Dimension of XX                             */\r
-)\r
-{\r
-    SKP_int i;\r
-    for( i = 0; i < D; i++ ) {\r
-        matrix_ptr( &XX[ 0 ], i, i, D ) = SKP_ADD32( matrix_ptr( &XX[ 0 ], i, i, D ), noise );\r
-    }\r
-    xx[ 0 ] += noise;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+/* Add noise to matrix diagonal */
+void SKP_Silk_regularize_correlations_FIX(
+    SKP_int32                       *XX,                /* I/O  Correlation matrices                        */
+    SKP_int32                       *xx,                /* I/O  Correlation values                          */
+    SKP_int32                       noise,              /* I    Noise to add                                */
+    SKP_int                         D                   /* I    Dimension of XX                             */
+)
+{
+    SKP_int i;
+    for( i = 0; i < D; i++ ) {
+        matrix_ptr( &XX[ 0 ], i, i, D ) = SKP_ADD32( matrix_ptr( &XX[ 0 ], i, i, D ), noise );
+    }
+    xx[ 0 ] += noise;
+}
index 980f81fefc887abb3339f5f2a361a625e902ee26..40a1b1a0ca77498bb7ed4bed50cce10b015c8938 100644 (file)
-/***********************************************************************\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
- * File Name:  SKP_Silk_resampler.c                                                                    *\r
- *                                                                                                                                             *\r
- * Description: Interface to collection of resamplers                                  *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- * All rights reserved.                                                                                                        *\r
- *                                                                      */\r
-\r
-/* Matrix of resampling methods used:\r
- *                                        Fs_out (kHz)\r
- *                        8      12     16     24     32     44.1   48\r
- *\r
- *               8        C      UF     U      UF     UF     UF     UF\r
- *              12        AF     C      UF     U      UF     UF     UF\r
- *              16        D      AF     C      UF     U      UF     UF\r
- * Fs_in (kHz)  24        AIF    D      AF     C      UF     UF     U\r
- *              32        UF     AF     D      AF     C      UF     UF\r
- *              44.1      AMI    AMI    AMI    AMI    AMI    C      UF\r
- *              48        DAF    DAF    AF     D      AF     UF     C\r
- *\r
- * default method: UF\r
- *\r
- * C   -> Copy (no resampling)\r
- * D   -> Allpass-based 2x downsampling\r
- * U   -> Allpass-based 2x upsampling\r
- * DAF -> Allpass-based 2x downsampling followed by AR2 filter followed by FIR interpolation\r
- * UF  -> Allpass-based 2x upsampling followed by FIR interpolation\r
- * AMI -> ARMA4 filter followed by FIR interpolation\r
- * AF  -> AR2 filter followed by FIR interpolation\r
- *\r
- * Input signals sampled above 48 kHz are first downsampled to at most 48 kHz.\r
- * Output signals sampled above 48 kHz are upsampled from at most 48 kHz.\r
- */\r
-\r
-#include "SKP_Silk_resampler_private.h"\r
-\r
-/* Greatest common divisor */\r
-static SKP_int32 gcd(\r
-    SKP_int32 a,\r
-    SKP_int32 b\r
-)\r
-{\r
-    SKP_int32 tmp;\r
-    while( b > 0 ) {\r
-        tmp = a - b * SKP_DIV32( a, b );\r
-        a   = b;\r
-        b   = tmp;\r
-    }\r
-    return a;\r
-}\r
-\r
-/* Initialize/reset the resampler state for a given pair of input/output sampling rates */\r
-SKP_int SKP_Silk_resampler_init( \r
-       SKP_Silk_resampler_state_struct *S,                 /* I/O: Resampler state                     */\r
-       SKP_int32                                                       Fs_Hz_in,       /* I:   Input sampling rate (Hz)        */\r
-       SKP_int32                                                       Fs_Hz_out       /* I:   Output sampling rate (Hz)       */\r
-)\r
-{\r
-    SKP_int32 cycleLen, cyclesPerBatch, up2 = 0, down2 = 0;\r
-\r
-       /* Clear state */\r
-       SKP_memset( S, 0, sizeof( SKP_Silk_resampler_state_struct ) );\r
-\r
-       /* Input checking */\r
-#if RESAMPLER_SUPPORT_ABOVE_48KHZ\r
-       if( Fs_Hz_in < 8000 || Fs_Hz_in > 192000 || Fs_Hz_out < 8000 || Fs_Hz_out > 192000 ) {\r
-#else\r
-    if( Fs_Hz_in < 8000 || Fs_Hz_in >  48000 || Fs_Hz_out < 8000 || Fs_Hz_out >  48000 ) {\r
-#endif\r
-               SKP_assert( 0 );\r
-               return -1;\r
-       }\r
-\r
-#if RESAMPLER_SUPPORT_ABOVE_48KHZ\r
-       /* Determine pre downsampling and post upsampling */\r
-       if( Fs_Hz_in > 96000 ) {\r
-               S->nPreDownsamplers = 2;\r
-        S->down_pre_function = SKP_Silk_resampler_private_down4;\r
-    } else if( Fs_Hz_in > 48000 ) {\r
-               S->nPreDownsamplers = 1;\r
-        S->down_pre_function = SKP_Silk_resampler_down2;\r
-    } else {\r
-               S->nPreDownsamplers = 0;\r
-        S->down_pre_function = NULL;\r
-    }\r
-\r
-       if( Fs_Hz_out > 96000 ) {\r
-               S->nPostUpsamplers = 2;\r
-        S->up_post_function = SKP_Silk_resampler_private_up4;\r
-    } else if( Fs_Hz_out > 48000 ) {\r
-               S->nPostUpsamplers = 1;\r
-        S->up_post_function = SKP_Silk_resampler_up2;\r
-    } else {\r
-               S->nPostUpsamplers = 0;\r
-        S->up_post_function = NULL;\r
-    }\r
-\r
-    if( S->nPreDownsamplers + S->nPostUpsamplers > 0 ) {\r
-        /* Ratio of output/input samples */\r
-           S->ratio_Q16 = SKP_LSHIFT32( SKP_DIV32( SKP_LSHIFT32( Fs_Hz_out, 13 ), Fs_Hz_in ), 3 );\r
-        /* Make sure the ratio is rounded up */\r
-        while( SKP_SMULWW( S->ratio_Q16, Fs_Hz_in ) < Fs_Hz_out ) S->ratio_Q16++;\r
-\r
-        /* Batch size is 10 ms */\r
-        S->batchSizePrePost = SKP_DIV32_16( Fs_Hz_in, 100 );\r
-\r
-        /* Convert sampling rate to those after pre-downsampling and before post-upsampling */\r
-           Fs_Hz_in  = SKP_RSHIFT( Fs_Hz_in,  S->nPreDownsamplers  );\r
-           Fs_Hz_out = SKP_RSHIFT( Fs_Hz_out, S->nPostUpsamplers  );\r
-    }\r
-#endif\r
-\r
-    /* Number of samples processed per batch */\r
-    /* First, try 10 ms frames */\r
-    S->batchSize = SKP_DIV32_16( Fs_Hz_in, 100 );\r
-    if( ( SKP_MUL( S->batchSize, 100 ) != Fs_Hz_in ) || ( Fs_Hz_in % 100 != 0 ) ) {\r
-        /* No integer number of input or output samples with 10 ms frames, use greatest common divisor */\r
-        cycleLen = SKP_DIV32( Fs_Hz_in, gcd( Fs_Hz_in, Fs_Hz_out ) );\r
-        cyclesPerBatch = SKP_DIV32( RESAMPLER_MAX_BATCH_SIZE_IN, cycleLen );\r
-        if( cyclesPerBatch == 0 ) {\r
-            /* cycleLen too big, let's just use the maximum batch size. Some distortion will result. */\r
-            S->batchSize = RESAMPLER_MAX_BATCH_SIZE_IN;\r
-            SKP_assert( 0 );\r
-        } else {\r
-            S->batchSize = SKP_MUL( cyclesPerBatch, cycleLen );\r
-        }\r
-    }\r
-\r
-\r
-       /* Find resampler with the right sampling ratio */\r
-    if( Fs_Hz_out > Fs_Hz_in ) {\r
-        /* Upsample */\r
-        if( Fs_Hz_out == SKP_MUL( Fs_Hz_in, 2 ) ) {                             /* Fs_out : Fs_in = 2 : 1 */\r
-            /* Special case: directly use 2x upsampler */\r
-           S->resampler_function = SKP_Silk_resampler_private_up2_HQ_wrapper;\r
-        } else {\r
-               /* Default resampler */\r
-               S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
-            up2 = 1;\r
-            if( Fs_Hz_in > 24000 ) {\r
-                /* Low-quality all-pass upsampler */\r
-                S->up2_function = SKP_Silk_resampler_up2;\r
-            } else {\r
-                /* High-quality all-pass upsampler */\r
-                S->up2_function = SKP_Silk_resampler_private_up2_HQ;\r
-            }\r
-        }\r
-    } else if ( Fs_Hz_out < Fs_Hz_in ) {\r
-        /* Downsample */\r
-        if( SKP_MUL( Fs_Hz_out, 4 ) == SKP_MUL( Fs_Hz_in, 3 ) ) {               /* Fs_out : Fs_in = 3 : 4 */\r
-           S->FIR_Fracs = 3;\r
-           S->Coefs = SKP_Silk_Resampler_3_4_COEFS;\r
-           S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 3 ) == SKP_MUL( Fs_Hz_in, 2 ) ) {        /* Fs_out : Fs_in = 2 : 3 */\r
-           S->FIR_Fracs = 2;\r
-           S->Coefs = SKP_Silk_Resampler_2_3_COEFS;\r
-           S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 2 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 2 */\r
-           S->FIR_Fracs = 1;\r
-           S->Coefs = SKP_Silk_Resampler_1_2_COEFS;\r
-           S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 8 ) == SKP_MUL( Fs_Hz_in, 3 ) ) {        /* Fs_out : Fs_in = 3 : 8 */\r
-           S->FIR_Fracs = 3;\r
-           S->Coefs = SKP_Silk_Resampler_3_8_COEFS;\r
-           S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 3 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 3 */\r
-           S->FIR_Fracs = 1;\r
-           S->Coefs = SKP_Silk_Resampler_1_3_COEFS;\r
-           S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 4 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 4 */\r
-           S->FIR_Fracs = 1;\r
-            down2 = 1;\r
-           S->Coefs = SKP_Silk_Resampler_1_2_COEFS;\r
-            S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 6 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 6 */\r
-           S->FIR_Fracs = 1;\r
-            down2 = 1;\r
-           S->Coefs = SKP_Silk_Resampler_1_3_COEFS;\r
-            S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 80 ) ) {     /* Fs_out : Fs_in = 80 : 441 */\r
-           S->Coefs = SKP_Silk_Resampler_80_441_ARMA4_COEFS;\r
-           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 120 ) ) {    /* Fs_out : Fs_in = 120 : 441 */\r
-           S->Coefs = SKP_Silk_Resampler_120_441_ARMA4_COEFS;\r
-           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 160 ) ) {    /* Fs_out : Fs_in = 160 : 441 */\r
-           S->Coefs = SKP_Silk_Resampler_160_441_ARMA4_COEFS;\r
-           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 240 ) ) {    /* Fs_out : Fs_in = 240 : 441 */\r
-           S->Coefs = SKP_Silk_Resampler_240_441_ARMA4_COEFS;\r
-           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
-        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 320 ) ) {    /* Fs_out : Fs_in = 320 : 441 */\r
-           S->Coefs = SKP_Silk_Resampler_320_441_ARMA4_COEFS;\r
-           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
-        } else {\r
-               /* Default resampler */\r
-               S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
-            up2 = 1;\r
-            if( Fs_Hz_in > 24000 ) {\r
-                /* Low-quality all-pass upsampler */\r
-                S->up2_function = SKP_Silk_resampler_up2;\r
-            } else {\r
-                /* High-quality all-pass upsampler */\r
-                S->up2_function = SKP_Silk_resampler_private_up2_HQ;\r
-            }\r
-        }\r
-    } else {\r
-        /* Input and output sampling rates are equal: copy */\r
-        S->resampler_function = SKP_Silk_resampler_private_copy;\r
-    }\r
-\r
-    S->input2x = up2 | down2;\r
-\r
-    /* Ratio of input/output samples */\r
-    S->invRatio_Q16 = SKP_LSHIFT32( SKP_DIV32( SKP_LSHIFT32( Fs_Hz_in, 14 + up2 - down2 ), Fs_Hz_out ), 2 );\r
-    /* Make sure the ratio is rounded up */\r
-    while( SKP_SMULWW( S->invRatio_Q16, SKP_LSHIFT32( Fs_Hz_out, down2 ) ) < SKP_LSHIFT32( Fs_Hz_in, up2 ) ) {\r
-        S->invRatio_Q16++;\r
-    }\r
-\r
-       S->magic_number = 123456789;\r
-\r
-       return 0;\r
-}\r
-\r
-/* Clear the states of all resampling filters, without resetting sampling rate ratio */\r
-SKP_int SKP_Silk_resampler_clear( \r
-       SKP_Silk_resampler_state_struct *S                  /* I/O: Resampler state                     */\r
-)\r
-{\r
-       /* Clear state */\r
-       SKP_memset( S->sDown2, 0, sizeof( S->sDown2 ) );\r
-       SKP_memset( S->sIIR,   0, sizeof( S->sIIR ) );\r
-       SKP_memset( S->sFIR,   0, sizeof( S->sFIR ) );\r
-#if RESAMPLER_SUPPORT_ABOVE_48KHZ\r
-       SKP_memset( S->sDownPre, 0, sizeof( S->sDownPre ) );\r
-       SKP_memset( S->sUpPost,  0, sizeof( S->sUpPost ) );\r
-#endif\r
-    return 0;\r
-}\r
-\r
-/* Resampler: convert from one sampling rate to another                                 */\r
-SKP_int SKP_Silk_resampler( \r
-       SKP_Silk_resampler_state_struct *S,                 /* I/O: Resampler state                     */\r
-       SKP_int16                                                       out[],      /* O:       Output signal                           */\r
-       const SKP_int16                                         in[],       /* I:       Input signal                            */\r
-       SKP_int32                                                       inLen       /* I:       Number of input samples         */\r
-)\r
-{\r
-       /* Verify that state was initialized and has not been corrupted */\r
-    if( S->magic_number != 123456789 ) {\r
-        SKP_assert( 0 );\r
-        return -1;\r
-    }\r
-\r
-#if RESAMPLER_SUPPORT_ABOVE_48KHZ\r
-       if( S->nPreDownsamplers + S->nPostUpsamplers > 0 ) {\r
-               /* The input and/or output sampling rate is above 48000 Hz */\r
-        SKP_int32       nSamplesIn, nSamplesOut;\r
-               SKP_int16               in_buf[ 480 ], out_buf[ 480 ];\r
-\r
-        while( inLen > 0 ) {\r
-            /* Number of input and output samples to process */\r
-               nSamplesIn = SKP_min( inLen, S->batchSizePrePost );\r
-            nSamplesOut = SKP_SMULWB( S->ratio_Q16, nSamplesIn );\r
-\r
-            SKP_assert( SKP_RSHIFT32( nSamplesIn,  S->nPreDownsamplers ) <= 480 );\r
-            SKP_assert( SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers  ) <= 480 );\r
-\r
-               if( S->nPreDownsamplers > 0 ) {\r
-                S->down_pre_function( S->sDownPre, in_buf, in, nSamplesIn );\r
-                   if( S->nPostUpsamplers > 0 ) {\r
-                       S->resampler_function( S, out_buf, in_buf, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) );\r
-                    S->up_post_function( S->sUpPost, out, out_buf, SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers ) );\r
-                } else {\r
-                       S->resampler_function( S, out, in_buf, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) );\r
-                }\r
-            } else {\r
-                       S->resampler_function( S, out_buf, in, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) );\r
-                S->up_post_function( S->sUpPost, out, out_buf, SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers ) );\r
-            }\r
-\r
-               in += nSamplesIn;\r
-            out += nSamplesOut;\r
-               inLen -= nSamplesIn;\r
-        }\r
-       } else \r
-#endif\r
-       {\r
-               /* Input and output sampling rate are at most 48000 Hz */\r
-               S->resampler_function( S, out, in, inLen );\r
-       }\r
-\r
-       return 0;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                                                                                             *
+ * File Name:  SKP_Silk_resampler.c                                                                    *
+ *                                                                                                                                             *
+ * Description: Interface to collection of resamplers                                  *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ * All rights reserved.                                                                                                        *
+ *                                                                      */
+
+/* Matrix of resampling methods used:
+ *                                        Fs_out (kHz)
+ *                        8      12     16     24     32     44.1   48
+ *
+ *               8        C      UF     U      UF     UF     UF     UF
+ *              12        AF     C      UF     U      UF     UF     UF
+ *              16        D      AF     C      UF     U      UF     UF
+ * Fs_in (kHz)  24        AIF    D      AF     C      UF     UF     U
+ *              32        UF     AF     D      AF     C      UF     UF
+ *              44.1      AMI    AMI    AMI    AMI    AMI    C      UF
+ *              48        DAF    DAF    AF     D      AF     UF     C
+ *
+ * default method: UF
+ *
+ * C   -> Copy (no resampling)
+ * D   -> Allpass-based 2x downsampling
+ * U   -> Allpass-based 2x upsampling
+ * DAF -> Allpass-based 2x downsampling followed by AR2 filter followed by FIR interpolation
+ * UF  -> Allpass-based 2x upsampling followed by FIR interpolation
+ * AMI -> ARMA4 filter followed by FIR interpolation
+ * AF  -> AR2 filter followed by FIR interpolation
+ *
+ * Input signals sampled above 48 kHz are first downsampled to at most 48 kHz.
+ * Output signals sampled above 48 kHz are upsampled from at most 48 kHz.
+ */
+
+#include "SKP_Silk_resampler_private.h"
+
+/* Greatest common divisor */
+static SKP_int32 gcd(
+    SKP_int32 a,
+    SKP_int32 b
+)
+{
+    SKP_int32 tmp;
+    while( b > 0 ) {
+        tmp = a - b * SKP_DIV32( a, b );
+        a   = b;
+        b   = tmp;
+    }
+    return a;
+}
+
+/* Initialize/reset the resampler state for a given pair of input/output sampling rates */
+SKP_int SKP_Silk_resampler_init( 
+       SKP_Silk_resampler_state_struct *S,                 /* I/O: Resampler state                     */
+       SKP_int32                                                       Fs_Hz_in,       /* I:   Input sampling rate (Hz)        */
+       SKP_int32                                                       Fs_Hz_out       /* I:   Output sampling rate (Hz)       */
+)
+{
+    SKP_int32 cycleLen, cyclesPerBatch, up2 = 0, down2 = 0;
+
+       /* Clear state */
+       SKP_memset( S, 0, sizeof( SKP_Silk_resampler_state_struct ) );
+
+       /* Input checking */
+#if RESAMPLER_SUPPORT_ABOVE_48KHZ
+       if( Fs_Hz_in < 8000 || Fs_Hz_in > 192000 || Fs_Hz_out < 8000 || Fs_Hz_out > 192000 ) {
+#else
+    if( Fs_Hz_in < 8000 || Fs_Hz_in >  48000 || Fs_Hz_out < 8000 || Fs_Hz_out >  48000 ) {
+#endif
+               SKP_assert( 0 );
+               return -1;
+       }
+
+#if RESAMPLER_SUPPORT_ABOVE_48KHZ
+       /* Determine pre downsampling and post upsampling */
+       if( Fs_Hz_in > 96000 ) {
+               S->nPreDownsamplers = 2;
+        S->down_pre_function = SKP_Silk_resampler_private_down4;
+    } else if( Fs_Hz_in > 48000 ) {
+               S->nPreDownsamplers = 1;
+        S->down_pre_function = SKP_Silk_resampler_down2;
+    } else {
+               S->nPreDownsamplers = 0;
+        S->down_pre_function = NULL;
+    }
+
+       if( Fs_Hz_out > 96000 ) {
+               S->nPostUpsamplers = 2;
+        S->up_post_function = SKP_Silk_resampler_private_up4;
+    } else if( Fs_Hz_out > 48000 ) {
+               S->nPostUpsamplers = 1;
+        S->up_post_function = SKP_Silk_resampler_up2;
+    } else {
+               S->nPostUpsamplers = 0;
+        S->up_post_function = NULL;
+    }
+
+    if( S->nPreDownsamplers + S->nPostUpsamplers > 0 ) {
+        /* Ratio of output/input samples */
+           S->ratio_Q16 = SKP_LSHIFT32( SKP_DIV32( SKP_LSHIFT32( Fs_Hz_out, 13 ), Fs_Hz_in ), 3 );
+        /* Make sure the ratio is rounded up */
+        while( SKP_SMULWW( S->ratio_Q16, Fs_Hz_in ) < Fs_Hz_out ) S->ratio_Q16++;
+
+        /* Batch size is 10 ms */
+        S->batchSizePrePost = SKP_DIV32_16( Fs_Hz_in, 100 );
+
+        /* Convert sampling rate to those after pre-downsampling and before post-upsampling */
+           Fs_Hz_in  = SKP_RSHIFT( Fs_Hz_in,  S->nPreDownsamplers  );
+           Fs_Hz_out = SKP_RSHIFT( Fs_Hz_out, S->nPostUpsamplers  );
+    }
+#endif
+
+    /* Number of samples processed per batch */
+    /* First, try 10 ms frames */
+    S->batchSize = SKP_DIV32_16( Fs_Hz_in, 100 );
+    if( ( SKP_MUL( S->batchSize, 100 ) != Fs_Hz_in ) || ( Fs_Hz_in % 100 != 0 ) ) {
+        /* No integer number of input or output samples with 10 ms frames, use greatest common divisor */
+        cycleLen = SKP_DIV32( Fs_Hz_in, gcd( Fs_Hz_in, Fs_Hz_out ) );
+        cyclesPerBatch = SKP_DIV32( RESAMPLER_MAX_BATCH_SIZE_IN, cycleLen );
+        if( cyclesPerBatch == 0 ) {
+            /* cycleLen too big, let's just use the maximum batch size. Some distortion will result. */
+            S->batchSize = RESAMPLER_MAX_BATCH_SIZE_IN;
+            SKP_assert( 0 );
+        } else {
+            S->batchSize = SKP_MUL( cyclesPerBatch, cycleLen );
+        }
+    }
+
+
+       /* Find resampler with the right sampling ratio */
+    if( Fs_Hz_out > Fs_Hz_in ) {
+        /* Upsample */
+        if( Fs_Hz_out == SKP_MUL( Fs_Hz_in, 2 ) ) {                             /* Fs_out : Fs_in = 2 : 1 */
+            /* Special case: directly use 2x upsampler */
+           S->resampler_function = SKP_Silk_resampler_private_up2_HQ_wrapper;
+        } else {
+               /* Default resampler */
+               S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;
+            up2 = 1;
+            if( Fs_Hz_in > 24000 ) {
+                /* Low-quality all-pass upsampler */
+                S->up2_function = SKP_Silk_resampler_up2;
+            } else {
+                /* High-quality all-pass upsampler */
+                S->up2_function = SKP_Silk_resampler_private_up2_HQ;
+            }
+        }
+    } else if ( Fs_Hz_out < Fs_Hz_in ) {
+        /* Downsample */
+        if( SKP_MUL( Fs_Hz_out, 4 ) == SKP_MUL( Fs_Hz_in, 3 ) ) {               /* Fs_out : Fs_in = 3 : 4 */
+           S->FIR_Fracs = 3;
+           S->Coefs = SKP_Silk_Resampler_3_4_COEFS;
+           S->resampler_function = SKP_Silk_resampler_private_down_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 3 ) == SKP_MUL( Fs_Hz_in, 2 ) ) {        /* Fs_out : Fs_in = 2 : 3 */
+           S->FIR_Fracs = 2;
+           S->Coefs = SKP_Silk_Resampler_2_3_COEFS;
+           S->resampler_function = SKP_Silk_resampler_private_down_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 2 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 2 */
+           S->FIR_Fracs = 1;
+           S->Coefs = SKP_Silk_Resampler_1_2_COEFS;
+           S->resampler_function = SKP_Silk_resampler_private_down_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 8 ) == SKP_MUL( Fs_Hz_in, 3 ) ) {        /* Fs_out : Fs_in = 3 : 8 */
+           S->FIR_Fracs = 3;
+           S->Coefs = SKP_Silk_Resampler_3_8_COEFS;
+           S->resampler_function = SKP_Silk_resampler_private_down_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 3 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 3 */
+           S->FIR_Fracs = 1;
+           S->Coefs = SKP_Silk_Resampler_1_3_COEFS;
+           S->resampler_function = SKP_Silk_resampler_private_down_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 4 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 4 */
+           S->FIR_Fracs = 1;
+            down2 = 1;
+           S->Coefs = SKP_Silk_Resampler_1_2_COEFS;
+            S->resampler_function = SKP_Silk_resampler_private_down_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 6 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 6 */
+           S->FIR_Fracs = 1;
+            down2 = 1;
+           S->Coefs = SKP_Silk_Resampler_1_3_COEFS;
+            S->resampler_function = SKP_Silk_resampler_private_down_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 80 ) ) {     /* Fs_out : Fs_in = 80 : 441 */
+           S->Coefs = SKP_Silk_Resampler_80_441_ARMA4_COEFS;
+           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 120 ) ) {    /* Fs_out : Fs_in = 120 : 441 */
+           S->Coefs = SKP_Silk_Resampler_120_441_ARMA4_COEFS;
+           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 160 ) ) {    /* Fs_out : Fs_in = 160 : 441 */
+           S->Coefs = SKP_Silk_Resampler_160_441_ARMA4_COEFS;
+           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 240 ) ) {    /* Fs_out : Fs_in = 240 : 441 */
+           S->Coefs = SKP_Silk_Resampler_240_441_ARMA4_COEFS;
+           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;
+        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 320 ) ) {    /* Fs_out : Fs_in = 320 : 441 */
+           S->Coefs = SKP_Silk_Resampler_320_441_ARMA4_COEFS;
+           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;
+        } else {
+               /* Default resampler */
+               S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;
+            up2 = 1;
+            if( Fs_Hz_in > 24000 ) {
+                /* Low-quality all-pass upsampler */
+                S->up2_function = SKP_Silk_resampler_up2;
+            } else {
+                /* High-quality all-pass upsampler */
+                S->up2_function = SKP_Silk_resampler_private_up2_HQ;
+            }
+        }
+    } else {
+        /* Input and output sampling rates are equal: copy */
+        S->resampler_function = SKP_Silk_resampler_private_copy;
+    }
+
+    S->input2x = up2 | down2;
+
+    /* Ratio of input/output samples */
+    S->invRatio_Q16 = SKP_LSHIFT32( SKP_DIV32( SKP_LSHIFT32( Fs_Hz_in, 14 + up2 - down2 ), Fs_Hz_out ), 2 );
+    /* Make sure the ratio is rounded up */
+    while( SKP_SMULWW( S->invRatio_Q16, SKP_LSHIFT32( Fs_Hz_out, down2 ) ) < SKP_LSHIFT32( Fs_Hz_in, up2 ) ) {
+        S->invRatio_Q16++;
+    }
+
+       S->magic_number = 123456789;
+
+       return 0;
+}
+
+/* Clear the states of all resampling filters, without resetting sampling rate ratio */
+SKP_int SKP_Silk_resampler_clear( 
+       SKP_Silk_resampler_state_struct *S                  /* I/O: Resampler state                     */
+)
+{
+       /* Clear state */
+       SKP_memset( S->sDown2, 0, sizeof( S->sDown2 ) );
+       SKP_memset( S->sIIR,   0, sizeof( S->sIIR ) );
+       SKP_memset( S->sFIR,   0, sizeof( S->sFIR ) );
+#if RESAMPLER_SUPPORT_ABOVE_48KHZ
+       SKP_memset( S->sDownPre, 0, sizeof( S->sDownPre ) );
+       SKP_memset( S->sUpPost,  0, sizeof( S->sUpPost ) );
+#endif
+    return 0;
+}
+
+/* Resampler: convert from one sampling rate to another                                 */
+SKP_int SKP_Silk_resampler( 
+       SKP_Silk_resampler_state_struct *S,                 /* I/O: Resampler state                     */
+       SKP_int16                                                       out[],      /* O:       Output signal                           */
+       const SKP_int16                                         in[],       /* I:       Input signal                            */
+       SKP_int32                                                       inLen       /* I:       Number of input samples         */
+)
+{
+       /* Verify that state was initialized and has not been corrupted */
+    if( S->magic_number != 123456789 ) {
+        SKP_assert( 0 );
+        return -1;
+    }
+
+#if RESAMPLER_SUPPORT_ABOVE_48KHZ
+       if( S->nPreDownsamplers + S->nPostUpsamplers > 0 ) {
+               /* The input and/or output sampling rate is above 48000 Hz */
+        SKP_int32       nSamplesIn, nSamplesOut;
+               SKP_int16               in_buf[ 480 ], out_buf[ 480 ];
+
+        while( inLen > 0 ) {
+            /* Number of input and output samples to process */
+               nSamplesIn = SKP_min( inLen, S->batchSizePrePost );
+            nSamplesOut = SKP_SMULWB( S->ratio_Q16, nSamplesIn );
+
+            SKP_assert( SKP_RSHIFT32( nSamplesIn,  S->nPreDownsamplers ) <= 480 );
+            SKP_assert( SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers  ) <= 480 );
+
+               if( S->nPreDownsamplers > 0 ) {
+                S->down_pre_function( S->sDownPre, in_buf, in, nSamplesIn );
+                   if( S->nPostUpsamplers > 0 ) {
+                       S->resampler_function( S, out_buf, in_buf, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) );
+                    S->up_post_function( S->sUpPost, out, out_buf, SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers ) );
+                } else {
+                       S->resampler_function( S, out, in_buf, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) );
+                }
+            } else {
+                       S->resampler_function( S, out_buf, in, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) );
+                S->up_post_function( S->sUpPost, out, out_buf, SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers ) );
+            }
+
+               in += nSamplesIn;
+            out += nSamplesOut;
+               inLen -= nSamplesIn;
+        }
+       } else 
+#endif
+       {
+               /* Input and output sampling rate are at most 48000 Hz */
+               S->resampler_function( S, out, in, inLen );
+       }
+
+       return 0;
+}
index 619442c0dfae8c83ad9c2cd585376afcb8f82e20..08dd18fbb7f258881852c9b77944d8a4c6350780 100644 (file)
@@ -1,77 +1,77 @@
-/***********************************************************************\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_resampler_down2.c                                         *\r
- *                                                                      *\r
- * Downsample by a factor 2, mediocre quality                           *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- *                                                                      */\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_resampler_rom.h"\r
-\r
-/* Downsample by a factor 2, mediocre quality */\r
-void SKP_Silk_resampler_down2(\r
-    SKP_int32                           *S,         /* I/O: State vector [ 2 ]                  */\r
-    SKP_int16                           *out,       /* O:   Output signal [ len ]               */\r
-    const SKP_int16                     *in,        /* I:   Input signal [ floor(len/2) ]       */\r
-    SKP_int32                           inLen       /* I:   Number of input samples             */\r
-)\r
-{\r
-    SKP_int32 k, len2 = SKP_RSHIFT32( inLen, 1 );\r
-    SKP_int32 in32, out32, Y, X;\r
-\r
-    SKP_assert( SKP_Silk_resampler_down2_0 > 0 );\r
-    SKP_assert( SKP_Silk_resampler_down2_1 < 0 );\r
-\r
-    /* Internal variables and state are in Q10 format */\r
-    for( k = 0; k < len2; k++ ) {\r
-        /* Convert to Q10 */\r
-        in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 );\r
-\r
-        /* All-pass section for even input sample */\r
-        Y      = SKP_SUB32( in32, S[ 0 ] );\r
-        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_down2_1 );\r
-        out32  = SKP_ADD32( S[ 0 ], X );\r
-        S[ 0 ] = SKP_ADD32( in32, X );\r
-\r
-        /* Convert to Q10 */\r
-        in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 );\r
-\r
-        /* All-pass section for odd input sample, and add to output of previous section */\r
-        Y      = SKP_SUB32( in32, S[ 1 ] );\r
-        X      = SKP_SMULWB( Y, SKP_Silk_resampler_down2_0 );\r
-        out32  = SKP_ADD32( out32, S[ 1 ] );\r
-        out32  = SKP_ADD32( out32, X );\r
-        S[ 1 ] = SKP_ADD32( in32, X );\r
-\r
-        /* Add, convert back to int16 and store to output */\r
-        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 11 ) );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_resampler_down2.c                                         *
+ *                                                                      *
+ * Downsample by a factor 2, mediocre quality                           *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_rom.h"
+
+/* Downsample by a factor 2, mediocre quality */
+void SKP_Silk_resampler_down2(
+    SKP_int32                           *S,         /* I/O: State vector [ 2 ]                  */
+    SKP_int16                           *out,       /* O:   Output signal [ len ]               */
+    const SKP_int16                     *in,        /* I:   Input signal [ floor(len/2) ]       */
+    SKP_int32                           inLen       /* I:   Number of input samples             */
+)
+{
+    SKP_int32 k, len2 = SKP_RSHIFT32( inLen, 1 );
+    SKP_int32 in32, out32, Y, X;
+
+    SKP_assert( SKP_Silk_resampler_down2_0 > 0 );
+    SKP_assert( SKP_Silk_resampler_down2_1 < 0 );
+
+    /* Internal variables and state are in Q10 format */
+    for( k = 0; k < len2; k++ ) {
+        /* Convert to Q10 */
+        in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 );
+
+        /* All-pass section for even input sample */
+        Y      = SKP_SUB32( in32, S[ 0 ] );
+        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_down2_1 );
+        out32  = SKP_ADD32( S[ 0 ], X );
+        S[ 0 ] = SKP_ADD32( in32, X );
+
+        /* Convert to Q10 */
+        in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 );
+
+        /* All-pass section for odd input sample, and add to output of previous section */
+        Y      = SKP_SUB32( in32, S[ 1 ] );
+        X      = SKP_SMULWB( Y, SKP_Silk_resampler_down2_0 );
+        out32  = SKP_ADD32( out32, S[ 1 ] );
+        out32  = SKP_ADD32( out32, X );
+        S[ 1 ] = SKP_ADD32( in32, X );
+
+        /* Add, convert back to int16 and store to output */
+        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 11 ) );
+    }
+}
index 31089f909ac1858bce022673e3e24119fadc72fc..d233e14457e84de4b7d54d296e9e72243fec0649 100644 (file)
-/***********************************************************************\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_resampler_down2_3.c                                       *\r
- *                                                                      *\r
- * Downsample by a factor 2/3, 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
-#define ORDER_FIR                   4\r
-\r
-/* Downsample by a factor 2/3, low quality */\r
-void SKP_Silk_resampler_down2_3(\r
-    SKP_int32                           *S,         /* I/O: State vector [ 6 ]                  */\r
-    SKP_int16                           *out,       /* O:   Output signal [ floor(2*inLen/3) ]  */\r
-    const SKP_int16                     *in,        /* I:   Input signal [ inLen ]              */\r
-    SKP_int32                           inLen       /* I:   Number of input samples             */\r
-)\r
-{\r
-       SKP_int32 nSamplesIn, counter, res_Q6;\r
-       SKP_int32 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR ];\r
-       SKP_int32 *buf_ptr;\r
-\r
-       /* Copy buffered samples to start of buffer */  \r
-       SKP_memcpy( buf, S, ORDER_FIR * sizeof( SKP_int32 ) );\r
-\r
-       /* Iterate over blocks of frameSizeIn input samples */\r
-       while( 1 ) {\r
-               nSamplesIn = SKP_min( inLen, RESAMPLER_MAX_BATCH_SIZE_IN );\r
-\r
-           /* Second-order AR filter (output in Q8) */\r
-           SKP_Silk_resampler_private_AR2( &S[ ORDER_FIR ], &buf[ ORDER_FIR ], in, \r
-            SKP_Silk_Resampler_2_3_COEFS_LQ, nSamplesIn );\r
-\r
-               /* Interpolate filtered signal */\r
-        buf_ptr = buf;\r
-        counter = nSamplesIn;\r
-        while( counter > 2 ) {\r
-            /* Inner product */\r
-                   res_Q6 = SKP_SMULWB(         buf_ptr[ 0 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 ] );\r
-                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 1 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 3 ] );\r
-                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 5 ] );\r
-                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 4 ] );\r
-\r
-            /* Scale down, saturate and store in output array */\r
-            *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );\r
-\r
-                   res_Q6 = SKP_SMULWB(         buf_ptr[ 1 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 4 ] );\r
-                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 5 ] );\r
-                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 3 ] );\r
-                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 4 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 ] );\r
-\r
-            /* Scale down, saturate and store in output array */\r
-            *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );\r
-\r
-            buf_ptr += 3;\r
-            counter -= 3;\r
-        }\r
-\r
-               in += nSamplesIn;\r
-               inLen -= nSamplesIn;\r
-\r
-               if( inLen > 0 ) {\r
-                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */\r
-                       SKP_memcpy( buf, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );\r
-               } else {\r
-                       break;\r
-               }\r
-       }\r
-\r
-       /* Copy last part of filtered signal to the state for the next call */\r
-       SKP_memcpy( S, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_resampler_down2_3.c                                       *
+ *                                                                      *
+ * Downsample by a factor 2/3, low quality                              *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_private.h"
+
+#define ORDER_FIR                   4
+
+/* Downsample by a factor 2/3, low quality */
+void SKP_Silk_resampler_down2_3(
+    SKP_int32                           *S,         /* I/O: State vector [ 6 ]                  */
+    SKP_int16                           *out,       /* O:   Output signal [ floor(2*inLen/3) ]  */
+    const SKP_int16                     *in,        /* I:   Input signal [ inLen ]              */
+    SKP_int32                           inLen       /* I:   Number of input samples             */
+)
+{
+       SKP_int32 nSamplesIn, counter, res_Q6;
+       SKP_int32 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR ];
+       SKP_int32 *buf_ptr;
+
+       /* Copy buffered samples to start of buffer */  
+       SKP_memcpy( buf, S, ORDER_FIR * sizeof( SKP_int32 ) );
+
+       /* Iterate over blocks of frameSizeIn input samples */
+       while( 1 ) {
+               nSamplesIn = SKP_min( inLen, RESAMPLER_MAX_BATCH_SIZE_IN );
+
+           /* Second-order AR filter (output in Q8) */
+           SKP_Silk_resampler_private_AR2( &S[ ORDER_FIR ], &buf[ ORDER_FIR ], in, 
+            SKP_Silk_Resampler_2_3_COEFS_LQ, nSamplesIn );
+
+               /* Interpolate filtered signal */
+        buf_ptr = buf;
+        counter = nSamplesIn;
+        while( counter > 2 ) {
+            /* Inner product */
+                   res_Q6 = SKP_SMULWB(         buf_ptr[ 0 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 ] );
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 1 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 3 ] );
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 5 ] );
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 4 ] );
+
+            /* Scale down, saturate and store in output array */
+            *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );
+
+                   res_Q6 = SKP_SMULWB(         buf_ptr[ 1 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 4 ] );
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 5 ] );
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 3 ] );
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 4 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 ] );
+
+            /* Scale down, saturate and store in output array */
+            *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );
+
+            buf_ptr += 3;
+            counter -= 3;
+        }
+
+               in += nSamplesIn;
+               inLen -= nSamplesIn;
+
+               if( inLen > 0 ) {
+                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */
+                       SKP_memcpy( buf, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );
+               } else {
+                       break;
+               }
+       }
+
+       /* Copy last part of filtered signal to the state for the next call */
+       SKP_memcpy( S, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );
+}
index 70c86f66987d520195052d178627398e190f0ac2..93ba5f6fccf46ab96ad57a8a772799d5eb08feb9 100644 (file)
@@ -1,93 +1,93 @@
-/***********************************************************************\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_resampler_down3.c                                         *\r
- *                                                                      *\r
- * Downsample by a factor 3, 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
-#define ORDER_FIR                   6\r
-\r
-/* Downsample by a factor 3, low quality */\r
-void SKP_Silk_resampler_down3(\r
-    SKP_int32                           *S,         /* I/O: State vector [ 8 ]                  */\r
-    SKP_int16                           *out,       /* O:   Output signal [ floor(inLen/3) ]    */\r
-    const SKP_int16                     *in,        /* I:   Input signal [ inLen ]              */\r
-    SKP_int32                           inLen       /* I:   Number of input samples             */\r
-)\r
-{\r
-       SKP_int32 nSamplesIn, counter, res_Q6;\r
-       SKP_int32 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR ];\r
-       SKP_int32 *buf_ptr;\r
-\r
-       /* Copy buffered samples to start of buffer */  \r
-       SKP_memcpy( buf, S, ORDER_FIR * sizeof( SKP_int32 ) );\r
-\r
-       /* Iterate over blocks of frameSizeIn input samples */\r
-       while( 1 ) {\r
-               nSamplesIn = SKP_min( inLen, RESAMPLER_MAX_BATCH_SIZE_IN );\r
-\r
-           /* Second-order AR filter (output in Q8) */\r
-           SKP_Silk_resampler_private_AR2( &S[ ORDER_FIR ], &buf[ ORDER_FIR ], in, \r
-            SKP_Silk_Resampler_1_3_COEFS_LQ, nSamplesIn );\r
-\r
-               /* Interpolate filtered signal */\r
-        buf_ptr = buf;\r
-        counter = nSamplesIn;\r
-        while( counter > 2 ) {\r
-            /* Inner product */\r
-            res_Q6 = SKP_SMULWB(         SKP_ADD32( buf_ptr[ 0 ], buf_ptr[ 5 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 ] );\r
-            res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 1 ], buf_ptr[ 4 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 3 ] );\r
-            res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 2 ], buf_ptr[ 3 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 4 ] );\r
-\r
-            /* Scale down, saturate and store in output array */\r
-            *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );\r
-\r
-            buf_ptr += 3;\r
-            counter -= 3;\r
-        }\r
-\r
-               in += nSamplesIn;\r
-               inLen -= nSamplesIn;\r
-\r
-               if( inLen > 0 ) {\r
-                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */\r
-                       SKP_memcpy( buf, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );\r
-               } else {\r
-                       break;\r
-               }\r
-       }\r
-\r
-       /* Copy last part of filtered signal to the state for the next call */\r
-       SKP_memcpy( S, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_resampler_down3.c                                         *
+ *                                                                      *
+ * Downsample by a factor 3, low quality                                *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_private.h"
+
+#define ORDER_FIR                   6
+
+/* Downsample by a factor 3, low quality */
+void SKP_Silk_resampler_down3(
+    SKP_int32                           *S,         /* I/O: State vector [ 8 ]                  */
+    SKP_int16                           *out,       /* O:   Output signal [ floor(inLen/3) ]    */
+    const SKP_int16                     *in,        /* I:   Input signal [ inLen ]              */
+    SKP_int32                           inLen       /* I:   Number of input samples             */
+)
+{
+       SKP_int32 nSamplesIn, counter, res_Q6;
+       SKP_int32 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR ];
+       SKP_int32 *buf_ptr;
+
+       /* Copy buffered samples to start of buffer */  
+       SKP_memcpy( buf, S, ORDER_FIR * sizeof( SKP_int32 ) );
+
+       /* Iterate over blocks of frameSizeIn input samples */
+       while( 1 ) {
+               nSamplesIn = SKP_min( inLen, RESAMPLER_MAX_BATCH_SIZE_IN );
+
+           /* Second-order AR filter (output in Q8) */
+           SKP_Silk_resampler_private_AR2( &S[ ORDER_FIR ], &buf[ ORDER_FIR ], in, 
+            SKP_Silk_Resampler_1_3_COEFS_LQ, nSamplesIn );
+
+               /* Interpolate filtered signal */
+        buf_ptr = buf;
+        counter = nSamplesIn;
+        while( counter > 2 ) {
+            /* Inner product */
+            res_Q6 = SKP_SMULWB(         SKP_ADD32( buf_ptr[ 0 ], buf_ptr[ 5 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 ] );
+            res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 1 ], buf_ptr[ 4 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 3 ] );
+            res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 2 ], buf_ptr[ 3 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 4 ] );
+
+            /* Scale down, saturate and store in output array */
+            *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );
+
+            buf_ptr += 3;
+            counter -= 3;
+        }
+
+               in += nSamplesIn;
+               inLen -= nSamplesIn;
+
+               if( inLen > 0 ) {
+                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */
+                       SKP_memcpy( buf, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );
+               } else {
+                       break;
+               }
+       }
+
+       /* Copy last part of filtered signal to the state for the next call */
+       SKP_memcpy( S, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );
+}
index 0402b484aa2c3c1f1df91fd316fb03933d4771d5..2a5d7d779f5659da10a56fa89d44e2ce30622d02 100644 (file)
-/***********************************************************************\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
- * File Name:  SKP_Silk_resampler_structs.h                                                    *\r
- *                                                                                                                                             *\r
- * Description: Structs for IIR/FIR resamplers                                                 *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- * All rights reserved.                                                                                                        *\r
- *                                                                                                                                             *\r
- *                                                                      */\r
-\r
-#ifndef SKP_Silk_RESAMPLER_H\r
-#define SKP_Silk_RESAMPLER_H\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_resampler_structs.h"\r
-#include "SKP_Silk_resampler_rom.h"\r
-\r
-/* Number of input samples to process in the inner loop */\r
-#define RESAMPLER_MAX_BATCH_SIZE_IN             480\r
-\r
-/* Description: Hybrid IIR/FIR polyphase implementation of resampling  */\r
-void SKP_Silk_resampler_private_IIR_FIR(\r
-       void                            *SS,                /* I/O: Resampler state                                             */\r
-       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
-       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
-       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
-);\r
-\r
-/* Description: Hybrid IIR/FIR polyphase implementation of resampling  */\r
-void SKP_Silk_resampler_private_down_FIR(\r
-       void                            *SS,                /* I/O: Resampler state                                             */\r
-       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
-       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
-       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
-);\r
-\r
-/* Copy */\r
-void SKP_Silk_resampler_private_copy(\r
-       void                            *SS,                /* I/O: Resampler state (unused)                            */\r
-       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
-       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
-       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
-);\r
-\r
-/* Upsample by a factor 2, high quality */\r
-void SKP_Silk_resampler_private_up2_HQ_wrapper(\r
-       void                            *SS,                /* I/O: Resampler state (unused)                            */\r
-    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */\r
-    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
-    SKP_int32                       len             /* I:   Number of input samples                 */\r
-);\r
-\r
-/* Upsample by a factor 2, high quality */\r
-void SKP_Silk_resampler_private_up2_HQ(\r
-       SKP_int32                           *S,                     /* I/O: Resampler state [ 6 ]                                       */\r
-    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */\r
-    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
-    SKP_int32                       len             /* I:   Number of input samples                 */\r
-);\r
-\r
-/* Upsample 4x, low quality */\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
-    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
-    SKP_int32                       len             /* I:   Number of input samples                 */\r
-);\r
-\r
-/* Downsample 4x, low quality */\r
-void SKP_Silk_resampler_private_down4(\r
-    SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */\r
-    SKP_int16                       *out,           /* O:   Output signal [ floor(len/2) ]          */\r
-    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
-    SKP_int32                       inLen           /* I:   Number of input samples                 */\r
-);\r
-\r
-/* Second order AR filter */\r
-void SKP_Silk_resampler_private_AR2(\r
-       SKP_int32                                           S[],                    /* I/O: State vector [ 2 ]                              */\r
-       SKP_int32                                           out_Q8[],           /* O:   Output signal                                       */\r
-       const SKP_int16                             in[],                       /* I:   Input signal                                        */\r
-       const SKP_int16                             A_Q14[],            /* I:   AR coefficients, Q14                    */\r
-       SKP_int32                                       len                             /* I:   Signal length                                           */\r
-);\r
-\r
-/* Fourth order ARMA filter */\r
-void SKP_Silk_resampler_private_ARMA4(\r
-       SKP_int32                                           S[],                    /* I/O: State vector [ 4 ]                              */\r
-       SKP_int16                                           out[],                  /* O:       Output signal                                       */\r
-       const SKP_int16                             in[],                       /* I:   Input signal                                        */\r
-       const SKP_int16                             Coef[],                 /* I:       ARMA coefficients [ 7 ]                 */\r
-       SKP_int32                                       len                             /* I:   Signal length                                           */\r
-);\r
-\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-#endif // SKP_Silk_RESAMPLER_H\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                                                                                             *
+ * File Name:  SKP_Silk_resampler_structs.h                                                    *
+ *                                                                                                                                             *
+ * Description: Structs for IIR/FIR resamplers                                                 *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ * All rights reserved.                                                                                                        *
+ *                                                                                                                                             *
+ *                                                                      */
+
+#ifndef SKP_Silk_RESAMPLER_H
+#define SKP_Silk_RESAMPLER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_structs.h"
+#include "SKP_Silk_resampler_rom.h"
+
+/* Number of input samples to process in the inner loop */
+#define RESAMPLER_MAX_BATCH_SIZE_IN             480
+
+/* Description: Hybrid IIR/FIR polyphase implementation of resampling  */
+void SKP_Silk_resampler_private_IIR_FIR(
+       void                            *SS,                /* I/O: Resampler state                                             */
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */
+);
+
+/* Description: Hybrid IIR/FIR polyphase implementation of resampling  */
+void SKP_Silk_resampler_private_down_FIR(
+       void                            *SS,                /* I/O: Resampler state                                             */
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */
+);
+
+/* Copy */
+void SKP_Silk_resampler_private_copy(
+       void                            *SS,                /* I/O: Resampler state (unused)                            */
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */
+);
+
+/* Upsample by a factor 2, high quality */
+void SKP_Silk_resampler_private_up2_HQ_wrapper(
+       void                            *SS,                /* I/O: Resampler state (unused)                            */
+    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */
+    SKP_int32                       len             /* I:   Number of input samples                 */
+);
+
+/* Upsample by a factor 2, high quality */
+void SKP_Silk_resampler_private_up2_HQ(
+       SKP_int32                           *S,                     /* I/O: Resampler state [ 6 ]                                       */
+    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */
+    SKP_int32                       len             /* I:   Number of input samples                 */
+);
+
+/* Upsample 4x, low quality */
+void SKP_Silk_resampler_private_up4(
+    SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */
+    SKP_int16                       *out,           /* O:   Output signal [ 4 * len ]               */
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */
+    SKP_int32                       len             /* I:   Number of input samples                 */
+);
+
+/* Downsample 4x, low quality */
+void SKP_Silk_resampler_private_down4(
+    SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */
+    SKP_int16                       *out,           /* O:   Output signal [ floor(len/2) ]          */
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */
+    SKP_int32                       inLen           /* I:   Number of input samples                 */
+);
+
+/* Second order AR filter */
+void SKP_Silk_resampler_private_AR2(
+       SKP_int32                                           S[],                    /* I/O: State vector [ 2 ]                              */
+       SKP_int32                                           out_Q8[],           /* O:   Output signal                                       */
+       const SKP_int16                             in[],                       /* I:   Input signal                                        */
+       const SKP_int16                             A_Q14[],            /* I:   AR coefficients, Q14                    */
+       SKP_int32                                       len                             /* I:   Signal length                                           */
+);
+
+/* Fourth order ARMA filter */
+void SKP_Silk_resampler_private_ARMA4(
+       SKP_int32                                           S[],                    /* I/O: State vector [ 4 ]                              */
+       SKP_int16                                           out[],                  /* O:       Output signal                                       */
+       const SKP_int16                             in[],                       /* I:   Input signal                                        */
+       const SKP_int16                             Coef[],                 /* I:       ARMA coefficients [ 7 ]                 */
+       SKP_int32                                       len                             /* I:   Signal length                                           */
+);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif // SKP_Silk_RESAMPLER_H
+
index 69f50431723f1e022659119857dcb6816765a2a0..8aaef7f4aed7568e24994a9d709ab2ece5250ee5 100644 (file)
@@ -1,58 +1,58 @@
-/***********************************************************************\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_resampler_private_AR2. c                                  *\r
- *                                                                                                                                             *\r
- * Second order AR filter with single delay elements                   *\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
-/* Second order AR filter with single delay elements */\r
-void SKP_Silk_resampler_private_AR2(\r
-       SKP_int32                                           S[],                    /* I/O: State vector [ 2 ]                              */\r
-       SKP_int32                                           out_Q8[],           /* O:   Output signal                                       */\r
-       const SKP_int16                             in[],                       /* I:   Input signal                                        */\r
-       const SKP_int16                             A_Q14[],            /* I:   AR coefficients, Q14                    */\r
-       SKP_int32                                       len                             /* I:   Signal length                                           */\r
-)\r
-{\r
-       SKP_int32       k;\r
-       SKP_int32       out32;\r
-\r
-       for( k = 0; k < len; k++ ) {\r
-               out32       = SKP_ADD_LSHIFT32( S[ 0 ], (SKP_int32)in[ k ], 8 );\r
-               out_Q8[ k ] = out32;\r
-               out32       = SKP_LSHIFT( out32, 2 );\r
-               S[ 0 ]      = SKP_SMLAWB( S[ 1 ], out32, A_Q14[ 0 ] );\r
-               S[ 1 ]      = SKP_SMULWB( out32, A_Q14[ 1 ] );\r
-       }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                                                                                             *
+ * SKP_Silk_resampler_private_AR2. c                                  *
+ *                                                                                                                                             *
+ * Second order AR filter with single delay elements                   *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_private.h"
+
+/* Second order AR filter with single delay elements */
+void SKP_Silk_resampler_private_AR2(
+       SKP_int32                                           S[],                    /* I/O: State vector [ 2 ]                              */
+       SKP_int32                                           out_Q8[],           /* O:   Output signal                                       */
+       const SKP_int16                             in[],                       /* I:   Input signal                                        */
+       const SKP_int16                             A_Q14[],            /* I:   AR coefficients, Q14                    */
+       SKP_int32                                       len                             /* I:   Signal length                                           */
+)
+{
+       SKP_int32       k;
+       SKP_int32       out32;
+
+       for( k = 0; k < len; k++ ) {
+               out32       = SKP_ADD_LSHIFT32( S[ 0 ], (SKP_int32)in[ k ], 8 );
+               out_Q8[ k ] = out32;
+               out32       = SKP_LSHIFT( out32, 2 );
+               S[ 0 ]      = SKP_SMLAWB( S[ 1 ], out32, A_Q14[ 0 ] );
+               S[ 1 ]      = SKP_SMULWB( out32, A_Q14[ 1 ] );
+       }
+}
index d0ca3a69fd2100cb6c0d517921e177def6b0642b..5a96b7a3ed679aabc6700a410e18dbdadc6070ed 100644 (file)
@@ -1,77 +1,77 @@
-/***********************************************************************\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_resampler_private_ARMA4.c                                 *\r
- *                                                                                                                                             *\r
- * Fourth order ARMA filter, applies 64x gain                           *\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
-/* Fourth order ARMA filter                                             */\r
-/* Internally operates as two biquad filters in sequence.               */\r
-\r
-/* Coeffients are stored in a packed format:                                                        */\r
-/*    { B1_Q14[1], B2_Q14[1], -A1_Q14[1], -A1_Q14[2], -A2_Q14[1], -A2_Q14[2], gain_Q16 }            */\r
-/* where it is assumed that B*_Q14[0], B*_Q14[2], A*_Q14[0] are all 16384                           */\r
-void SKP_Silk_resampler_private_ARMA4(\r
-       SKP_int32                                           S[],                    /* I/O: State vector [ 4 ]                              */\r
-       SKP_int16                                           out[],                  /* O:       Output signal                                       */\r
-       const SKP_int16                             in[],                       /* I:   Input signal                                        */\r
-       const SKP_int16                             Coef[],                 /* I:       ARMA coefficients [ 7 ]                 */\r
-       SKP_int32                                       len                             /* I:   Signal length                                           */\r
-)\r
-{\r
-       SKP_int32 k;\r
-       SKP_int32 in_Q8, out1_Q8, out2_Q8, X;\r
-\r
-       for( k = 0; k < len; k++ ) {\r
-        in_Q8  = SKP_LSHIFT32( (SKP_int32)in[ k ], 8 );\r
-\r
-        /* Outputs of first and second biquad */\r
-        out1_Q8 = SKP_ADD_LSHIFT32( in_Q8,   S[ 0 ], 2 );\r
-        out2_Q8 = SKP_ADD_LSHIFT32( out1_Q8, S[ 2 ], 2 );\r
-\r
-        /* Update states, which are stored in Q6. Coefficients are in Q14 here */\r
-        X      = SKP_SMLAWB( S[ 1 ], in_Q8,   Coef[ 0 ] );\r
-        S[ 0 ] = SKP_SMLAWB( X,      out1_Q8, Coef[ 2 ] );\r
-\r
-        X      = SKP_SMLAWB( S[ 3 ], out1_Q8, Coef[ 1 ] );\r
-        S[ 2 ] = SKP_SMLAWB( X,      out2_Q8, Coef[ 4 ] );\r
-\r
-        S[ 1 ] = SKP_SMLAWB( SKP_RSHIFT32( in_Q8,   2 ), out1_Q8, Coef[ 3 ] );\r
-        S[ 3 ] = SKP_SMLAWB( SKP_RSHIFT32( out1_Q8, 2 ), out2_Q8, Coef[ 5 ] );\r
-\r
-        /* Apply gain and store to output. The coefficient is in Q16 */\r
-        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( SKP_SMLAWB( 128, out2_Q8, Coef[ 6 ] ), 8 ) );\r
-       }\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                                                                                             *
+ * SKP_Silk_resampler_private_ARMA4.c                                 *
+ *                                                                                                                                             *
+ * Fourth order ARMA filter, applies 64x gain                           *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_private.h"
+
+/* Fourth order ARMA filter                                             */
+/* Internally operates as two biquad filters in sequence.               */
+
+/* Coeffients are stored in a packed format:                                                        */
+/*    { B1_Q14[1], B2_Q14[1], -A1_Q14[1], -A1_Q14[2], -A2_Q14[1], -A2_Q14[2], gain_Q16 }            */
+/* where it is assumed that B*_Q14[0], B*_Q14[2], A*_Q14[0] are all 16384                           */
+void SKP_Silk_resampler_private_ARMA4(
+       SKP_int32                                           S[],                    /* I/O: State vector [ 4 ]                              */
+       SKP_int16                                           out[],                  /* O:       Output signal                                       */
+       const SKP_int16                             in[],                       /* I:   Input signal                                        */
+       const SKP_int16                             Coef[],                 /* I:       ARMA coefficients [ 7 ]                 */
+       SKP_int32                                       len                             /* I:   Signal length                                           */
+)
+{
+       SKP_int32 k;
+       SKP_int32 in_Q8, out1_Q8, out2_Q8, X;
+
+       for( k = 0; k < len; k++ ) {
+        in_Q8  = SKP_LSHIFT32( (SKP_int32)in[ k ], 8 );
+
+        /* Outputs of first and second biquad */
+        out1_Q8 = SKP_ADD_LSHIFT32( in_Q8,   S[ 0 ], 2 );
+        out2_Q8 = SKP_ADD_LSHIFT32( out1_Q8, S[ 2 ], 2 );
+
+        /* Update states, which are stored in Q6. Coefficients are in Q14 here */
+        X      = SKP_SMLAWB( S[ 1 ], in_Q8,   Coef[ 0 ] );
+        S[ 0 ] = SKP_SMLAWB( X,      out1_Q8, Coef[ 2 ] );
+
+        X      = SKP_SMLAWB( S[ 3 ], out1_Q8, Coef[ 1 ] );
+        S[ 2 ] = SKP_SMLAWB( X,      out2_Q8, Coef[ 4 ] );
+
+        S[ 1 ] = SKP_SMLAWB( SKP_RSHIFT32( in_Q8,   2 ), out1_Q8, Coef[ 3 ] );
+        S[ 3 ] = SKP_SMLAWB( SKP_RSHIFT32( out1_Q8, 2 ), out2_Q8, Coef[ 5 ] );
+
+        /* Apply gain and store to output. The coefficient is in Q16 */
+        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( SKP_SMLAWB( 128, out2_Q8, Coef[ 6 ] ), 8 ) );
+       }
+}
+
index df9a031dc8e850e68e07175ebe041af3231b30f4..85cb08358cbbb5c19fa66d7c864e5e36db0815e0 100644 (file)
-/***********************************************************************\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
- * File Name:  SKP_Silk_resampler_private_IIR_FIR.c                        *\r
- *                                                                                                                                             *\r
- * Description: Hybrid IIR/FIR polyphase implementation of resampling  *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- * All rights reserved.                                                                                                        *\r
- *                                                                      */\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_resampler_private.h"\r
-SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_IIR_FIR_INTERPOL( \r
-                       SKP_int16 * out, SKP_int16 * buf, SKP_int32 max_index_Q16 , SKP_int32 index_increment_Q16 ){\r
-       SKP_int32 index_Q16, res_Q15;\r
-       SKP_int16 *buf_ptr;\r
-       SKP_int32 table_index;\r
-       /* Interpolate upsampled signal and store in output array */\r
-       for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {\r
-        table_index = SKP_SMULWB( index_Q16 & 0xFFFF, 144 );\r
-        buf_ptr = &buf[ index_Q16 >> 16 ];\r
-            \r
-        res_Q15 = SKP_SMULBB(          buf_ptr[ 0 ], SKP_Silk_resampler_frac_FIR_144[       table_index ][ 0 ] );\r
-        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 1 ], SKP_Silk_resampler_frac_FIR_144[       table_index ][ 1 ] );\r
-        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 2 ], SKP_Silk_resampler_frac_FIR_144[       table_index ][ 2 ] );\r
-        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 3 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 2 ] );\r
-        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 4 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 1 ] );\r
-        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 5 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 0 ] );          \r
-               *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q15, 15 ) );\r
-       }\r
-       return out;     \r
-}\r
-/* Upsample using a combination of allpass-based 2x upsampling and FIR interpolation */\r
-void SKP_Silk_resampler_private_IIR_FIR(\r
-       void                            *SS,                /* I/O: Resampler state                                             */\r
-       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
-       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
-       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
-)\r
-{\r
-    SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS;\r
-       SKP_int32 nSamplesIn;\r
-       SKP_int32 max_index_Q16, index_increment_Q16;\r
-       SKP_int16 buf[ 2 * RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_ORDER_FIR_144 ];\r
-    \r
-\r
-       /* Copy buffered samples to start of buffer */  \r
-       SKP_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) );\r
-\r
-       /* Iterate over blocks of frameSizeIn input samples */\r
-    index_increment_Q16 = S->invRatio_Q16;\r
-       while( 1 ) {\r
-               nSamplesIn = SKP_min( inLen, S->batchSize );\r
-\r
-        if( S->input2x == 1 ) {\r
-                   /* Upsample 2x */\r
-            S->up2_function( S->sIIR, &buf[ RESAMPLER_ORDER_FIR_144 ], in, nSamplesIn );\r
-        } else {\r
-                   /* Fourth-order ARMA filter */\r
-            SKP_Silk_resampler_private_ARMA4( S->sIIR, &buf[ RESAMPLER_ORDER_FIR_144 ], in, S->Coefs, nSamplesIn );\r
-        }\r
-\r
-        max_index_Q16 = SKP_LSHIFT32( nSamplesIn, 16 + S->input2x );         /* +1 if 2x upsampling */\r
-               out = SKP_Silk_resampler_private_IIR_FIR_INTERPOL(out, buf, max_index_Q16, index_increment_Q16);    \r
-               in += nSamplesIn;\r
-               inLen -= nSamplesIn;\r
-\r
-               if( inLen > 0 ) {\r
-                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */\r
-                       SKP_memcpy( buf, &buf[ nSamplesIn << S->input2x ], RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) );\r
-               } else {\r
-                       break;\r
-               }\r
-       }\r
-\r
-       /* Copy last part of filtered signal to the state for the next call */\r
-       SKP_memcpy( S->sFIR, &buf[nSamplesIn << S->input2x ], RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) );\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                                                                                             *
+ * File Name:  SKP_Silk_resampler_private_IIR_FIR.c                        *
+ *                                                                                                                                             *
+ * Description: Hybrid IIR/FIR polyphase implementation of resampling  *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ * All rights reserved.                                                                                                        *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_private.h"
+SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_IIR_FIR_INTERPOL( 
+                       SKP_int16 * out, SKP_int16 * buf, SKP_int32 max_index_Q16 , SKP_int32 index_increment_Q16 ){
+       SKP_int32 index_Q16, res_Q15;
+       SKP_int16 *buf_ptr;
+       SKP_int32 table_index;
+       /* Interpolate upsampled signal and store in output array */
+       for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {
+        table_index = SKP_SMULWB( index_Q16 & 0xFFFF, 144 );
+        buf_ptr = &buf[ index_Q16 >> 16 ];
+            
+        res_Q15 = SKP_SMULBB(          buf_ptr[ 0 ], SKP_Silk_resampler_frac_FIR_144[       table_index ][ 0 ] );
+        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 1 ], SKP_Silk_resampler_frac_FIR_144[       table_index ][ 1 ] );
+        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 2 ], SKP_Silk_resampler_frac_FIR_144[       table_index ][ 2 ] );
+        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 3 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 2 ] );
+        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 4 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 1 ] );
+        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 5 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 0 ] );          
+               *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q15, 15 ) );
+       }
+       return out;     
+}
+/* Upsample using a combination of allpass-based 2x upsampling and FIR interpolation */
+void SKP_Silk_resampler_private_IIR_FIR(
+       void                            *SS,                /* I/O: Resampler state                                             */
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */
+)
+{
+    SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS;
+       SKP_int32 nSamplesIn;
+       SKP_int32 max_index_Q16, index_increment_Q16;
+       SKP_int16 buf[ 2 * RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_ORDER_FIR_144 ];
+    
+
+       /* Copy buffered samples to start of buffer */  
+       SKP_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) );
+
+       /* Iterate over blocks of frameSizeIn input samples */
+    index_increment_Q16 = S->invRatio_Q16;
+       while( 1 ) {
+               nSamplesIn = SKP_min( inLen, S->batchSize );
+
+        if( S->input2x == 1 ) {
+                   /* Upsample 2x */
+            S->up2_function( S->sIIR, &buf[ RESAMPLER_ORDER_FIR_144 ], in, nSamplesIn );
+        } else {
+                   /* Fourth-order ARMA filter */
+            SKP_Silk_resampler_private_ARMA4( S->sIIR, &buf[ RESAMPLER_ORDER_FIR_144 ], in, S->Coefs, nSamplesIn );
+        }
+
+        max_index_Q16 = SKP_LSHIFT32( nSamplesIn, 16 + S->input2x );         /* +1 if 2x upsampling */
+               out = SKP_Silk_resampler_private_IIR_FIR_INTERPOL(out, buf, max_index_Q16, index_increment_Q16);    
+               in += nSamplesIn;
+               inLen -= nSamplesIn;
+
+               if( inLen > 0 ) {
+                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */
+                       SKP_memcpy( buf, &buf[ nSamplesIn << S->input2x ], RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) );
+               } else {
+                       break;
+               }
+       }
+
+       /* Copy last part of filtered signal to the state for the next call */
+       SKP_memcpy( S->sFIR, &buf[nSamplesIn << S->input2x ], RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) );
+}
+
index 7c5b03197a5bb70060469a0a60abdfab2e4587e5..071e210a7915e6932881270013ff1e1ce9fc5209 100644 (file)
@@ -1,49 +1,49 @@
-/***********************************************************************\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
- * File Name:  SKP_Silk_resampler_private_copy.c                     *\r
- *                                                                                                                                             *\r
- * Description: Copy.                                                   *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- * All rights reserved.                                                                                                        *\r
- *                                                                      */\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_resampler_private.h"\r
-\r
-/* Copy */\r
-void SKP_Silk_resampler_private_copy(\r
-       void                            *SS,                /* I/O: Resampler state (unused)                            */\r
-       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
-       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
-       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
-)\r
-{\r
-    SKP_memcpy( out, in, inLen * sizeof( SKP_int16 ) );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                                                                                             *
+ * File Name:  SKP_Silk_resampler_private_copy.c                     *
+ *                                                                                                                                             *
+ * Description: Copy.                                                   *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ * All rights reserved.                                                                                                        *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_private.h"
+
+/* Copy */
+void SKP_Silk_resampler_private_copy(
+       void                            *SS,                /* I/O: Resampler state (unused)                            */
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */
+)
+{
+    SKP_memcpy( out, in, inLen * sizeof( SKP_int16 ) );
+}
index 0d327c728f7a7ac0f58206916dd935752da79cfd..54e56f53d4be7ac0c15fd7d866ed42d2cf8ffb87 100644 (file)
@@ -1,77 +1,77 @@
-/***********************************************************************\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_resampler_private_down4.c                                 *\r
- *                                                                      *\r
- * Downsample by a factor 4                                             *\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
-/* Downsample by a factor 4. Note: very low quality, only use with input sampling rates above 96 kHz. */\r
-void SKP_Silk_resampler_private_down4(\r
-    SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */\r
-    SKP_int16                       *out,           /* O:   Output signal [ floor(len/2) ]          */\r
-    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
-    SKP_int32                       inLen           /* I:   Number of input samples                 */\r
-)\r
-{\r
-    SKP_int32 k, len4 = SKP_RSHIFT32( inLen, 2 );\r
-    SKP_int32 in32, out32, Y, X;\r
-\r
-    SKP_assert( SKP_Silk_resampler_down2_0 > 0 );\r
-    SKP_assert( SKP_Silk_resampler_down2_1 < 0 );\r
-\r
-    /* Internal variables and state are in Q10 format */\r
-    for( k = 0; k < len4; k++ ) {\r
-        /* Add two input samples and convert to Q10 */\r
-        in32 = SKP_LSHIFT( SKP_ADD32( (SKP_int32)in[ 4 * k ], (SKP_int32)in[ 4 * k + 1 ] ), 9 );\r
-\r
-        /* All-pass section for even input sample */\r
-        Y      = SKP_SUB32( in32, S[ 0 ] );\r
-        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_down2_1 );\r
-        out32  = SKP_ADD32( S[ 0 ], X );\r
-        S[ 0 ] = SKP_ADD32( in32, X );\r
-\r
-        /* Add two input samples and convert to Q10 */\r
-        in32 = SKP_LSHIFT( SKP_ADD32( (SKP_int32)in[ 4 * k + 2 ], (SKP_int32)in[ 4 * k + 3 ] ), 9 );\r
-\r
-        /* All-pass section for odd input sample */\r
-        Y      = SKP_SUB32( in32, S[ 1 ] );\r
-        X      = SKP_SMULWB( Y, SKP_Silk_resampler_down2_0 );\r
-        out32  = SKP_ADD32( out32, S[ 1 ] );\r
-        out32  = SKP_ADD32( out32, X );\r
-        S[ 1 ] = SKP_ADD32( in32, X );\r
-\r
-        /* Add, convert back to int16 and store to output */\r
-        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 11 ) );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_resampler_private_down4.c                                 *
+ *                                                                      *
+ * Downsample by a factor 4                                             *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_private.h"
+
+/* Downsample by a factor 4. Note: very low quality, only use with input sampling rates above 96 kHz. */
+void SKP_Silk_resampler_private_down4(
+    SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */
+    SKP_int16                       *out,           /* O:   Output signal [ floor(len/2) ]          */
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */
+    SKP_int32                       inLen           /* I:   Number of input samples                 */
+)
+{
+    SKP_int32 k, len4 = SKP_RSHIFT32( inLen, 2 );
+    SKP_int32 in32, out32, Y, X;
+
+    SKP_assert( SKP_Silk_resampler_down2_0 > 0 );
+    SKP_assert( SKP_Silk_resampler_down2_1 < 0 );
+
+    /* Internal variables and state are in Q10 format */
+    for( k = 0; k < len4; k++ ) {
+        /* Add two input samples and convert to Q10 */
+        in32 = SKP_LSHIFT( SKP_ADD32( (SKP_int32)in[ 4 * k ], (SKP_int32)in[ 4 * k + 1 ] ), 9 );
+
+        /* All-pass section for even input sample */
+        Y      = SKP_SUB32( in32, S[ 0 ] );
+        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_down2_1 );
+        out32  = SKP_ADD32( S[ 0 ], X );
+        S[ 0 ] = SKP_ADD32( in32, X );
+
+        /* Add two input samples and convert to Q10 */
+        in32 = SKP_LSHIFT( SKP_ADD32( (SKP_int32)in[ 4 * k + 2 ], (SKP_int32)in[ 4 * k + 3 ] ), 9 );
+
+        /* All-pass section for odd input sample */
+        Y      = SKP_SUB32( in32, S[ 1 ] );
+        X      = SKP_SMULWB( Y, SKP_Silk_resampler_down2_0 );
+        out32  = SKP_ADD32( out32, S[ 1 ] );
+        out32  = SKP_ADD32( out32, X );
+        S[ 1 ] = SKP_ADD32( in32, X );
+
+        /* Add, convert back to int16 and store to output */
+        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 11 ) );
+    }
+}
index f84357beb141e8b6eccd647a0cfe0261c011e0b0..61da218efd7a222e89eee88a7cd9bf6a0a343248 100644 (file)
-/***********************************************************************\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
- * File Name:  SKP_Silk_resampler_private_down_FIR.c                 *\r
- *                                                                                                                                             *\r
- * Description: Hybrid IIR/FIR polyphase implementation of resampling  *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- * All rights reserved.                                                                                                        *\r
- *                                                                      */\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_resampler_private.h"\r
-SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_down_FIR_INTERPOL0(\r
-       SKP_int16 *out, SKP_int32 *buf2, const SKP_int16 *FIR_Coefs, SKP_int32 max_index_Q16, SKP_int32 index_increment_Q16){\r
-       \r
-       SKP_int32 index_Q16, res_Q6;\r
-       SKP_int32 *buf_ptr;\r
-       for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {\r
-               /* Integer part gives pointer to buffered input */\r
-               buf_ptr = buf2 + SKP_RSHIFT( index_Q16, 16 );\r
-\r
-               /* Inner product */\r
-               res_Q6 = SKP_SMULWB(         SKP_ADD32( buf_ptr[ 0 ], buf_ptr[ 11 ] ), FIR_Coefs[ 0 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 1 ], buf_ptr[ 10 ] ), FIR_Coefs[ 1 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 2 ], buf_ptr[  9 ] ), FIR_Coefs[ 2 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 3 ], buf_ptr[  8 ] ), FIR_Coefs[ 3 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 4 ], buf_ptr[  7 ] ), FIR_Coefs[ 4 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 5 ], buf_ptr[  6 ] ), FIR_Coefs[ 5 ] );\r
-\r
-                           /* Scale down, saturate and store in output array */\r
-               *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );\r
-       }\r
-       return out;\r
-}\r
-\r
-SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_down_FIR_INTERPOL1(\r
-       SKP_int16 *out, SKP_int32 *buf2, const SKP_int16 *FIR_Coefs, SKP_int32 max_index_Q16, SKP_int32 index_increment_Q16, SKP_int32 FIR_Fracs){\r
-       \r
-       SKP_int32 index_Q16, res_Q6;\r
-       SKP_int32 *buf_ptr;\r
-       SKP_int32 interpol_ind;\r
-       const SKP_int16 *interpol_ptr;\r
-       for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {\r
-               /* Integer part gives pointer to buffered input */\r
-               buf_ptr = buf2 + SKP_RSHIFT( index_Q16, 16 );\r
-\r
-               /* Fractional part gives interpolation coefficients */\r
-               interpol_ind = SKP_SMULWB( index_Q16 & 0xFFFF, FIR_Fracs );\r
-\r
-               /* Inner product */\r
-               interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR / 2 * interpol_ind ];\r
-               res_Q6 = SKP_SMULWB(         buf_ptr[ 0 ], interpol_ptr[ 0 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 1 ], interpol_ptr[ 1 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], interpol_ptr[ 2 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], interpol_ptr[ 3 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 4 ], interpol_ptr[ 4 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 5 ], interpol_ptr[ 5 ] );\r
-               interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR / 2 * ( FIR_Fracs - 1 - interpol_ind ) ];\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 11 ], interpol_ptr[ 0 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 10 ], interpol_ptr[ 1 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  9 ], interpol_ptr[ 2 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  8 ], interpol_ptr[ 3 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  7 ], interpol_ptr[ 4 ] );\r
-               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  6 ], interpol_ptr[ 5 ] );\r
-\r
-               /* Scale down, saturate and store in output array */\r
-               *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );\r
-       }\r
-       return out;\r
-}\r
-\r
-\r
-/* Resample with a 2x downsampler (optional), a 2nd order AR filter followed by FIR interpolation */\r
-void SKP_Silk_resampler_private_down_FIR(\r
-       void                            *SS,                /* I/O: Resampler state                                             */\r
-       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
-       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
-       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
-)\r
-{\r
-    SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS;\r
-       SKP_int32 nSamplesIn;\r
-       SKP_int32 max_index_Q16, index_increment_Q16;\r
-       SKP_int16 buf1[ RESAMPLER_MAX_BATCH_SIZE_IN / 2 ];\r
-       SKP_int32 buf2[ RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_DOWN_ORDER_FIR ];\r
-       const SKP_int16 *FIR_Coefs;\r
-\r
-       /* Copy buffered samples to start of buffer */  \r
-       SKP_memcpy( buf2, S->sFIR, RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) );\r
-\r
-    FIR_Coefs = &S->Coefs[ 2 ];\r
-\r
-       /* Iterate over blocks of frameSizeIn input samples */\r
-    index_increment_Q16 = S->invRatio_Q16;\r
-       while( 1 ) {\r
-               nSamplesIn = SKP_min( inLen, S->batchSize );\r
-\r
-        if( S->input2x == 1 ) {\r
-            /* Downsample 2x */\r
-            SKP_Silk_resampler_down2( S->sDown2, buf1, in, nSamplesIn );\r
-\r
-            nSamplesIn = SKP_RSHIFT32( nSamplesIn, 1 );\r
-\r
-                   /* Second-order AR filter (output in Q8) */\r
-                   SKP_Silk_resampler_private_AR2( S->sIIR, &buf2[ RESAMPLER_DOWN_ORDER_FIR ], buf1, S->Coefs, nSamplesIn );\r
-        } else {\r
-                   /* Second-order AR filter (output in Q8) */\r
-                   SKP_Silk_resampler_private_AR2( S->sIIR, &buf2[ RESAMPLER_DOWN_ORDER_FIR ], in, S->Coefs, nSamplesIn );\r
-        }\r
-\r
-        max_index_Q16 = SKP_LSHIFT32( nSamplesIn, 16 );\r
-\r
-               /* Interpolate filtered signal */\r
-        if( S->FIR_Fracs == 1 ) {\r
-               out = SKP_Silk_resampler_private_down_FIR_INTERPOL0(out, buf2, FIR_Coefs, max_index_Q16, index_increment_Q16);\r
-        } else {\r
-               out = SKP_Silk_resampler_private_down_FIR_INTERPOL1(out, buf2, FIR_Coefs, max_index_Q16, index_increment_Q16, S->FIR_Fracs);\r
-        }\r
-        \r
-               in += nSamplesIn << S->input2x;\r
-               inLen -= nSamplesIn << S->input2x;\r
-\r
-               if( inLen > S->input2x ) {\r
-                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */\r
-                       SKP_memcpy( buf2, &buf2[ nSamplesIn ], RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) );\r
-               } else {\r
-                       break;\r
-               }\r
-       }\r
-\r
-       /* Copy last part of filtered signal to the state for the next call */\r
-       SKP_memcpy( S->sFIR, &buf2[ nSamplesIn ], RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) );\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                                                                                             *
+ * File Name:  SKP_Silk_resampler_private_down_FIR.c                 *
+ *                                                                                                                                             *
+ * Description: Hybrid IIR/FIR polyphase implementation of resampling  *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ * All rights reserved.                                                                                                        *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_private.h"
+SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_down_FIR_INTERPOL0(
+       SKP_int16 *out, SKP_int32 *buf2, const SKP_int16 *FIR_Coefs, SKP_int32 max_index_Q16, SKP_int32 index_increment_Q16){
+       
+       SKP_int32 index_Q16, res_Q6;
+       SKP_int32 *buf_ptr;
+       for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {
+               /* Integer part gives pointer to buffered input */
+               buf_ptr = buf2 + SKP_RSHIFT( index_Q16, 16 );
+
+               /* Inner product */
+               res_Q6 = SKP_SMULWB(         SKP_ADD32( buf_ptr[ 0 ], buf_ptr[ 11 ] ), FIR_Coefs[ 0 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 1 ], buf_ptr[ 10 ] ), FIR_Coefs[ 1 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 2 ], buf_ptr[  9 ] ), FIR_Coefs[ 2 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 3 ], buf_ptr[  8 ] ), FIR_Coefs[ 3 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 4 ], buf_ptr[  7 ] ), FIR_Coefs[ 4 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 5 ], buf_ptr[  6 ] ), FIR_Coefs[ 5 ] );
+
+                           /* Scale down, saturate and store in output array */
+               *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );
+       }
+       return out;
+}
+
+SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_down_FIR_INTERPOL1(
+       SKP_int16 *out, SKP_int32 *buf2, const SKP_int16 *FIR_Coefs, SKP_int32 max_index_Q16, SKP_int32 index_increment_Q16, SKP_int32 FIR_Fracs){
+       
+       SKP_int32 index_Q16, res_Q6;
+       SKP_int32 *buf_ptr;
+       SKP_int32 interpol_ind;
+       const SKP_int16 *interpol_ptr;
+       for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {
+               /* Integer part gives pointer to buffered input */
+               buf_ptr = buf2 + SKP_RSHIFT( index_Q16, 16 );
+
+               /* Fractional part gives interpolation coefficients */
+               interpol_ind = SKP_SMULWB( index_Q16 & 0xFFFF, FIR_Fracs );
+
+               /* Inner product */
+               interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR / 2 * interpol_ind ];
+               res_Q6 = SKP_SMULWB(         buf_ptr[ 0 ], interpol_ptr[ 0 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 1 ], interpol_ptr[ 1 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], interpol_ptr[ 2 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], interpol_ptr[ 3 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 4 ], interpol_ptr[ 4 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 5 ], interpol_ptr[ 5 ] );
+               interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR / 2 * ( FIR_Fracs - 1 - interpol_ind ) ];
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 11 ], interpol_ptr[ 0 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 10 ], interpol_ptr[ 1 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  9 ], interpol_ptr[ 2 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  8 ], interpol_ptr[ 3 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  7 ], interpol_ptr[ 4 ] );
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  6 ], interpol_ptr[ 5 ] );
+
+               /* Scale down, saturate and store in output array */
+               *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );
+       }
+       return out;
+}
+
+
+/* Resample with a 2x downsampler (optional), a 2nd order AR filter followed by FIR interpolation */
+void SKP_Silk_resampler_private_down_FIR(
+       void                            *SS,                /* I/O: Resampler state                                             */
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */
+)
+{
+    SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS;
+       SKP_int32 nSamplesIn;
+       SKP_int32 max_index_Q16, index_increment_Q16;
+       SKP_int16 buf1[ RESAMPLER_MAX_BATCH_SIZE_IN / 2 ];
+       SKP_int32 buf2[ RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_DOWN_ORDER_FIR ];
+       const SKP_int16 *FIR_Coefs;
+
+       /* Copy buffered samples to start of buffer */  
+       SKP_memcpy( buf2, S->sFIR, RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) );
+
+    FIR_Coefs = &S->Coefs[ 2 ];
+
+       /* Iterate over blocks of frameSizeIn input samples */
+    index_increment_Q16 = S->invRatio_Q16;
+       while( 1 ) {
+               nSamplesIn = SKP_min( inLen, S->batchSize );
+
+        if( S->input2x == 1 ) {
+            /* Downsample 2x */
+            SKP_Silk_resampler_down2( S->sDown2, buf1, in, nSamplesIn );
+
+            nSamplesIn = SKP_RSHIFT32( nSamplesIn, 1 );
+
+                   /* Second-order AR filter (output in Q8) */
+                   SKP_Silk_resampler_private_AR2( S->sIIR, &buf2[ RESAMPLER_DOWN_ORDER_FIR ], buf1, S->Coefs, nSamplesIn );
+        } else {
+                   /* Second-order AR filter (output in Q8) */
+                   SKP_Silk_resampler_private_AR2( S->sIIR, &buf2[ RESAMPLER_DOWN_ORDER_FIR ], in, S->Coefs, nSamplesIn );
+        }
+
+        max_index_Q16 = SKP_LSHIFT32( nSamplesIn, 16 );
+
+               /* Interpolate filtered signal */
+        if( S->FIR_Fracs == 1 ) {
+               out = SKP_Silk_resampler_private_down_FIR_INTERPOL0(out, buf2, FIR_Coefs, max_index_Q16, index_increment_Q16);
+        } else {
+               out = SKP_Silk_resampler_private_down_FIR_INTERPOL1(out, buf2, FIR_Coefs, max_index_Q16, index_increment_Q16, S->FIR_Fracs);
+        }
+        
+               in += nSamplesIn << S->input2x;
+               inLen -= nSamplesIn << S->input2x;
+
+               if( inLen > S->input2x ) {
+                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */
+                       SKP_memcpy( buf2, &buf2[ nSamplesIn ], RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) );
+               } else {
+                       break;
+               }
+       }
+
+       /* Copy last part of filtered signal to the state for the next call */
+       SKP_memcpy( S->sFIR, &buf2[ nSamplesIn ], RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) );
+}
+
index 8ae2548e36f4d08af07342be785ff644d5ece64a..1d755174fe2b3cf9f2c1d8365235fa978eae60ed 100644 (file)
-/***********************************************************************\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_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
-/* Upsample by a factor 2, high quality */\r
-/* Uses 2nd order allpass filters for the 2x upsampling, followed by a      */\r
-/* notch filter just above Nyquist.                                         */\r
-void SKP_Silk_resampler_private_up2_HQ(\r
-       SKP_int32                           *S,                     /* I/O: Resampler state [ 6 ]                                       */\r
-    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */\r
-    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
-    SKP_int32                       len             /* I:   Number of INPUT samples                 */\r
-)\r
-{\r
-    SKP_int32 k;\r
-    SKP_int32 in32, out32_1, out32_2, Y, X;\r
-\r
-    SKP_assert( SKP_Silk_resampler_up2_hq_0[ 0 ] > 0 );\r
-    SKP_assert( SKP_Silk_resampler_up2_hq_0[ 1 ] < 0 );\r
-    SKP_assert( SKP_Silk_resampler_up2_hq_1[ 0 ] > 0 );\r
-    SKP_assert( SKP_Silk_resampler_up2_hq_1[ 1 ] < 0 );\r
-    \r
-    /* Internal variables and state are in Q10 format */\r
-    for( k = 0; k < len; k++ ) {\r
-        /* Convert to Q10 */\r
-        in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 );\r
-\r
-        /* First all-pass section for even output sample */\r
-        Y       = SKP_SUB32( in32, S[ 0 ] );\r
-        X       = SKP_SMULWB( Y, SKP_Silk_resampler_up2_hq_0[ 0 ] );\r
-        out32_1 = SKP_ADD32( S[ 0 ], X );\r
-        S[ 0 ]  = SKP_ADD32( in32, X );\r
-\r
-        /* Second all-pass section for even output sample */\r
-        Y       = SKP_SUB32( out32_1, S[ 1 ] );\r
-        X       = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_hq_0[ 1 ] );\r
-        out32_2 = SKP_ADD32( S[ 1 ], X );\r
-        S[ 1 ]  = SKP_ADD32( out32_1, X );\r
-\r
-        /* Biquad notch filter */\r
-        out32_2 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 2 ] );\r
-        out32_2 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 1 ] );\r
-        out32_1 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 0 ] );\r
-        S[ 5 ]  = SKP_SUB32(  out32_2, S[ 5 ] );\r
-        \r
-        /* Apply gain in Q15, convert back to int16 and store to output */\r
-        out[ 2 * k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( \r
-            SKP_SMLAWB( 256, out32_1, SKP_Silk_resampler_up2_hq_notch[ 3 ] ), 9 ) );\r
-\r
-        /* First all-pass section for odd output sample */\r
-        Y       = SKP_SUB32( in32, S[ 2 ] );\r
-        X       = SKP_SMULWB( Y, SKP_Silk_resampler_up2_hq_1[ 0 ] );\r
-        out32_1 = SKP_ADD32( S[ 2 ], X );\r
-        S[ 2 ]  = SKP_ADD32( in32, X );\r
-\r
-        /* Second all-pass section for odd output sample */\r
-        Y       = SKP_SUB32( out32_1, S[ 3 ] );\r
-        X       = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_hq_1[ 1 ] );\r
-        out32_2 = SKP_ADD32( S[ 3 ], X );\r
-        S[ 3 ]  = SKP_ADD32( out32_1, X );\r
-\r
-        /* Biquad notch filter */\r
-        out32_2 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 2 ] );\r
-        out32_2 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 1 ] );\r
-        out32_1 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 0 ] );\r
-        S[ 4 ]  = SKP_SUB32(  out32_2, S[ 4 ] );\r
-        \r
-        /* Apply gain in Q15, convert back to int16 and store to output */\r
-        out[ 2 * k + 1 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( \r
-            SKP_SMLAWB( 256, out32_1, SKP_Silk_resampler_up2_hq_notch[ 3 ] ), 9 ) );\r
-    }\r
-}\r
-\r
-\r
-void SKP_Silk_resampler_private_up2_HQ_wrapper(\r
-       void                            *SS,                /* I/O: Resampler state (unused)                            */\r
-    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */\r
-    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
-    SKP_int32                       len             /* I:   Number of input samples                 */\r
-)\r
-{\r
-    SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS;\r
-    SKP_Silk_resampler_private_up2_HQ( S->sIIR, out, in, len );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_resampler_private_up2_HQ.c                                *
+ *                                                                      *
+ * Upsample by a factor 2, high quality                                 *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_private.h"
+
+/* Upsample by a factor 2, high quality */
+/* Uses 2nd order allpass filters for the 2x upsampling, followed by a      */
+/* notch filter just above Nyquist.                                         */
+void SKP_Silk_resampler_private_up2_HQ(
+       SKP_int32                           *S,                     /* I/O: Resampler state [ 6 ]                                       */
+    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */
+    SKP_int32                       len             /* I:   Number of INPUT samples                 */
+)
+{
+    SKP_int32 k;
+    SKP_int32 in32, out32_1, out32_2, Y, X;
+
+    SKP_assert( SKP_Silk_resampler_up2_hq_0[ 0 ] > 0 );
+    SKP_assert( SKP_Silk_resampler_up2_hq_0[ 1 ] < 0 );
+    SKP_assert( SKP_Silk_resampler_up2_hq_1[ 0 ] > 0 );
+    SKP_assert( SKP_Silk_resampler_up2_hq_1[ 1 ] < 0 );
+    
+    /* Internal variables and state are in Q10 format */
+    for( k = 0; k < len; k++ ) {
+        /* Convert to Q10 */
+        in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 );
+
+        /* First all-pass section for even output sample */
+        Y       = SKP_SUB32( in32, S[ 0 ] );
+        X       = SKP_SMULWB( Y, SKP_Silk_resampler_up2_hq_0[ 0 ] );
+        out32_1 = SKP_ADD32( S[ 0 ], X );
+        S[ 0 ]  = SKP_ADD32( in32, X );
+
+        /* Second all-pass section for even output sample */
+        Y       = SKP_SUB32( out32_1, S[ 1 ] );
+        X       = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_hq_0[ 1 ] );
+        out32_2 = SKP_ADD32( S[ 1 ], X );
+        S[ 1 ]  = SKP_ADD32( out32_1, X );
+
+        /* Biquad notch filter */
+        out32_2 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 2 ] );
+        out32_2 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 1 ] );
+        out32_1 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 0 ] );
+        S[ 5 ]  = SKP_SUB32(  out32_2, S[ 5 ] );
+        
+        /* Apply gain in Q15, convert back to int16 and store to output */
+        out[ 2 * k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( 
+            SKP_SMLAWB( 256, out32_1, SKP_Silk_resampler_up2_hq_notch[ 3 ] ), 9 ) );
+
+        /* First all-pass section for odd output sample */
+        Y       = SKP_SUB32( in32, S[ 2 ] );
+        X       = SKP_SMULWB( Y, SKP_Silk_resampler_up2_hq_1[ 0 ] );
+        out32_1 = SKP_ADD32( S[ 2 ], X );
+        S[ 2 ]  = SKP_ADD32( in32, X );
+
+        /* Second all-pass section for odd output sample */
+        Y       = SKP_SUB32( out32_1, S[ 3 ] );
+        X       = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_hq_1[ 1 ] );
+        out32_2 = SKP_ADD32( S[ 3 ], X );
+        S[ 3 ]  = SKP_ADD32( out32_1, X );
+
+        /* Biquad notch filter */
+        out32_2 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 2 ] );
+        out32_2 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 1 ] );
+        out32_1 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 0 ] );
+        S[ 4 ]  = SKP_SUB32(  out32_2, S[ 4 ] );
+        
+        /* Apply gain in Q15, convert back to int16 and store to output */
+        out[ 2 * k + 1 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( 
+            SKP_SMLAWB( 256, out32_1, SKP_Silk_resampler_up2_hq_notch[ 3 ] ), 9 ) );
+    }
+}
+
+
+void SKP_Silk_resampler_private_up2_HQ_wrapper(
+       void                            *SS,                /* I/O: Resampler state (unused)                            */
+    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */
+    SKP_int32                       len             /* I:   Number of input samples                 */
+)
+{
+    SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS;
+    SKP_Silk_resampler_private_up2_HQ( S->sIIR, out, in, len );
+}
index 9c63d400e27409c9c62e18ebfeb467cdb9da1f86..96b4e2a186778204a95d4da2bcf1d2b142e2c3dc 100644 (file)
@@ -1,81 +1,81 @@
-/***********************************************************************\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_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
-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
-    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
-    SKP_int32                       len             /* I:   Number of INPUT samples                 */\r
-)\r
-{\r
-    SKP_int32 k;\r
-    SKP_int32 in32, out32, Y, X;\r
-    SKP_int16 out16;\r
-\r
-    SKP_assert( SKP_Silk_resampler_up2_lq_0 > 0 );\r
-    SKP_assert( SKP_Silk_resampler_up2_lq_1 < 0 );\r
-\r
-    /* Internal variables and state are in Q10 format */\r
-    for( k = 0; k < len; k++ ) {\r
-        /* Convert to Q10 */\r
-        in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 );\r
-\r
-        /* All-pass section for even output sample */\r
-        Y      = SKP_SUB32( in32, S[ 0 ] );\r
-        X      = SKP_SMULWB( Y, SKP_Silk_resampler_up2_lq_0 );\r
-        out32  = SKP_ADD32( S[ 0 ], X );\r
-        S[ 0 ] = SKP_ADD32( in32, X );\r
-\r
-        /* Convert back to int16 and store to output */\r
-        out16 = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );\r
-        out[ 4 * k ]     = out16;\r
-        out[ 4 * k + 1 ] = out16;\r
-\r
-        /* All-pass section for odd output sample */\r
-        Y      = SKP_SUB32( in32, S[ 1 ] );\r
-        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_lq_1 );\r
-        out32  = SKP_ADD32( S[ 1 ], X );\r
-        S[ 1 ] = SKP_ADD32( in32, X );\r
-\r
-        /* Convert back to int16 and store to output */\r
-        out16 = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );\r
-        out[ 4 * k + 2 ] = out16;\r
-        out[ 4 * k + 3 ] = out16;\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_resampler_private_up4.c                                   *
+ *                                                                      *
+ * Upsample by a factor 4, low quality                                  *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_private.h"
+
+/* Upsample by a factor 4, Note: very low quality, only use with output sampling rates above 96 kHz. */
+void SKP_Silk_resampler_private_up4(
+    SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */
+    SKP_int16                       *out,           /* O:   Output signal [ 4 * len ]               */
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */
+    SKP_int32                       len             /* I:   Number of INPUT samples                 */
+)
+{
+    SKP_int32 k;
+    SKP_int32 in32, out32, Y, X;
+    SKP_int16 out16;
+
+    SKP_assert( SKP_Silk_resampler_up2_lq_0 > 0 );
+    SKP_assert( SKP_Silk_resampler_up2_lq_1 < 0 );
+
+    /* Internal variables and state are in Q10 format */
+    for( k = 0; k < len; k++ ) {
+        /* Convert to Q10 */
+        in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 );
+
+        /* All-pass section for even output sample */
+        Y      = SKP_SUB32( in32, S[ 0 ] );
+        X      = SKP_SMULWB( Y, SKP_Silk_resampler_up2_lq_0 );
+        out32  = SKP_ADD32( S[ 0 ], X );
+        S[ 0 ] = SKP_ADD32( in32, X );
+
+        /* Convert back to int16 and store to output */
+        out16 = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );
+        out[ 4 * k ]     = out16;
+        out[ 4 * k + 1 ] = out16;
+
+        /* All-pass section for odd output sample */
+        Y      = SKP_SUB32( in32, S[ 1 ] );
+        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_lq_1 );
+        out32  = SKP_ADD32( S[ 1 ], X );
+        S[ 1 ] = SKP_ADD32( in32, X );
+
+        /* Convert back to int16 and store to output */
+        out16 = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );
+        out[ 4 * k + 2 ] = out16;
+        out[ 4 * k + 3 ] = out16;
+    }
+}
index 96ecde3659e1a8309c23404ae4c7cb90ab4d88be..2589547fbfea4e0e2dfaa7b3dc72f7750c7785d7 100644 (file)
-/***********************************************************************\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
- * File Name:  SKP_Silk_resampler_rom.c                                                                *\r
- *                                                                                                                                             *\r
- * Description: Filter coefficients for IIR/FIR polyphase resampling   *\r
- * Total size: 550 Words (1.1 kB)                                      *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- * All rights reserved.                                                                                                        *\r
- *                                                                      */\r
-\r
-#include "SKP_Silk_resampler_private.h"\r
-\r
-/* Tables for 2x downsampler */\r
-const SKP_int16 SKP_Silk_resampler_down2_0 = 9872;\r
-const SKP_int16 SKP_Silk_resampler_down2_1 = 39809 - 65536;\r
-\r
-/* Tables for 2x upsampler, low quality */\r
-const SKP_int16 SKP_Silk_resampler_up2_lq_0 = 8102;\r
-const SKP_int16 SKP_Silk_resampler_up2_lq_1 = 36783 - 65536;\r
-\r
-/* Tables for 2x upsampler, high quality */\r
-const SKP_int16 SKP_Silk_resampler_up2_hq_0[ 2 ] = {  4280, 33727 - 65536 };\r
-const SKP_int16 SKP_Silk_resampler_up2_hq_1[ 2 ] = { 16295, 54015 - 65536 };\r
-/* Matlab code for the notch filter coefficients: */\r
-/* B = [1, 0.12, 1];  A = [1, 0.055, 0.8]; G = 0.87; freqz(G * B, A, 2^14, 16e3); axis([0, 8000, -10, 1]);  */\r
-/* fprintf('\t%6d, %6d, %6d, %6d\n', round(B(2)*2^16), round(-A(2)*2^16), round((1-A(3))*2^16), round(G*2^15)) */\r
-const SKP_int16 SKP_Silk_resampler_up2_hq_notch[ 4 ] = { 7864,  -3604,  13107,  28508 };\r
-\r
-\r
-/* Tables with IIR and FIR coefficients for fractional downsamplers (70 Words) */\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = {\r
-       -18249, -12532,\r
-          -97,    284,   -495,    309,  10268,  20317,\r
-          -94,    156,    -48,   -720,   5984,  18278,\r
-          -45,     -4,    237,   -847,   2540,  14662,\r
-};\r
-\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = {\r
-       -11891, -12486,\r
-           20,    211,   -657,    688,   8423,  15911,\r
-          -44,    197,   -152,   -653,   3855,  13015,\r
-};\r
-\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_2_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR / 2 ] = {\r
-         2415, -13101,\r
-          158,   -295,   -400,   1265,   4832,   7968,\r
-};\r
-\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_3_8_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = {\r
-        13270, -13738,\r
-         -294,   -123,    747,   2043,   3339,   3995,\r
-         -151,   -311,    414,   1583,   2947,   3877,\r
-          -33,   -389,    143,   1141,   2503,   3653,\r
-};\r
-\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_3_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR / 2 ] = {\r
-        16643, -14000,\r
-         -331,     19,    581,   1421,   2290,   2845,\r
-};\r
-\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ] = {\r
-        -2797,  -6507,\r
-         4697,  10739,\r
-         1567,   8276,\r
-};\r
-\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 + 3 ] = {\r
-        16777,  -9792,\r
-          890,   1614,   2148,\r
-};\r
-\r
-\r
-/* Tables with coefficients for 4th order ARMA filter (35 Words), in a packed format:       */\r
-/*    { B1_Q14[1], B2_Q14[1], -A1_Q14[1], -A1_Q14[2], -A2_Q14[1], -A2_Q14[2], gain_Q16 }    */\r
-/* where it is assumed that B*_Q14[0], B*_Q14[2], A*_Q14[0] are all 16384                   */\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_320_441_ARMA4_COEFS[ 7 ] = {\r
-        31454,  24746,  -9706,  -3386, -17911, -13243,  24797\r
-};\r
-\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_240_441_ARMA4_COEFS[ 7 ] = {\r
-        28721,  11254,   3189,  -2546,  -1495, -12618,  11562\r
-};\r
-\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_160_441_ARMA4_COEFS[ 7 ] = {\r
-        23492,  -6457,  14358,  -4856,  14654, -13008,   4456\r
-};\r
-\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_120_441_ARMA4_COEFS[ 7 ] = {\r
-        19311, -15569,  19489,  -6950,  21441, -13559,   2370\r
-};\r
-\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_80_441_ARMA4_COEFS[ 7 ] = {\r
-        13248, -23849,  24126,  -9486,  26806, -14286,   1065\r
-};\r
-\r
-/* Table with interplation fractions of 1/288 : 2/288 : 287/288 (432 Words) */\r
-SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_resampler_frac_FIR_144[ 144 ][ RESAMPLER_ORDER_FIR_144 / 2 ] = {\r
-       { -647,  1884, 30078},\r
-       { -625,  1736, 30044},\r
-       { -603,  1591, 30005},\r
-       { -581,  1448, 29963},\r
-       { -559,  1308, 29917},\r
-       { -537,  1169, 29867},\r
-       { -515,  1032, 29813},\r
-       { -494,   898, 29755},\r
-       { -473,   766, 29693},\r
-       { -452,   636, 29627},\r
-       { -431,   508, 29558},\r
-       { -410,   383, 29484},\r
-       { -390,   260, 29407},\r
-       { -369,   139, 29327},\r
-       { -349,    20, 29242},\r
-       { -330,   -97, 29154},\r
-       { -310,  -211, 29062},\r
-       { -291,  -324, 28967},\r
-       { -271,  -434, 28868},\r
-       { -253,  -542, 28765},\r
-       { -234,  -647, 28659},\r
-       { -215,  -751, 28550},\r
-       { -197,  -852, 28436},\r
-       { -179,  -951, 28320},\r
-       { -162, -1048, 28200},\r
-       { -144, -1143, 28077},\r
-       { -127, -1235, 27950},\r
-       { -110, -1326, 27820},\r
-       {  -94, -1414, 27687},\r
-       {  -77, -1500, 27550},\r
-       {  -61, -1584, 27410},\r
-       {  -45, -1665, 27268},\r
-       {  -30, -1745, 27122},\r
-       {  -15, -1822, 26972},\r
-       {    0, -1897, 26820},\r
-       {   15, -1970, 26665},\r
-       {   29, -2041, 26507},\r
-       {   44, -2110, 26346},\r
-       {   57, -2177, 26182},\r
-       {   71, -2242, 26015},\r
-       {   84, -2305, 25845},\r
-       {   97, -2365, 25673},\r
-       {  110, -2424, 25498},\r
-       {  122, -2480, 25320},\r
-       {  134, -2534, 25140},\r
-       {  146, -2587, 24956},\r
-       {  157, -2637, 24771},\r
-       {  168, -2685, 24583},\r
-       {  179, -2732, 24392},\r
-       {  190, -2776, 24199},\r
-       {  200, -2819, 24003},\r
-       {  210, -2859, 23805},\r
-       {  220, -2898, 23605},\r
-       {  229, -2934, 23403},\r
-       {  238, -2969, 23198},\r
-       {  247, -3002, 22992},\r
-       {  255, -3033, 22783},\r
-       {  263, -3062, 22572},\r
-       {  271, -3089, 22359},\r
-       {  279, -3114, 22144},\r
-       {  286, -3138, 21927},\r
-       {  293, -3160, 21709},\r
-       {  300, -3180, 21488},\r
-       {  306, -3198, 21266},\r
-       {  312, -3215, 21042},\r
-       {  318, -3229, 20816},\r
-       {  323, -3242, 20589},\r
-       {  328, -3254, 20360},\r
-       {  333, -3263, 20130},\r
-       {  338, -3272, 19898},\r
-       {  342, -3278, 19665},\r
-       {  346, -3283, 19430},\r
-       {  350, -3286, 19194},\r
-       {  353, -3288, 18957},\r
-       {  356, -3288, 18718},\r
-       {  359, -3286, 18478},\r
-       {  362, -3283, 18238},\r
-       {  364, -3279, 17996},\r
-       {  366, -3273, 17753},\r
-       {  368, -3266, 17509},\r
-       {  369, -3257, 17264},\r
-       {  371, -3247, 17018},\r
-       {  372, -3235, 16772},\r
-       {  372, -3222, 16525},\r
-       {  373, -3208, 16277},\r
-       {  373, -3192, 16028},\r
-       {  373, -3175, 15779},\r
-       {  373, -3157, 15529},\r
-       {  372, -3138, 15279},\r
-       {  371, -3117, 15028},\r
-       {  370, -3095, 14777},\r
-       {  369, -3072, 14526},\r
-       {  368, -3048, 14274},\r
-       {  366, -3022, 14022},\r
-       {  364, -2996, 13770},\r
-       {  362, -2968, 13517},\r
-       {  359, -2940, 13265},\r
-       {  357, -2910, 13012},\r
-       {  354, -2880, 12760},\r
-       {  351, -2848, 12508},\r
-       {  348, -2815, 12255},\r
-       {  344, -2782, 12003},\r
-       {  341, -2747, 11751},\r
-       {  337, -2712, 11500},\r
-       {  333, -2676, 11248},\r
-       {  328, -2639, 10997},\r
-       {  324, -2601, 10747},\r
-       {  320, -2562, 10497},\r
-       {  315, -2523, 10247},\r
-       {  310, -2482,  9998},\r
-       {  305, -2442,  9750},\r
-       {  300, -2400,  9502},\r
-       {  294, -2358,  9255},\r
-       {  289, -2315,  9009},\r
-       {  283, -2271,  8763},\r
-       {  277, -2227,  8519},\r
-       {  271, -2182,  8275},\r
-       {  265, -2137,  8032},\r
-       {  259, -2091,  7791},\r
-       {  252, -2045,  7550},\r
-       {  246, -1998,  7311},\r
-       {  239, -1951,  7072},\r
-       {  232, -1904,  6835},\r
-       {  226, -1856,  6599},\r
-       {  219, -1807,  6364},\r
-       {  212, -1758,  6131},\r
-       {  204, -1709,  5899},\r
-       {  197, -1660,  5668},\r
-       {  190, -1611,  5439},\r
-       {  183, -1561,  5212},\r
-       {  175, -1511,  4986},\r
-       {  168, -1460,  4761},\r
-       {  160, -1410,  4538},\r
-       {  152, -1359,  4317},\r
-       {  145, -1309,  4098},\r
-       {  137, -1258,  3880},\r
-       {  129, -1207,  3664},\r
-       {  121, -1156,  3450},\r
-       {  113, -1105,  3238},\r
-       {  105, -1054,  3028},\r
-       {   97, -1003,  2820},\r
-       {   89,  -952,  2614},\r
-       {   81,  -901,  2409},\r
-       {   73,  -851,  2207},\r
-};\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                                                                                             *
+ * File Name:  SKP_Silk_resampler_rom.c                                                                *
+ *                                                                                                                                             *
+ * Description: Filter coefficients for IIR/FIR polyphase resampling   *
+ * Total size: 550 Words (1.1 kB)                                      *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ * All rights reserved.                                                                                                        *
+ *                                                                      */
+
+#include "SKP_Silk_resampler_private.h"
+
+/* Tables for 2x downsampler */
+const SKP_int16 SKP_Silk_resampler_down2_0 = 9872;
+const SKP_int16 SKP_Silk_resampler_down2_1 = 39809 - 65536;
+
+/* Tables for 2x upsampler, low quality */
+const SKP_int16 SKP_Silk_resampler_up2_lq_0 = 8102;
+const SKP_int16 SKP_Silk_resampler_up2_lq_1 = 36783 - 65536;
+
+/* Tables for 2x upsampler, high quality */
+const SKP_int16 SKP_Silk_resampler_up2_hq_0[ 2 ] = {  4280, 33727 - 65536 };
+const SKP_int16 SKP_Silk_resampler_up2_hq_1[ 2 ] = { 16295, 54015 - 65536 };
+/* Matlab code for the notch filter coefficients: */
+/* B = [1, 0.12, 1];  A = [1, 0.055, 0.8]; G = 0.87; freqz(G * B, A, 2^14, 16e3); axis([0, 8000, -10, 1]);  */
+/* fprintf('\t%6d, %6d, %6d, %6d\n', round(B(2)*2^16), round(-A(2)*2^16), round((1-A(3))*2^16), round(G*2^15)) */
+const SKP_int16 SKP_Silk_resampler_up2_hq_notch[ 4 ] = { 7864,  -3604,  13107,  28508 };
+
+
+/* Tables with IIR and FIR coefficients for fractional downsamplers (70 Words) */
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = {
+       -18249, -12532,
+          -97,    284,   -495,    309,  10268,  20317,
+          -94,    156,    -48,   -720,   5984,  18278,
+          -45,     -4,    237,   -847,   2540,  14662,
+};
+
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = {
+       -11891, -12486,
+           20,    211,   -657,    688,   8423,  15911,
+          -44,    197,   -152,   -653,   3855,  13015,
+};
+
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_2_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR / 2 ] = {
+         2415, -13101,
+          158,   -295,   -400,   1265,   4832,   7968,
+};
+
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_3_8_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = {
+        13270, -13738,
+         -294,   -123,    747,   2043,   3339,   3995,
+         -151,   -311,    414,   1583,   2947,   3877,
+          -33,   -389,    143,   1141,   2503,   3653,
+};
+
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_3_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR / 2 ] = {
+        16643, -14000,
+         -331,     19,    581,   1421,   2290,   2845,
+};
+
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ] = {
+        -2797,  -6507,
+         4697,  10739,
+         1567,   8276,
+};
+
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 + 3 ] = {
+        16777,  -9792,
+          890,   1614,   2148,
+};
+
+
+/* Tables with coefficients for 4th order ARMA filter (35 Words), in a packed format:       */
+/*    { B1_Q14[1], B2_Q14[1], -A1_Q14[1], -A1_Q14[2], -A2_Q14[1], -A2_Q14[2], gain_Q16 }    */
+/* where it is assumed that B*_Q14[0], B*_Q14[2], A*_Q14[0] are all 16384                   */
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_320_441_ARMA4_COEFS[ 7 ] = {
+        31454,  24746,  -9706,  -3386, -17911, -13243,  24797
+};
+
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_240_441_ARMA4_COEFS[ 7 ] = {
+        28721,  11254,   3189,  -2546,  -1495, -12618,  11562
+};
+
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_160_441_ARMA4_COEFS[ 7 ] = {
+        23492,  -6457,  14358,  -4856,  14654, -13008,   4456
+};
+
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_120_441_ARMA4_COEFS[ 7 ] = {
+        19311, -15569,  19489,  -6950,  21441, -13559,   2370
+};
+
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_80_441_ARMA4_COEFS[ 7 ] = {
+        13248, -23849,  24126,  -9486,  26806, -14286,   1065
+};
+
+/* Table with interplation fractions of 1/288 : 2/288 : 287/288 (432 Words) */
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_resampler_frac_FIR_144[ 144 ][ RESAMPLER_ORDER_FIR_144 / 2 ] = {
+       { -647,  1884, 30078},
+       { -625,  1736, 30044},
+       { -603,  1591, 30005},
+       { -581,  1448, 29963},
+       { -559,  1308, 29917},
+       { -537,  1169, 29867},
+       { -515,  1032, 29813},
+       { -494,   898, 29755},
+       { -473,   766, 29693},
+       { -452,   636, 29627},
+       { -431,   508, 29558},
+       { -410,   383, 29484},
+       { -390,   260, 29407},
+       { -369,   139, 29327},
+       { -349,    20, 29242},
+       { -330,   -97, 29154},
+       { -310,  -211, 29062},
+       { -291,  -324, 28967},
+       { -271,  -434, 28868},
+       { -253,  -542, 28765},
+       { -234,  -647, 28659},
+       { -215,  -751, 28550},
+       { -197,  -852, 28436},
+       { -179,  -951, 28320},
+       { -162, -1048, 28200},
+       { -144, -1143, 28077},
+       { -127, -1235, 27950},
+       { -110, -1326, 27820},
+       {  -94, -1414, 27687},
+       {  -77, -1500, 27550},
+       {  -61, -1584, 27410},
+       {  -45, -1665, 27268},
+       {  -30, -1745, 27122},
+       {  -15, -1822, 26972},
+       {    0, -1897, 26820},
+       {   15, -1970, 26665},
+       {   29, -2041, 26507},
+       {   44, -2110, 26346},
+       {   57, -2177, 26182},
+       {   71, -2242, 26015},
+       {   84, -2305, 25845},
+       {   97, -2365, 25673},
+       {  110, -2424, 25498},
+       {  122, -2480, 25320},
+       {  134, -2534, 25140},
+       {  146, -2587, 24956},
+       {  157, -2637, 24771},
+       {  168, -2685, 24583},
+       {  179, -2732, 24392},
+       {  190, -2776, 24199},
+       {  200, -2819, 24003},
+       {  210, -2859, 23805},
+       {  220, -2898, 23605},
+       {  229, -2934, 23403},
+       {  238, -2969, 23198},
+       {  247, -3002, 22992},
+       {  255, -3033, 22783},
+       {  263, -3062, 22572},
+       {  271, -3089, 22359},
+       {  279, -3114, 22144},
+       {  286, -3138, 21927},
+       {  293, -3160, 21709},
+       {  300, -3180, 21488},
+       {  306, -3198, 21266},
+       {  312, -3215, 21042},
+       {  318, -3229, 20816},
+       {  323, -3242, 20589},
+       {  328, -3254, 20360},
+       {  333, -3263, 20130},
+       {  338, -3272, 19898},
+       {  342, -3278, 19665},
+       {  346, -3283, 19430},
+       {  350, -3286, 19194},
+       {  353, -3288, 18957},
+       {  356, -3288, 18718},
+       {  359, -3286, 18478},
+       {  362, -3283, 18238},
+       {  364, -3279, 17996},
+       {  366, -3273, 17753},
+       {  368, -3266, 17509},
+       {  369, -3257, 17264},
+       {  371, -3247, 17018},
+       {  372, -3235, 16772},
+       {  372, -3222, 16525},
+       {  373, -3208, 16277},
+       {  373, -3192, 16028},
+       {  373, -3175, 15779},
+       {  373, -3157, 15529},
+       {  372, -3138, 15279},
+       {  371, -3117, 15028},
+       {  370, -3095, 14777},
+       {  369, -3072, 14526},
+       {  368, -3048, 14274},
+       {  366, -3022, 14022},
+       {  364, -2996, 13770},
+       {  362, -2968, 13517},
+       {  359, -2940, 13265},
+       {  357, -2910, 13012},
+       {  354, -2880, 12760},
+       {  351, -2848, 12508},
+       {  348, -2815, 12255},
+       {  344, -2782, 12003},
+       {  341, -2747, 11751},
+       {  337, -2712, 11500},
+       {  333, -2676, 11248},
+       {  328, -2639, 10997},
+       {  324, -2601, 10747},
+       {  320, -2562, 10497},
+       {  315, -2523, 10247},
+       {  310, -2482,  9998},
+       {  305, -2442,  9750},
+       {  300, -2400,  9502},
+       {  294, -2358,  9255},
+       {  289, -2315,  9009},
+       {  283, -2271,  8763},
+       {  277, -2227,  8519},
+       {  271, -2182,  8275},
+       {  265, -2137,  8032},
+       {  259, -2091,  7791},
+       {  252, -2045,  7550},
+       {  246, -1998,  7311},
+       {  239, -1951,  7072},
+       {  232, -1904,  6835},
+       {  226, -1856,  6599},
+       {  219, -1807,  6364},
+       {  212, -1758,  6131},
+       {  204, -1709,  5899},
+       {  197, -1660,  5668},
+       {  190, -1611,  5439},
+       {  183, -1561,  5212},
+       {  175, -1511,  4986},
+       {  168, -1460,  4761},
+       {  160, -1410,  4538},
+       {  152, -1359,  4317},
+       {  145, -1309,  4098},
+       {  137, -1258,  3880},
+       {  129, -1207,  3664},
+       {  121, -1156,  3450},
+       {  113, -1105,  3238},
+       {  105, -1054,  3028},
+       {   97, -1003,  2820},
+       {   89,  -952,  2614},
+       {   81,  -901,  2409},
+       {   73,  -851,  2207},
+};
index 3369cb736d4818406cd542b1e70f62f763deb96f..04701178e9b9b010d0e250fd6ea72686b11778a5 100644 (file)
@@ -1,91 +1,91 @@
-/***********************************************************************\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
- * 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
-#ifdef  __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-#include "SKP_Silk_typedef.h"\r
-#include "SKP_Silk_resampler_structs.h"\r
-\r
-#define RESAMPLER_DOWN_ORDER_FIR                12\r
-#define RESAMPLER_ORDER_FIR_144                 6\r
-\r
-\r
-/* Tables for 2x downsampler. Values above 32767 intentionally wrap to a negative value. */\r
-extern const SKP_int16 SKP_Silk_resampler_down2_0;\r
-extern const SKP_int16 SKP_Silk_resampler_down2_1;\r
-\r
-/* Tables for 2x upsampler, low quality. Values above 32767 intentionally wrap to a negative value. */\r
-extern const SKP_int16 SKP_Silk_resampler_up2_lq_0;\r
-extern const SKP_int16 SKP_Silk_resampler_up2_lq_1;\r
-\r
-/* Tables for 2x upsampler, high quality. Values above 32767 intentionally wrap to a negative value. */\r
-extern const SKP_int16 SKP_Silk_resampler_up2_hq_0[ 2 ];\r
-extern const SKP_int16 SKP_Silk_resampler_up2_hq_1[ 2 ];\r
-extern const SKP_int16 SKP_Silk_resampler_up2_hq_notch[ 4 ];\r
-\r
-/* Tables with IIR and FIR coefficients for fractional downsamplers */\r
-extern const SKP_int16 SKP_Silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ];\r
-extern const SKP_int16 SKP_Silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR / 2 ];\r
-extern const SKP_int16 SKP_Silk_Resampler_1_2_COEFS[ 2 +     RESAMPLER_DOWN_ORDER_FIR / 2 ];\r
-extern const SKP_int16 SKP_Silk_Resampler_3_8_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ];\r
-extern const SKP_int16 SKP_Silk_Resampler_1_3_COEFS[ 2 +     RESAMPLER_DOWN_ORDER_FIR / 2 ];\r
-extern const SKP_int16 SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ];\r
-extern const SKP_int16 SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 + 3 ];\r
-\r
-/* Tables with coefficients for 4th order ARMA filter */\r
-extern const SKP_int16 SKP_Silk_Resampler_320_441_ARMA4_COEFS[ 7 ];\r
-extern const SKP_int16 SKP_Silk_Resampler_240_441_ARMA4_COEFS[ 7 ];\r
-extern const SKP_int16 SKP_Silk_Resampler_160_441_ARMA4_COEFS[ 7 ];\r
-extern const SKP_int16 SKP_Silk_Resampler_120_441_ARMA4_COEFS[ 7 ];\r
-extern const SKP_int16 SKP_Silk_Resampler_80_441_ARMA4_COEFS[ 7 ];\r
-\r
-/* Table with interplation fractions of 1/288 : 2/288 : 287/288 (432 Words) */\r
-extern const SKP_int16 SKP_Silk_resampler_frac_FIR_144[ 144 ][ RESAMPLER_ORDER_FIR_144 / 2 ];\r
-\r
-#ifdef  __cplusplus\r
-}\r
-#endif\r
-\r
-#endif // _SKP_SILK_FIX_RESAMPLER_ROM_H_\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * File Name:    SKP_Silk_resample_rom.h                              *
+ *                                                                      *
+ * Description: Header file for FIR resampling of                       *
+ *                32 and 44 kHz input                                   *
+ *                                                                      *
+ * Copyright 2007 (c), Skype Limited                                    *
+ * All rights reserved.                                                 *
+ *                                                                      *
+ * Date: 070807                                                         *
+ *                                                                      */
+
+#ifndef _SKP_SILK_FIX_RESAMPLER_ROM_H_
+#define _SKP_SILK_FIX_RESAMPLER_ROM_H_
+
+#ifdef  __cplusplus
+extern "C"
+{
+#endif
+
+#include "SKP_Silk_typedef.h"
+#include "SKP_Silk_resampler_structs.h"
+
+#define RESAMPLER_DOWN_ORDER_FIR                12
+#define RESAMPLER_ORDER_FIR_144                 6
+
+
+/* Tables for 2x downsampler. Values above 32767 intentionally wrap to a negative value. */
+extern const SKP_int16 SKP_Silk_resampler_down2_0;
+extern const SKP_int16 SKP_Silk_resampler_down2_1;
+
+/* Tables for 2x upsampler, low quality. Values above 32767 intentionally wrap to a negative value. */
+extern const SKP_int16 SKP_Silk_resampler_up2_lq_0;
+extern const SKP_int16 SKP_Silk_resampler_up2_lq_1;
+
+/* Tables for 2x upsampler, high quality. Values above 32767 intentionally wrap to a negative value. */
+extern const SKP_int16 SKP_Silk_resampler_up2_hq_0[ 2 ];
+extern const SKP_int16 SKP_Silk_resampler_up2_hq_1[ 2 ];
+extern const SKP_int16 SKP_Silk_resampler_up2_hq_notch[ 4 ];
+
+/* Tables with IIR and FIR coefficients for fractional downsamplers */
+extern const SKP_int16 SKP_Silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ];
+extern const SKP_int16 SKP_Silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR / 2 ];
+extern const SKP_int16 SKP_Silk_Resampler_1_2_COEFS[ 2 +     RESAMPLER_DOWN_ORDER_FIR / 2 ];
+extern const SKP_int16 SKP_Silk_Resampler_3_8_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ];
+extern const SKP_int16 SKP_Silk_Resampler_1_3_COEFS[ 2 +     RESAMPLER_DOWN_ORDER_FIR / 2 ];
+extern const SKP_int16 SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ];
+extern const SKP_int16 SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 + 3 ];
+
+/* Tables with coefficients for 4th order ARMA filter */
+extern const SKP_int16 SKP_Silk_Resampler_320_441_ARMA4_COEFS[ 7 ];
+extern const SKP_int16 SKP_Silk_Resampler_240_441_ARMA4_COEFS[ 7 ];
+extern const SKP_int16 SKP_Silk_Resampler_160_441_ARMA4_COEFS[ 7 ];
+extern const SKP_int16 SKP_Silk_Resampler_120_441_ARMA4_COEFS[ 7 ];
+extern const SKP_int16 SKP_Silk_Resampler_80_441_ARMA4_COEFS[ 7 ];
+
+/* Table with interplation fractions of 1/288 : 2/288 : 287/288 (432 Words) */
+extern const SKP_int16 SKP_Silk_resampler_frac_FIR_144[ 144 ][ RESAMPLER_ORDER_FIR_144 / 2 ];
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif // _SKP_SILK_FIX_RESAMPLER_ROM_H_
index 48c326946c2615c3ca78d097a0d499e840e28d0e..6e320847954fdd495efb2ff01e6c6a252b183bc4 100644 (file)
@@ -1,80 +1,80 @@
-/***********************************************************************\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
- * File Name:  SKP_Silk_resampler_structs.h                                                    *\r
- *                                                                                                                                             *\r
- * Description: Structs for IIR/FIR resamplers                                                 *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- * All rights reserved.                                                                                                        *\r
- *                                                                                                                                             *\r
- *                                                                      */\r
-\r
-#ifndef SKP_Silk_RESAMPLER_STRUCTS_H\r
-#define SKP_Silk_RESAMPLER_STRUCTS_H\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#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
-\r
-#define SKP_Silk_RESAMPLER_MAX_FIR_ORDER                 16\r
-#define SKP_Silk_RESAMPLER_MAX_IIR_ORDER                 6\r
-\r
-\r
-typedef struct _SKP_Silk_resampler_state_struct{\r
-       SKP_int32       sIIR[ SKP_Silk_RESAMPLER_MAX_IIR_ORDER ];        /* this must be the first element of this struct */\r
-       SKP_int32       sFIR[ SKP_Silk_RESAMPLER_MAX_FIR_ORDER ];\r
-       SKP_int32       sDown2[ 2 ];\r
-       void            (*resampler_function)( void *, SKP_int16 *, const SKP_int16 *, SKP_int32 );\r
-       void            (*up2_function)(  SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 );\r
-    SKP_int32       batchSize;\r
-       SKP_int32       invRatio_Q16;\r
-       SKP_int32       FIR_Fracs;\r
-    SKP_int32       input2x;\r
-       const SKP_int16 *Coefs;\r
-#if RESAMPLER_SUPPORT_ABOVE_48KHZ\r
-       SKP_int32       sDownPre[ 2 ];\r
-       SKP_int32       sUpPost[ 2 ];\r
-       void            (*down_pre_function)( SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 );\r
-       void            (*up_post_function)(  SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 );\r
-       SKP_int32       batchSizePrePost;\r
-       SKP_int32       ratio_Q16;\r
-       SKP_int32       nPreDownsamplers;\r
-       SKP_int32       nPostUpsamplers;\r
-#endif\r
-       SKP_int32 magic_number;\r
-} SKP_Silk_resampler_state_struct;\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-#endif /* SKP_Silk_RESAMPLER_STRUCTS_H */\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                                                                                             *
+ * File Name:  SKP_Silk_resampler_structs.h                                                    *
+ *                                                                                                                                             *
+ * Description: Structs for IIR/FIR resamplers                                                 *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ * All rights reserved.                                                                                                        *
+ *                                                                                                                                             *
+ *                                                                      */
+
+#ifndef SKP_Silk_RESAMPLER_STRUCTS_H
+#define SKP_Silk_RESAMPLER_STRUCTS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Flag to enable support for input/output sampling rates above 48 kHz. Turn off for embedded devices */
+#define RESAMPLER_SUPPORT_ABOVE_48KHZ                   1
+
+#define SKP_Silk_RESAMPLER_MAX_FIR_ORDER                 16
+#define SKP_Silk_RESAMPLER_MAX_IIR_ORDER                 6
+
+
+typedef struct _SKP_Silk_resampler_state_struct{
+       SKP_int32       sIIR[ SKP_Silk_RESAMPLER_MAX_IIR_ORDER ];        /* this must be the first element of this struct */
+       SKP_int32       sFIR[ SKP_Silk_RESAMPLER_MAX_FIR_ORDER ];
+       SKP_int32       sDown2[ 2 ];
+       void            (*resampler_function)( void *, SKP_int16 *, const SKP_int16 *, SKP_int32 );
+       void            (*up2_function)(  SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 );
+    SKP_int32       batchSize;
+       SKP_int32       invRatio_Q16;
+       SKP_int32       FIR_Fracs;
+    SKP_int32       input2x;
+       const SKP_int16 *Coefs;
+#if RESAMPLER_SUPPORT_ABOVE_48KHZ
+       SKP_int32       sDownPre[ 2 ];
+       SKP_int32       sUpPost[ 2 ];
+       void            (*down_pre_function)( SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 );
+       void            (*up_post_function)(  SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 );
+       SKP_int32       batchSizePrePost;
+       SKP_int32       ratio_Q16;
+       SKP_int32       nPreDownsamplers;
+       SKP_int32       nPostUpsamplers;
+#endif
+       SKP_int32 magic_number;
+} SKP_Silk_resampler_state_struct;
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* SKP_Silk_RESAMPLER_STRUCTS_H */
+
index 718b2740d05dea5047828d515824a274dd2363f3..1e0fa38c83f1f067048ffb05719643dfbe3a5408 100644 (file)
@@ -1,75 +1,75 @@
-/***********************************************************************\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_resampler_up2.c                                           *\r
- *                                                                      *\r
- * Upsample by a factor 2, low quality                                  *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- *                                                                      */\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_resampler_rom.h"\r
-\r
-/* Upsample by a factor 2, low quality */\r
-void SKP_Silk_resampler_up2(\r
-    SKP_int32                           *S,         /* I/O: State vector [ 2 ]                  */\r
-    SKP_int16                           *out,       /* O:   Output signal [ 2 * len ]           */\r
-    const SKP_int16                     *in,        /* I:   Input signal [ len ]                */\r
-    SKP_int32                           len         /* I:   Number of input samples             */\r
-)\r
-{\r
-    SKP_int32 k;\r
-    SKP_int32 in32, out32, Y, X;\r
-\r
-    SKP_assert( SKP_Silk_resampler_up2_lq_0 > 0 );\r
-    SKP_assert( SKP_Silk_resampler_up2_lq_1 < 0 );\r
-    /* Internal variables and state are in Q10 format */\r
-    for( k = 0; k < len; k++ ) {\r
-        /* Convert to Q10 */\r
-        in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 );\r
-\r
-        /* All-pass section for even output sample */\r
-        Y      = SKP_SUB32( in32, S[ 0 ] );\r
-        X      = SKP_SMULWB( Y, SKP_Silk_resampler_up2_lq_0 );\r
-        out32  = SKP_ADD32( S[ 0 ], X );\r
-        S[ 0 ] = SKP_ADD32( in32, X );\r
-\r
-        /* Convert back to int16 and store to output */\r
-        out[ 2 * k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );\r
-\r
-        /* All-pass section for odd output sample */\r
-        Y      = SKP_SUB32( in32, S[ 1 ] );\r
-        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_lq_1 );\r
-        out32  = SKP_ADD32( S[ 1 ], X );\r
-        S[ 1 ] = SKP_ADD32( in32, X );\r
-\r
-        /* Convert back to int16 and store to output */\r
-        out[ 2 * k + 1 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_resampler_up2.c                                           *
+ *                                                                      *
+ * Upsample by a factor 2, low quality                                  *
+ *                                                                      *
+ * Copyright 2010 (c), Skype Limited                                    *
+ *                                                                      */
+
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_resampler_rom.h"
+
+/* Upsample by a factor 2, low quality */
+void SKP_Silk_resampler_up2(
+    SKP_int32                           *S,         /* I/O: State vector [ 2 ]                  */
+    SKP_int16                           *out,       /* O:   Output signal [ 2 * len ]           */
+    const SKP_int16                     *in,        /* I:   Input signal [ len ]                */
+    SKP_int32                           len         /* I:   Number of input samples             */
+)
+{
+    SKP_int32 k;
+    SKP_int32 in32, out32, Y, X;
+
+    SKP_assert( SKP_Silk_resampler_up2_lq_0 > 0 );
+    SKP_assert( SKP_Silk_resampler_up2_lq_1 < 0 );
+    /* Internal variables and state are in Q10 format */
+    for( k = 0; k < len; k++ ) {
+        /* Convert to Q10 */
+        in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 );
+
+        /* All-pass section for even output sample */
+        Y      = SKP_SUB32( in32, S[ 0 ] );
+        X      = SKP_SMULWB( Y, SKP_Silk_resampler_up2_lq_0 );
+        out32  = SKP_ADD32( S[ 0 ], X );
+        S[ 0 ] = SKP_ADD32( in32, X );
+
+        /* Convert back to int16 and store to output */
+        out[ 2 * k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );
+
+        /* All-pass section for odd output sample */
+        Y      = SKP_SUB32( in32, S[ 1 ] );
+        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_lq_1 );
+        out32  = SKP_ADD32( S[ 1 ], X );
+        S[ 1 ] = SKP_ADD32( in32, X );
+
+        /* Convert back to int16 and store to output */
+        out[ 2 * k + 1 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );
+    }
+}
index b559ce61ab5b38e1966494f5e8f1724b46e1eff0..a3c83978dee145b9a8d0adf4d5e5c6eb9d3ae8cf 100644 (file)
@@ -1,99 +1,99 @@
-/***********************************************************************\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_FIX.h"\r
-\r
-/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */\r
-SKP_int32 SKP_Silk_residual_energy16_covar_FIX(\r
-    const SKP_int16                 *c,                 /* I    Prediction vector                           */\r
-    const SKP_int32                 *wXX,               /* I    Correlation matrix                          */\r
-    const SKP_int32                 *wXx,               /* I    Correlation vector                          */\r
-    SKP_int32                       wxx,                /* I    Signal energy                               */\r
-    SKP_int                         D,                  /* I    Dimension                                   */\r
-    SKP_int                         cQ                  /* I    Q value for c vector 0 - 15                 */\r
-)\r
-{\r
-    SKP_int   i, j, lshifts, Qxtra;\r
-    SKP_int32 c_max, w_max, tmp, tmp2, nrg;\r
-    SKP_int   cn[ MAX_MATRIX_SIZE ]; \r
-    const SKP_int32 *pRow;\r
-\r
-    /* Safety checks */\r
-    SKP_assert( D >=  0 );\r
-    SKP_assert( D <= 16 );\r
-    SKP_assert( cQ >  0 );\r
-    SKP_assert( cQ < 16 );\r
-\r
-    lshifts = 16 - cQ;\r
-    Qxtra = lshifts;\r
-\r
-    c_max = 0;\r
-    for( i = 0; i < D; i++ ) {\r
-        c_max = SKP_max_32( c_max, SKP_abs( ( SKP_int32 )c[ i ] ) );\r
-    }\r
-    Qxtra = SKP_min_int( Qxtra, SKP_Silk_CLZ32( c_max ) - 17 );\r
-\r
-    w_max = SKP_max_32( wXX[ 0 ], wXX[ D * D - 1 ] );\r
-    Qxtra = SKP_min_int( Qxtra, SKP_Silk_CLZ32( SKP_MUL( D, SKP_RSHIFT( SKP_SMULWB( w_max, c_max ), 4 ) ) ) - 5 );\r
-    Qxtra = SKP_max_int( Qxtra, 0 );\r
-    for( i = 0; i < D; i++ ) {\r
-        cn[ i ] = SKP_LSHIFT( ( SKP_int )c[ i ], Qxtra );\r
-        SKP_assert( SKP_abs(cn[i]) <= ( SKP_int16_MAX + 1 ) ); /* Check that SKP_SMLAWB can be used */\r
-    }\r
-    lshifts -= Qxtra;\r
-\r
-    /* Compute wxx - 2 * wXx * c */\r
-    tmp = 0;\r
-    for( i = 0; i < D; i++ ) {\r
-        tmp = SKP_SMLAWB( tmp, wXx[ i ], cn[ i ] );\r
-    }\r
-    nrg = SKP_RSHIFT( wxx, 1 + lshifts ) - tmp;                         /* Q: -lshifts - 1 */\r
-\r
-    /* Add c' * wXX * c, assuming wXX is symmetric */\r
-    tmp2 = 0;\r
-    for( i = 0; i < D; i++ ) {\r
-        tmp = 0;\r
-        pRow = &wXX[ i * D ];\r
-        for( j = i + 1; j < D; j++ ) {\r
-            tmp = SKP_SMLAWB( tmp, pRow[ j ], cn[ j ] );\r
-        }\r
-        tmp  = SKP_SMLAWB( tmp,  SKP_RSHIFT( pRow[ i ], 1 ), cn[ i ] );\r
-        tmp2 = SKP_SMLAWB( tmp2, tmp,                        cn[ i ] );\r
-    }\r
-    nrg = SKP_ADD_LSHIFT32( nrg, tmp2, lshifts );                       /* Q: -lshifts - 1 */\r
-\r
-    /* Keep one bit free always, because we add them for LSF interpolation */\r
-    if( nrg < 1 ) {\r
-        nrg = 1;\r
-    } else if( nrg > SKP_RSHIFT( SKP_int32_MAX, lshifts + 2 ) ) {\r
-        nrg = SKP_int32_MAX >> 1;\r
-    } else {\r
-        nrg = SKP_LSHIFT( nrg, lshifts + 1 );                           /* Q0 */\r
-    }\r
-    return nrg;\r
-\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
+SKP_int32 SKP_Silk_residual_energy16_covar_FIX(
+    const SKP_int16                 *c,                 /* I    Prediction vector                           */
+    const SKP_int32                 *wXX,               /* I    Correlation matrix                          */
+    const SKP_int32                 *wXx,               /* I    Correlation vector                          */
+    SKP_int32                       wxx,                /* I    Signal energy                               */
+    SKP_int                         D,                  /* I    Dimension                                   */
+    SKP_int                         cQ                  /* I    Q value for c vector 0 - 15                 */
+)
+{
+    SKP_int   i, j, lshifts, Qxtra;
+    SKP_int32 c_max, w_max, tmp, tmp2, nrg;
+    SKP_int   cn[ MAX_MATRIX_SIZE ]; 
+    const SKP_int32 *pRow;
+
+    /* Safety checks */
+    SKP_assert( D >=  0 );
+    SKP_assert( D <= 16 );
+    SKP_assert( cQ >  0 );
+    SKP_assert( cQ < 16 );
+
+    lshifts = 16 - cQ;
+    Qxtra = lshifts;
+
+    c_max = 0;
+    for( i = 0; i < D; i++ ) {
+        c_max = SKP_max_32( c_max, SKP_abs( ( SKP_int32 )c[ i ] ) );
+    }
+    Qxtra = SKP_min_int( Qxtra, SKP_Silk_CLZ32( c_max ) - 17 );
+
+    w_max = SKP_max_32( wXX[ 0 ], wXX[ D * D - 1 ] );
+    Qxtra = SKP_min_int( Qxtra, SKP_Silk_CLZ32( SKP_MUL( D, SKP_RSHIFT( SKP_SMULWB( w_max, c_max ), 4 ) ) ) - 5 );
+    Qxtra = SKP_max_int( Qxtra, 0 );
+    for( i = 0; i < D; i++ ) {
+        cn[ i ] = SKP_LSHIFT( ( SKP_int )c[ i ], Qxtra );
+        SKP_assert( SKP_abs(cn[i]) <= ( SKP_int16_MAX + 1 ) ); /* Check that SKP_SMLAWB can be used */
+    }
+    lshifts -= Qxtra;
+
+    /* Compute wxx - 2 * wXx * c */
+    tmp = 0;
+    for( i = 0; i < D; i++ ) {
+        tmp = SKP_SMLAWB( tmp, wXx[ i ], cn[ i ] );
+    }
+    nrg = SKP_RSHIFT( wxx, 1 + lshifts ) - tmp;                         /* Q: -lshifts - 1 */
+
+    /* Add c' * wXX * c, assuming wXX is symmetric */
+    tmp2 = 0;
+    for( i = 0; i < D; i++ ) {
+        tmp = 0;
+        pRow = &wXX[ i * D ];
+        for( j = i + 1; j < D; j++ ) {
+            tmp = SKP_SMLAWB( tmp, pRow[ j ], cn[ j ] );
+        }
+        tmp  = SKP_SMLAWB( tmp,  SKP_RSHIFT( pRow[ i ], 1 ), cn[ i ] );
+        tmp2 = SKP_SMLAWB( tmp2, tmp,                        cn[ i ] );
+    }
+    nrg = SKP_ADD_LSHIFT32( nrg, tmp2, lshifts );                       /* Q: -lshifts - 1 */
+
+    /* Keep one bit free always, because we add them for LSF interpolation */
+    if( nrg < 1 ) {
+        nrg = 1;
+    } else if( nrg > SKP_RSHIFT( SKP_int32_MAX, lshifts + 2 ) ) {
+        nrg = SKP_int32_MAX >> 1;
+    } else {
+        nrg = SKP_LSHIFT( nrg, lshifts + 1 );                           /* Q0 */
+    }
+    return nrg;
+
+}
index 19921ef0d8480b04c9822fd732a9da600345a2ae..b6b1ce6ce78a7b4009d2499d7a76b09c63e5e30d 100644 (file)
@@ -1,88 +1,88 @@
-/***********************************************************************\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_FIX.h"\r
-\r
-/* Calculates residual energies of input subframes where all subframes have LPC_order   */\r
-/* of preceeding samples                                                                */\r
-void SKP_Silk_residual_energy_FIX(\r
-          SKP_int32 nrgs[ NB_SUBFR ],           /* O    Residual energy per subframe    */\r
-          SKP_int   nrgsQ[ NB_SUBFR ],          /* O    Q value per subframe            */\r
-    const SKP_int16 x[],                        /* I    Input signal                    */\r
-          SKP_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ],/* I    AR coefs for each frame half    */\r
-    const SKP_int32 gains[ NB_SUBFR ],          /* I    Quantization gains              */\r
-    const SKP_int   subfr_length,               /* I    Subframe length                 */\r
-    const SKP_int   LPC_order                   /* I    LPC order                       */\r
-)\r
-{\r
-    SKP_int         offset, i, j, rshift, lz1, lz2;\r
-    SKP_int16       *LPC_res_ptr, LPC_res[ ( MAX_FRAME_LENGTH + NB_SUBFR * MAX_LPC_ORDER ) / 2 ];\r
-    const SKP_int16 *x_ptr;\r
-    SKP_int16       S[ MAX_LPC_ORDER ];\r
-    SKP_int32       tmp32;\r
-\r
-    x_ptr  = x;\r
-    offset = LPC_order + subfr_length;\r
-    \r
-    /* Filter input to create the LPC residual for each frame half, and measure subframe energies */\r
-    for( i = 0; i < 2; i++ ) {\r
-        /* Calculate half frame LPC residual signal including preceeding samples */\r
-        SKP_memset( S, 0, LPC_order * sizeof( SKP_int16 ) );\r
-        SKP_Silk_LPC_analysis_filter( x_ptr, a_Q12[ i ], S, LPC_res, ( NB_SUBFR >> 1 ) * offset, LPC_order );\r
-\r
-        /* Point to first subframe of the just calculated LPC residual signal */\r
-        LPC_res_ptr = LPC_res + LPC_order;\r
-        for( j = 0; j < ( NB_SUBFR >> 1 ); j++ ) {\r
-            /* Measure subframe energy */\r
-            SKP_Silk_sum_sqr_shift( &nrgs[ i * ( NB_SUBFR >> 1 ) + j ], &rshift, LPC_res_ptr, subfr_length ); \r
-            \r
-            /* Set Q values for the measured energy */\r
-            nrgsQ[ i * ( NB_SUBFR >> 1 ) + j ] = -rshift;\r
-            \r
-            /* Move to next subframe */\r
-            LPC_res_ptr += offset;\r
-        }\r
-        /* Move to next frame half */\r
-        x_ptr += ( NB_SUBFR >> 1 ) * offset;\r
-    }\r
-\r
-    /* Apply the squared subframe gains */\r
-    for( i = 0; i < NB_SUBFR; i++ ) {\r
-        /* Fully upscale gains and energies */\r
-        lz1 = SKP_Silk_CLZ32( nrgs[  i ] ) - 1; \r
-        lz2 = SKP_Silk_CLZ32( gains[ i ] ) - 1; \r
-        \r
-        tmp32 = SKP_LSHIFT32( gains[ i ], lz2 );\r
-\r
-        /* Find squared gains */\r
-        tmp32 = SKP_SMMUL( tmp32, tmp32 ); // Q( 2 * lz2 - 32 )\r
-\r
-        /* Scale energies */\r
-        nrgs[ i ] = SKP_SMMUL( tmp32, SKP_LSHIFT32( nrgs[ i ], lz1 ) ); // Q( nrgsQ[ i ] + lz1 + 2 * lz2 - 32 - 32 )\r
-        nrgsQ[ i ] += lz1 + 2 * lz2 - 32 - 32;\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+/* Calculates residual energies of input subframes where all subframes have LPC_order   */
+/* of preceeding samples                                                                */
+void SKP_Silk_residual_energy_FIX(
+          SKP_int32 nrgs[ NB_SUBFR ],           /* O    Residual energy per subframe    */
+          SKP_int   nrgsQ[ NB_SUBFR ],          /* O    Q value per subframe            */
+    const SKP_int16 x[],                        /* I    Input signal                    */
+          SKP_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ],/* I    AR coefs for each frame half    */
+    const SKP_int32 gains[ NB_SUBFR ],          /* I    Quantization gains              */
+    const SKP_int   subfr_length,               /* I    Subframe length                 */
+    const SKP_int   LPC_order                   /* I    LPC order                       */
+)
+{
+    SKP_int         offset, i, j, rshift, lz1, lz2;
+    SKP_int16       *LPC_res_ptr, LPC_res[ ( MAX_FRAME_LENGTH + NB_SUBFR * MAX_LPC_ORDER ) / 2 ];
+    const SKP_int16 *x_ptr;
+    SKP_int16       S[ MAX_LPC_ORDER ];
+    SKP_int32       tmp32;
+
+    x_ptr  = x;
+    offset = LPC_order + subfr_length;
+    
+    /* Filter input to create the LPC residual for each frame half, and measure subframe energies */
+    for( i = 0; i < 2; i++ ) {
+        /* Calculate half frame LPC residual signal including preceeding samples */
+        SKP_memset( S, 0, LPC_order * sizeof( SKP_int16 ) );
+        SKP_Silk_LPC_analysis_filter( x_ptr, a_Q12[ i ], S, LPC_res, ( NB_SUBFR >> 1 ) * offset, LPC_order );
+
+        /* Point to first subframe of the just calculated LPC residual signal */
+        LPC_res_ptr = LPC_res + LPC_order;
+        for( j = 0; j < ( NB_SUBFR >> 1 ); j++ ) {
+            /* Measure subframe energy */
+            SKP_Silk_sum_sqr_shift( &nrgs[ i * ( NB_SUBFR >> 1 ) + j ], &rshift, LPC_res_ptr, subfr_length ); 
+            
+            /* Set Q values for the measured energy */
+            nrgsQ[ i * ( NB_SUBFR >> 1 ) + j ] = -rshift;
+            
+            /* Move to next subframe */
+            LPC_res_ptr += offset;
+        }
+        /* Move to next frame half */
+        x_ptr += ( NB_SUBFR >> 1 ) * offset;
+    }
+
+    /* Apply the squared subframe gains */
+    for( i = 0; i < NB_SUBFR; i++ ) {
+        /* Fully upscale gains and energies */
+        lz1 = SKP_Silk_CLZ32( nrgs[  i ] ) - 1; 
+        lz2 = SKP_Silk_CLZ32( gains[ i ] ) - 1; 
+        
+        tmp32 = SKP_LSHIFT32( gains[ i ], lz2 );
+
+        /* Find squared gains */
+        tmp32 = SKP_SMMUL( tmp32, tmp32 ); // Q( 2 * lz2 - 32 )
+
+        /* Scale energies */
+        nrgs[ i ] = SKP_SMMUL( tmp32, SKP_LSHIFT32( nrgs[ i ], lz1 ) ); // Q( nrgsQ[ i ] + lz1 + 2 * lz2 - 32 - 32 )
+        nrgsQ[ i ] += lz1 + 2 * lz2 - 32 - 32;
+    }
+}
index 2fa4bf6218b12e155e3e4602dd62e7d2b2c15ed0..37d4facb3e10d0e73838c17a31b09c2b2b03a229 100644 (file)
@@ -1,45 +1,45 @@
-/***********************************************************************\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_SigProc_FIX.h"\r
-\r
-/* Copy and multiply a vector by a constant */\r
-void SKP_Silk_scale_copy_vector16( \r
-    SKP_int16           *data_out, \r
-    const SKP_int16     *data_in, \r
-    SKP_int32           gain_Q16,                   /* (I):   gain in Q16   */\r
-    const SKP_int       dataSize                    /* (I):   length        */\r
-)\r
-{\r
-    SKP_int  i;\r
-    SKP_int32 tmp32;\r
-\r
-    for( i = 0; i < dataSize; i++ ) {\r
-        tmp32 = SKP_SMULWB( gain_Q16, data_in[ i ] );\r
-        data_out[ i ] = (SKP_int16)SKP_CHECK_FIT16( tmp32 );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Copy and multiply a vector by a constant */
+void SKP_Silk_scale_copy_vector16( 
+    SKP_int16           *data_out, 
+    const SKP_int16     *data_in, 
+    SKP_int32           gain_Q16,                   /* (I):   gain in Q16   */
+    const SKP_int       dataSize                    /* (I):   length        */
+)
+{
+    SKP_int  i;
+    SKP_int32 tmp32;
+
+    for( i = 0; i < dataSize; i++ ) {
+        tmp32 = SKP_SMULWB( gain_Q16, data_in[ i ] );
+        data_out[ i ] = (SKP_int16)SKP_CHECK_FIT16( tmp32 );
+    }
+}
index f596a441471b3d3a71eb00c3595cada9822ca151..acfc55a0459a2a51c656afd122976663a1670d4e 100644 (file)
@@ -1,43 +1,43 @@
-/***********************************************************************\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_SigProc_FIX.h"\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
-    SKP_int             dataSize                    /* (I):   length        */\r
-)\r
-{\r
-    SKP_int  i;\r
-\r
-    for( i = 0; i < dataSize; i++ ) {\r
-        data1[ i ] = (SKP_int32)SKP_CHECK_FIT32( SKP_RSHIFT64( SKP_SMULL( data1[ i ], gain_Q26 ), 8 ) );// OUTPUT: Q18\r
-    }\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Multiply a vector by a constant */
+void SKP_Silk_scale_vector32_Q26_lshift_18( 
+    SKP_int32           *data1,                     /* (I/O): Q0/Q18        */
+    SKP_int32           gain_Q26,                   /* (I):   Q26           */
+    SKP_int             dataSize                    /* (I):   length        */
+)
+{
+    SKP_int  i;
+
+    for( i = 0; i < dataSize; i++ ) {
+        data1[ i ] = (SKP_int32)SKP_CHECK_FIT32( SKP_RSHIFT64( SKP_SMULL( data1[ i ], gain_Q26 ), 8 ) );// OUTPUT: Q18
+    }
+}
+
index 5fced358359a99d84573b6d6981fb40fe814e35b..4b6384f91559e04460177ed3b083350d7dcd2157 100644 (file)
@@ -1,94 +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
-/*                                                                      *\r
- * SKP_Silk_schur.c                                                   *\r
- *                                                                      *\r
- * Calculates the reflection coefficients from the correlation sequence *\r
- *                                                                      *\r
- * Copyright 2008 (c), Skype Limited                                    *\r
- * Date: 080103                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Faster than schur64(), but much less accurate.                       */\r
-/* uses SMLAWB(), requiring armv5E and higher.                          */ \r
-SKP_int32 SKP_Silk_schur(                     /* O:    Returns residual energy                     */\r
-    SKP_int16            *rc_Q15,               /* O:    reflection coefficients [order] Q15         */\r
-    const SKP_int32      *c,                    /* I:    correlations [order+1]                      */\r
-    const SKP_int32      order                  /* I:    prediction order                            */\r
-)\r
-{\r
-    SKP_int        k, n, lz;\r
-    SKP_int32    C[ SKP_Silk_MAX_ORDER_LPC + 1 ][ 2 ];\r
-    SKP_int32    Ctmp1, Ctmp2, rc_tmp_Q15;\r
-\r
-    /* Get number of leading zeros */\r
-    lz = SKP_Silk_CLZ32( c[ 0 ] );\r
-\r
-    /* Copy correlations and adjust level to Q30 */\r
-    if( lz < 2 ) {\r
-        /* lz must be 1, so shift one to the right */\r
-        for( k = 0; k < order + 1; k++ ) {\r
-            C[ k ][ 0 ] = C[ k ][ 1 ] = SKP_RSHIFT( c[ k ], 1 );\r
-        }\r
-    } else if( lz > 2 ) {\r
-        /* Shift to the left */\r
-        lz -= 2; \r
-        for( k = 0; k < order + 1; k++ ) {\r
-            C[ k ][ 0 ] = C[ k ][ 1 ] = SKP_LSHIFT( c[k], lz );\r
-        }\r
-    } else {\r
-        /* No need to shift */\r
-        for( k = 0; k < order + 1; k++ ) {\r
-            C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ];\r
-        }\r
-    }\r
-\r
-    for( k = 0; k < order; k++ ) {\r
-        \r
-        /* Get reflection coefficient */\r
-        rc_tmp_Q15 = -SKP_DIV32_16( C[ k + 1 ][ 0 ], SKP_max_32( SKP_RSHIFT( C[ 0 ][ 1 ], 15 ), 1 ) );\r
-\r
-        /* Clip (shouldn't happen for properly conditioned inputs) */\r
-        rc_tmp_Q15 = SKP_SAT16( rc_tmp_Q15 );\r
-\r
-        /* Store */\r
-        rc_Q15[ k ] = (SKP_int16)rc_tmp_Q15;\r
-\r
-        /* Update correlations */\r
-        for( n = 0; n < order - k; n++ ) {\r
-            Ctmp1 = C[ n + k + 1 ][ 0 ];\r
-            Ctmp2 = C[ n ][ 1 ];\r
-            C[ n + k + 1 ][ 0 ] = SKP_SMLAWB( Ctmp1, SKP_LSHIFT( Ctmp2, 1 ), rc_tmp_Q15 );\r
-            C[ n ][ 1 ]         = SKP_SMLAWB( Ctmp2, SKP_LSHIFT( Ctmp1, 1 ), rc_tmp_Q15 );\r
-        }\r
-    }\r
-\r
-    /* return residual energy */\r
-    return C[0][1];\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_schur.c                                                   *
+ *                                                                      *
+ * Calculates the reflection coefficients from the correlation sequence *
+ *                                                                      *
+ * Copyright 2008 (c), Skype Limited                                    *
+ * Date: 080103                                                         *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Faster than schur64(), but much less accurate.                       */
+/* uses SMLAWB(), requiring armv5E and higher.                          */ 
+SKP_int32 SKP_Silk_schur(                     /* O:    Returns residual energy                     */
+    SKP_int16            *rc_Q15,               /* O:    reflection coefficients [order] Q15         */
+    const SKP_int32      *c,                    /* I:    correlations [order+1]                      */
+    const SKP_int32      order                  /* I:    prediction order                            */
+)
+{
+    SKP_int        k, n, lz;
+    SKP_int32    C[ SKP_Silk_MAX_ORDER_LPC + 1 ][ 2 ];
+    SKP_int32    Ctmp1, Ctmp2, rc_tmp_Q15;
+
+    /* Get number of leading zeros */
+    lz = SKP_Silk_CLZ32( c[ 0 ] );
+
+    /* Copy correlations and adjust level to Q30 */
+    if( lz < 2 ) {
+        /* lz must be 1, so shift one to the right */
+        for( k = 0; k < order + 1; k++ ) {
+            C[ k ][ 0 ] = C[ k ][ 1 ] = SKP_RSHIFT( c[ k ], 1 );
+        }
+    } else if( lz > 2 ) {
+        /* Shift to the left */
+        lz -= 2; 
+        for( k = 0; k < order + 1; k++ ) {
+            C[ k ][ 0 ] = C[ k ][ 1 ] = SKP_LSHIFT( c[k], lz );
+        }
+    } else {
+        /* No need to shift */
+        for( k = 0; k < order + 1; k++ ) {
+            C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ];
+        }
+    }
+
+    for( k = 0; k < order; k++ ) {
+        
+        /* Get reflection coefficient */
+        rc_tmp_Q15 = -SKP_DIV32_16( C[ k + 1 ][ 0 ], SKP_max_32( SKP_RSHIFT( C[ 0 ][ 1 ], 15 ), 1 ) );
+
+        /* Clip (shouldn't happen for properly conditioned inputs) */
+        rc_tmp_Q15 = SKP_SAT16( rc_tmp_Q15 );
+
+        /* Store */
+        rc_Q15[ k ] = (SKP_int16)rc_tmp_Q15;
+
+        /* Update correlations */
+        for( n = 0; n < order - k; n++ ) {
+            Ctmp1 = C[ n + k + 1 ][ 0 ];
+            Ctmp2 = C[ n ][ 1 ];
+            C[ n + k + 1 ][ 0 ] = SKP_SMLAWB( Ctmp1, SKP_LSHIFT( Ctmp2, 1 ), rc_tmp_Q15 );
+            C[ n ][ 1 ]         = SKP_SMLAWB( Ctmp2, SKP_LSHIFT( Ctmp1, 1 ), rc_tmp_Q15 );
+        }
+    }
+
+    /* return residual energy */
+    return C[0][1];
+}
index bb869c0020cf4c335cfd383720bcf266acdcfe78..d74da765d8d145c547224843b2ffeb6de4ed2e83 100644 (file)
@@ -1,80 +1,80 @@
-/***********************************************************************\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_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            rc_Q16[],               /* O:    Reflection coefficients [order] Q16         */\r
-    const SKP_int32      c[],                    /* I:    Correlations [order+1]                      */\r
-    SKP_int32            order                   /* I:    Prediction order                            */\r
-)\r
-{\r
-    SKP_int   k, n;\r
-    SKP_int32 C[ SKP_Silk_MAX_ORDER_LPC + 1 ][ 2 ];\r
-    SKP_int32 Ctmp1_Q30, Ctmp2_Q30, rc_tmp_Q31;\r
-\r
-    /* Check for invalid input */\r
-    if( c[ 0 ] <= 0 ) {\r
-        SKP_memset( rc_Q16, 0, order * sizeof( SKP_int32 ) );\r
-        return 0;\r
-    }\r
-    \r
-    for( k = 0; k < order + 1; k++ ) {\r
-        C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ];\r
-    }\r
-\r
-    for( k = 0; k < order; k++ ) {\r
-        /* Get reflection coefficient: divide two Q30 values and get result in Q31 */\r
-        rc_tmp_Q31 = SKP_DIV32_varQ( -C[ k + 1 ][ 0 ], C[ 0 ][ 1 ], 31 );\r
-\r
-        /* Save the output */\r
-        rc_Q16[ k ] = SKP_RSHIFT_ROUND( rc_tmp_Q31, 15 );\r
-\r
-        /* Update correlations */\r
-        for( n = 0; n < order - k; n++ ) {\r
-            Ctmp1_Q30 = C[ n + k + 1 ][ 0 ];\r
-            Ctmp2_Q30 = C[ n ][ 1 ];\r
-            \r
-            /* Multiply and add the highest int32 */\r
-            C[ n + k + 1 ][ 0 ] = Ctmp1_Q30 + SKP_SMMUL( SKP_LSHIFT( Ctmp2_Q30, 1 ), rc_tmp_Q31 );\r
-            C[ n ][ 1 ]         = Ctmp2_Q30 + SKP_SMMUL( SKP_LSHIFT( Ctmp1_Q30, 1 ), rc_tmp_Q31 );\r
-        }\r
-    }\r
-\r
-    return C[ 0 ][ 1 ];\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_schur64.c                                                 *
+ *                                                                      *
+ * Calculates the reflection coefficients from the correlation sequence *
+ * using extra precision                                                *
+ *                                                                      *
+ * Copyright 2008 (c), Skype Limited                                    *
+ * Date: 080103                                                         *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Slower than schur(), but more accurate.                              */
+/* Uses SMULL(), available on armv4                                     */ 
+SKP_int32 SKP_Silk_schur64(                    /* O:    Returns residual energy                     */
+    SKP_int32            rc_Q16[],               /* O:    Reflection coefficients [order] Q16         */
+    const SKP_int32      c[],                    /* I:    Correlations [order+1]                      */
+    SKP_int32            order                   /* I:    Prediction order                            */
+)
+{
+    SKP_int   k, n;
+    SKP_int32 C[ SKP_Silk_MAX_ORDER_LPC + 1 ][ 2 ];
+    SKP_int32 Ctmp1_Q30, Ctmp2_Q30, rc_tmp_Q31;
+
+    /* Check for invalid input */
+    if( c[ 0 ] <= 0 ) {
+        SKP_memset( rc_Q16, 0, order * sizeof( SKP_int32 ) );
+        return 0;
+    }
+    
+    for( k = 0; k < order + 1; k++ ) {
+        C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ];
+    }
+
+    for( k = 0; k < order; k++ ) {
+        /* Get reflection coefficient: divide two Q30 values and get result in Q31 */
+        rc_tmp_Q31 = SKP_DIV32_varQ( -C[ k + 1 ][ 0 ], C[ 0 ][ 1 ], 31 );
+
+        /* Save the output */
+        rc_Q16[ k ] = SKP_RSHIFT_ROUND( rc_tmp_Q31, 15 );
+
+        /* Update correlations */
+        for( n = 0; n < order - k; n++ ) {
+            Ctmp1_Q30 = C[ n + k + 1 ][ 0 ];
+            Ctmp2_Q30 = C[ n ][ 1 ];
+            
+            /* Multiply and add the highest int32 */
+            C[ n + k + 1 ][ 0 ] = Ctmp1_Q30 + SKP_SMMUL( SKP_LSHIFT( Ctmp2_Q30, 1 ), rc_tmp_Q31 );
+            C[ n ][ 1 ]         = Ctmp2_Q30 + SKP_SMMUL( SKP_LSHIFT( Ctmp1_Q30, 1 ), rc_tmp_Q31 );
+        }
+    }
+
+    return C[ 0 ][ 1 ];
+}
index b6933ae5a32e818cb3e9ad663b65b280b5788c43..3477fd6f52051fc8226ce11b1c9ca8d8dca4a48e 100644 (file)
@@ -1,99 +1,99 @@
-/***********************************************************************\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  Pointer to Silk encoder state           */\r
-    SKP_int                         Complexity          /* I    Complexity (0->low; 1->medium; 2->high) */\r
-)\r
-{\r
-    SKP_int ret = SKP_SILK_NO_ERROR;\r
-\r
-    /* Check that settings are valid */\r
-    if( LOW_COMPLEXITY_ONLY && Complexity != 0 ) { \r
-        ret = SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING;\r
-    }\r
-\r
-    /* Set encoding complexity */\r
-    if( Complexity == 0 || LOW_COMPLEXITY_ONLY ) {\r
-        /* Low complexity */\r
-        psEncC->Complexity                      = 0;\r
-        psEncC->pitchEstimationComplexity       = PITCH_EST_COMPLEXITY_LC_MODE;\r
-        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( FIND_PITCH_CORRELATION_THRESHOLD_LC_MODE, 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             = MAX_NLSF_MSVQ_SURVIVORS_LC_MODE;\r
-        psEncC->warping_Q16                     = 0;\r
-    } else if( Complexity == 1 ) {\r
-        /* Medium complexity */\r
-        psEncC->Complexity                      = 1;\r
-        psEncC->pitchEstimationComplexity       = PITCH_EST_COMPLEXITY_MC_MODE;\r
-        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( FIND_PITCH_CORRELATION_THRESHOLD_MC_MODE, 16 );\r
-        psEncC->pitchEstimationLPCOrder         = 12;\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             = MAX_NLSF_MSVQ_SURVIVORS_MC_MODE;\r
-        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );\r
-    } else if( Complexity == 2 ) {\r
-        /* High complexity */\r
-        psEncC->Complexity                      = 2;\r
-        psEncC->pitchEstimationComplexity       = PITCH_EST_COMPLEXITY_HC_MODE;\r
-        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( FIND_PITCH_CORRELATION_THRESHOLD_HC_MODE, 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             = MAX_NLSF_MSVQ_SURVIVORS;\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                      = 5 * 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
-\r
-    return( ret );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+#include "SKP_Silk_tuning_parameters.h"
+
+SKP_INLINE SKP_int SKP_Silk_setup_complexity(
+    SKP_Silk_encoder_state          *psEncC,            /* I/O  Pointer to Silk encoder state           */
+    SKP_int                         Complexity          /* I    Complexity (0->low; 1->medium; 2->high) */
+)
+{
+    SKP_int ret = SKP_SILK_NO_ERROR;
+
+    /* Check that settings are valid */
+    if( LOW_COMPLEXITY_ONLY && Complexity != 0 ) { 
+        ret = SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING;
+    }
+
+    /* Set encoding complexity */
+    if( Complexity == 0 || LOW_COMPLEXITY_ONLY ) {
+        /* Low complexity */
+        psEncC->Complexity                      = 0;
+        psEncC->pitchEstimationComplexity       = PITCH_EST_COMPLEXITY_LC_MODE;
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( FIND_PITCH_CORRELATION_THRESHOLD_LC_MODE, 16 );
+        psEncC->pitchEstimationLPCOrder         = 6;
+        psEncC->shapingLPCOrder                 = 8;
+        psEncC->la_shape                        = 3 * psEncC->fs_kHz;
+        psEncC->nStatesDelayedDecision          = 1;
+        psEncC->useInterpolatedNLSFs            = 0;
+        psEncC->LTPQuantLowComplexity           = 1;
+        psEncC->NLSF_MSVQ_Survivors             = MAX_NLSF_MSVQ_SURVIVORS_LC_MODE;
+        psEncC->warping_Q16                     = 0;
+    } else if( Complexity == 1 ) {
+        /* Medium complexity */
+        psEncC->Complexity                      = 1;
+        psEncC->pitchEstimationComplexity       = PITCH_EST_COMPLEXITY_MC_MODE;
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( FIND_PITCH_CORRELATION_THRESHOLD_MC_MODE, 16 );
+        psEncC->pitchEstimationLPCOrder         = 12;
+        psEncC->shapingLPCOrder                 = 12;
+        psEncC->la_shape                        = 5 * psEncC->fs_kHz;
+        psEncC->nStatesDelayedDecision          = 2;
+        psEncC->useInterpolatedNLSFs            = 0;
+        psEncC->LTPQuantLowComplexity           = 0;
+        psEncC->NLSF_MSVQ_Survivors             = MAX_NLSF_MSVQ_SURVIVORS_MC_MODE;
+        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );
+    } else if( Complexity == 2 ) {
+        /* High complexity */
+        psEncC->Complexity                      = 2;
+        psEncC->pitchEstimationComplexity       = PITCH_EST_COMPLEXITY_HC_MODE;
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( FIND_PITCH_CORRELATION_THRESHOLD_HC_MODE, 16 );
+        psEncC->pitchEstimationLPCOrder         = 16;
+        psEncC->shapingLPCOrder                 = 16;
+        psEncC->la_shape                        = 5 * psEncC->fs_kHz;
+        psEncC->nStatesDelayedDecision          = MAX_DEL_DEC_STATES;
+        psEncC->useInterpolatedNLSFs            = 1;
+        psEncC->LTPQuantLowComplexity           = 0;
+        psEncC->NLSF_MSVQ_Survivors             = MAX_NLSF_MSVQ_SURVIVORS;
+        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );
+    } else {
+        ret = SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING;
+    }
+
+    /* Do not allow higher pitch estimation LPC order than predict LPC order */
+    psEncC->pitchEstimationLPCOrder             = SKP_min_int( psEncC->pitchEstimationLPCOrder, psEncC->predictLPCOrder );
+    psEncC->shapeWinLength                      = 5 * psEncC->fs_kHz + 2 * psEncC->la_shape;
+
+    SKP_assert( psEncC->pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER );
+    SKP_assert( psEncC->shapingLPCOrder         <= MAX_SHAPE_LPC_ORDER      );
+    SKP_assert( psEncC->nStatesDelayedDecision  <= MAX_DEL_DEC_STATES       );
+    SKP_assert( psEncC->warping_Q16             <= 32767                    );
+    SKP_assert( psEncC->la_shape                <= LA_SHAPE_MAX             );
+    SKP_assert( psEncC->shapeWinLength          <= SHAPE_LPC_WIN_MAX        );
+
+    return( ret );
+}
index f8bdf1ff34e277a3ae57b3e1a02a1c1a5dd55bab..230718c5a3def8cf67ed5f1da6b71b847a75e5fd 100644 (file)
-/***********************************************************************\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
-/* shell coder; pulse-subframe length is hardcoded */\r
-\r
-SKP_INLINE void combine_pulses(\r
-    SKP_int         *out,   /* O:   combined pulses vector [len] */\r
-    const SKP_int   *in,    /* I:   input vector       [2 * len] */\r
-    const SKP_int   len     /* I:   number of OUTPUT samples     */\r
-)\r
-{\r
-    SKP_int k;\r
-    for( k = 0; k < len; k++ ) {\r
-        out[ k ] = in[ 2 * k ] + in[ 2 * k + 1 ];\r
-    }\r
-}\r
-\r
-SKP_INLINE void encode_split(\r
-    SKP_Silk_range_coder_state  *sRC,           /* I/O: compressor data structure                   */\r
-    const SKP_int               p_child1,       /* I:   pulse amplitude of first child subframe     */\r
-    const SKP_int               p,              /* I:   pulse amplitude of current subframe         */\r
-    const SKP_uint16            *shell_table    /* I:   table of shell cdfs                         */\r
-)\r
-{\r
-    const SKP_uint16 *cdf;\r
-\r
-    if( p > 0 ) {\r
-        cdf = &shell_table[ SKP_Silk_shell_code_table_offsets[ p ] ];\r
-        SKP_Silk_range_encoder( sRC, p_child1, cdf );\r
-    }\r
-}\r
-\r
-SKP_INLINE void decode_split(\r
-    SKP_int                     *p_child1,      /* O:   pulse amplitude of first child subframe     */\r
-    SKP_int                     *p_child2,      /* O:   pulse amplitude of second child subframe    */\r
-    SKP_Silk_range_coder_state  *sRC,           /* I/O: compressor data structure                   */\r
-    const SKP_int               p,              /* I:   pulse amplitude of current subframe         */\r
-    const SKP_uint16            *shell_table    /* I:   table of shell cdfs                         */\r
-)\r
-{\r
-    SKP_int cdf_middle;\r
-    const SKP_uint16 *cdf;\r
-\r
-    if( p > 0 ) {\r
-        cdf_middle = SKP_RSHIFT( p, 1 );\r
-        cdf = &shell_table[ SKP_Silk_shell_code_table_offsets[ p ] ];\r
-        SKP_Silk_range_decoder( p_child1, sRC, cdf, cdf_middle );\r
-        p_child2[ 0 ] = p - p_child1[ 0 ];\r
-    } else {\r
-        p_child1[ 0 ] = 0;\r
-        p_child2[ 0 ] = 0;\r
-    }\r
-}\r
-\r
-/* Shell encoder, operates on one shell code frame of 16 pulses */\r
-void SKP_Silk_shell_encoder(\r
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  compressor data structure                   */\r
-    const SKP_int                   *pulses0            /* I    data: nonnegative pulse amplitudes          */\r
-)\r
-{\r
-    SKP_int pulses1[ 8 ], pulses2[ 4 ], pulses3[ 2 ], pulses4[ 1 ];\r
-\r
-    /* this function operates on one shell code frame of 16 pulses */\r
-    SKP_assert( SHELL_CODEC_FRAME_LENGTH == 16 );\r
-\r
-    /* tree representation per pulse-subframe */\r
-    combine_pulses( pulses1, pulses0, 8 );\r
-    combine_pulses( pulses2, pulses1, 4 );\r
-    combine_pulses( pulses3, pulses2, 2 );\r
-    combine_pulses( pulses4, pulses3, 1 );\r
-\r
-    encode_split( sRC, pulses3[  0 ], pulses4[ 0 ], SKP_Silk_shell_code_table3 );\r
-\r
-    encode_split( sRC, pulses2[  0 ], pulses3[ 0 ], SKP_Silk_shell_code_table2 );\r
-\r
-    encode_split( sRC, pulses1[  0 ], pulses2[ 0 ], SKP_Silk_shell_code_table1 );\r
-    encode_split( sRC, pulses0[  0 ], pulses1[ 0 ], SKP_Silk_shell_code_table0 );\r
-    encode_split( sRC, pulses0[  2 ], pulses1[ 1 ], SKP_Silk_shell_code_table0 );\r
-\r
-    encode_split( sRC, pulses1[  2 ], pulses2[ 1 ], SKP_Silk_shell_code_table1 );\r
-    encode_split( sRC, pulses0[  4 ], pulses1[ 2 ], SKP_Silk_shell_code_table0 );\r
-    encode_split( sRC, pulses0[  6 ], pulses1[ 3 ], SKP_Silk_shell_code_table0 );\r
-\r
-    encode_split( sRC, pulses2[  2 ], pulses3[ 1 ], SKP_Silk_shell_code_table2 );\r
-\r
-    encode_split( sRC, pulses1[  4 ], pulses2[ 2 ], SKP_Silk_shell_code_table1 );\r
-    encode_split( sRC, pulses0[  8 ], pulses1[ 4 ], SKP_Silk_shell_code_table0 );\r
-    encode_split( sRC, pulses0[ 10 ], pulses1[ 5 ], SKP_Silk_shell_code_table0 );\r
-\r
-    encode_split( sRC, pulses1[  6 ], pulses2[ 3 ], SKP_Silk_shell_code_table1 );\r
-    encode_split( sRC, pulses0[ 12 ], pulses1[ 6 ], SKP_Silk_shell_code_table0 );\r
-    encode_split( sRC, pulses0[ 14 ], pulses1[ 7 ], SKP_Silk_shell_code_table0 );\r
-}\r
-\r
-\r
-/* Shell decoder, operates on one shell code frame of 16 pulses */\r
-void SKP_Silk_shell_decoder(\r
-    SKP_int                         *pulses0,           /* O    data: nonnegative pulse amplitudes          */\r
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  compressor data structure                   */\r
-    const SKP_int                   pulses4             /* I    number of pulses per pulse-subframe         */\r
-)\r
-{\r
-    SKP_int pulses3[ 2 ], pulses2[ 4 ], pulses1[ 8 ];\r
-\r
-    /* this function operates on one shell code frame of 16 pulses */\r
-    SKP_assert( SHELL_CODEC_FRAME_LENGTH == 16 );\r
-\r
-    decode_split( &pulses3[  0 ], &pulses3[  1 ], sRC, pulses4,      SKP_Silk_shell_code_table3 );\r
-\r
-    decode_split( &pulses2[  0 ], &pulses2[  1 ], sRC, pulses3[ 0 ], SKP_Silk_shell_code_table2 );\r
-\r
-    decode_split( &pulses1[  0 ], &pulses1[  1 ], sRC, pulses2[ 0 ], SKP_Silk_shell_code_table1 );\r
-    decode_split( &pulses0[  0 ], &pulses0[  1 ], sRC, pulses1[ 0 ], SKP_Silk_shell_code_table0 );\r
-    decode_split( &pulses0[  2 ], &pulses0[  3 ], sRC, pulses1[ 1 ], SKP_Silk_shell_code_table0 );\r
-\r
-    decode_split( &pulses1[  2 ], &pulses1[  3 ], sRC, pulses2[ 1 ], SKP_Silk_shell_code_table1 );\r
-    decode_split( &pulses0[  4 ], &pulses0[  5 ], sRC, pulses1[ 2 ], SKP_Silk_shell_code_table0 );\r
-    decode_split( &pulses0[  6 ], &pulses0[  7 ], sRC, pulses1[ 3 ], SKP_Silk_shell_code_table0 );\r
-\r
-    decode_split( &pulses2[  2 ], &pulses2[  3 ], sRC, pulses3[ 1 ], SKP_Silk_shell_code_table2 );\r
-\r
-    decode_split( &pulses1[  4 ], &pulses1[  5 ], sRC, pulses2[ 2 ], SKP_Silk_shell_code_table1 );\r
-    decode_split( &pulses0[  8 ], &pulses0[  9 ], sRC, pulses1[ 4 ], SKP_Silk_shell_code_table0 );\r
-    decode_split( &pulses0[ 10 ], &pulses0[ 11 ], sRC, pulses1[ 5 ], SKP_Silk_shell_code_table0 );\r
-\r
-    decode_split( &pulses1[  6 ], &pulses1[  7 ], sRC, pulses2[ 3 ], SKP_Silk_shell_code_table1 );\r
-    decode_split( &pulses0[ 12 ], &pulses0[ 13 ], sRC, pulses1[ 6 ], SKP_Silk_shell_code_table0 );\r
-    decode_split( &pulses0[ 14 ], &pulses0[ 15 ], sRC, pulses1[ 7 ], SKP_Silk_shell_code_table0 );\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* shell coder; pulse-subframe length is hardcoded */
+
+SKP_INLINE void combine_pulses(
+    SKP_int         *out,   /* O:   combined pulses vector [len] */
+    const SKP_int   *in,    /* I:   input vector       [2 * len] */
+    const SKP_int   len     /* I:   number of OUTPUT samples     */
+)
+{
+    SKP_int k;
+    for( k = 0; k < len; k++ ) {
+        out[ k ] = in[ 2 * k ] + in[ 2 * k + 1 ];
+    }
+}
+
+SKP_INLINE void encode_split(
+    SKP_Silk_range_coder_state  *sRC,           /* I/O: compressor data structure                   */
+    const SKP_int               p_child1,       /* I:   pulse amplitude of first child subframe     */
+    const SKP_int               p,              /* I:   pulse amplitude of current subframe         */
+    const SKP_uint16            *shell_table    /* I:   table of shell cdfs                         */
+)
+{
+    const SKP_uint16 *cdf;
+
+    if( p > 0 ) {
+        cdf = &shell_table[ SKP_Silk_shell_code_table_offsets[ p ] ];
+        SKP_Silk_range_encoder( sRC, p_child1, cdf );
+    }
+}
+
+SKP_INLINE void decode_split(
+    SKP_int                     *p_child1,      /* O:   pulse amplitude of first child subframe     */
+    SKP_int                     *p_child2,      /* O:   pulse amplitude of second child subframe    */
+    SKP_Silk_range_coder_state  *sRC,           /* I/O: compressor data structure                   */
+    const SKP_int               p,              /* I:   pulse amplitude of current subframe         */
+    const SKP_uint16            *shell_table    /* I:   table of shell cdfs                         */
+)
+{
+    SKP_int cdf_middle;
+    const SKP_uint16 *cdf;
+
+    if( p > 0 ) {
+        cdf_middle = SKP_RSHIFT( p, 1 );
+        cdf = &shell_table[ SKP_Silk_shell_code_table_offsets[ p ] ];
+        SKP_Silk_range_decoder( p_child1, sRC, cdf, cdf_middle );
+        p_child2[ 0 ] = p - p_child1[ 0 ];
+    } else {
+        p_child1[ 0 ] = 0;
+        p_child2[ 0 ] = 0;
+    }
+}
+
+/* Shell encoder, operates on one shell code frame of 16 pulses */
+void SKP_Silk_shell_encoder(
+    SKP_Silk_range_coder_state      *sRC,               /* I/O  compressor data structure                   */
+    const SKP_int                   *pulses0            /* I    data: nonnegative pulse amplitudes          */
+)
+{
+    SKP_int pulses1[ 8 ], pulses2[ 4 ], pulses3[ 2 ], pulses4[ 1 ];
+
+    /* this function operates on one shell code frame of 16 pulses */
+    SKP_assert( SHELL_CODEC_FRAME_LENGTH == 16 );
+
+    /* tree representation per pulse-subframe */
+    combine_pulses( pulses1, pulses0, 8 );
+    combine_pulses( pulses2, pulses1, 4 );
+    combine_pulses( pulses3, pulses2, 2 );
+    combine_pulses( pulses4, pulses3, 1 );
+
+    encode_split( sRC, pulses3[  0 ], pulses4[ 0 ], SKP_Silk_shell_code_table3 );
+
+    encode_split( sRC, pulses2[  0 ], pulses3[ 0 ], SKP_Silk_shell_code_table2 );
+
+    encode_split( sRC, pulses1[  0 ], pulses2[ 0 ], SKP_Silk_shell_code_table1 );
+    encode_split( sRC, pulses0[  0 ], pulses1[ 0 ], SKP_Silk_shell_code_table0 );
+    encode_split( sRC, pulses0[  2 ], pulses1[ 1 ], SKP_Silk_shell_code_table0 );
+
+    encode_split( sRC, pulses1[  2 ], pulses2[ 1 ], SKP_Silk_shell_code_table1 );
+    encode_split( sRC, pulses0[  4 ], pulses1[ 2 ], SKP_Silk_shell_code_table0 );
+    encode_split( sRC, pulses0[  6 ], pulses1[ 3 ], SKP_Silk_shell_code_table0 );
+
+    encode_split( sRC, pulses2[  2 ], pulses3[ 1 ], SKP_Silk_shell_code_table2 );
+
+    encode_split( sRC, pulses1[  4 ], pulses2[ 2 ], SKP_Silk_shell_code_table1 );
+    encode_split( sRC, pulses0[  8 ], pulses1[ 4 ], SKP_Silk_shell_code_table0 );
+    encode_split( sRC, pulses0[ 10 ], pulses1[ 5 ], SKP_Silk_shell_code_table0 );
+
+    encode_split( sRC, pulses1[  6 ], pulses2[ 3 ], SKP_Silk_shell_code_table1 );
+    encode_split( sRC, pulses0[ 12 ], pulses1[ 6 ], SKP_Silk_shell_code_table0 );
+    encode_split( sRC, pulses0[ 14 ], pulses1[ 7 ], SKP_Silk_shell_code_table0 );
+}
+
+
+/* Shell decoder, operates on one shell code frame of 16 pulses */
+void SKP_Silk_shell_decoder(
+    SKP_int                         *pulses0,           /* O    data: nonnegative pulse amplitudes          */
+    SKP_Silk_range_coder_state      *sRC,               /* I/O  compressor data structure                   */
+    const SKP_int                   pulses4             /* I    number of pulses per pulse-subframe         */
+)
+{
+    SKP_int pulses3[ 2 ], pulses2[ 4 ], pulses1[ 8 ];
+
+    /* this function operates on one shell code frame of 16 pulses */
+    SKP_assert( SHELL_CODEC_FRAME_LENGTH == 16 );
+
+    decode_split( &pulses3[  0 ], &pulses3[  1 ], sRC, pulses4,      SKP_Silk_shell_code_table3 );
+
+    decode_split( &pulses2[  0 ], &pulses2[  1 ], sRC, pulses3[ 0 ], SKP_Silk_shell_code_table2 );
+
+    decode_split( &pulses1[  0 ], &pulses1[  1 ], sRC, pulses2[ 0 ], SKP_Silk_shell_code_table1 );
+    decode_split( &pulses0[  0 ], &pulses0[  1 ], sRC, pulses1[ 0 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses0[  2 ], &pulses0[  3 ], sRC, pulses1[ 1 ], SKP_Silk_shell_code_table0 );
+
+    decode_split( &pulses1[  2 ], &pulses1[  3 ], sRC, pulses2[ 1 ], SKP_Silk_shell_code_table1 );
+    decode_split( &pulses0[  4 ], &pulses0[  5 ], sRC, pulses1[ 2 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses0[  6 ], &pulses0[  7 ], sRC, pulses1[ 3 ], SKP_Silk_shell_code_table0 );
+
+    decode_split( &pulses2[  2 ], &pulses2[  3 ], sRC, pulses3[ 1 ], SKP_Silk_shell_code_table2 );
+
+    decode_split( &pulses1[  4 ], &pulses1[  5 ], sRC, pulses2[ 2 ], SKP_Silk_shell_code_table1 );
+    decode_split( &pulses0[  8 ], &pulses0[  9 ], sRC, pulses1[ 4 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses0[ 10 ], &pulses0[ 11 ], sRC, pulses1[ 5 ], SKP_Silk_shell_code_table0 );
+
+    decode_split( &pulses1[  6 ], &pulses1[  7 ], sRC, pulses2[ 3 ], SKP_Silk_shell_code_table1 );
+    decode_split( &pulses0[ 12 ], &pulses0[ 13 ], sRC, pulses1[ 6 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses0[ 14 ], &pulses0[ 15 ], sRC, pulses1[ 7 ], SKP_Silk_shell_code_table0 );
+}
index 5b4168c16e09ae98769666dc7b17eae7673b201d..b42476e38e943b93bfe725f16f9a703cb02ae982 100644 (file)
@@ -1,78 +1,78 @@
-/***********************************************************************\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_sigm_Q15.c                                                       *\r
- *                                                                      *\r
- * Approximate sigmoid function                                         *\r
- *                                                                      *\r
- * Copyright 2006 (c), Skype Limited                                    *\r
- * Date: 060221                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-/********************************/\r
-/* approximate sigmoid function */\r
-/********************************/\r
-/* fprintf(1, '%d, ', round(1024 * ([1 ./ (1 + exp(-(1:5))), 1] - 1 ./ (1 + exp(-(0:5)))))); */\r
-static const SKP_int32 sigm_LUT_slope_Q10[ 6 ] = {\r
-    237, 153, 73, 30, 12, 7\r
-};\r
-/* fprintf(1, '%d, ', round(32767 * 1 ./ (1 + exp(-(0:5))))); */\r
-static const SKP_int32 sigm_LUT_pos_Q15[ 6 ] = {\r
-    16384, 23955, 28861, 31213, 32178, 32548\r
-};\r
-/* fprintf(1, '%d, ', round(32767 * 1 ./ (1 + exp((0:5))))); */\r
-static const SKP_int32 sigm_LUT_neg_Q15[ 6 ] = {\r
-    16384, 8812, 3906, 1554, 589, 219\r
-};\r
-\r
-SKP_int SKP_Silk_sigm_Q15( SKP_int in_Q5 ) \r
-{\r
-    SKP_int ind;\r
-\r
-    if( in_Q5 < 0 ) {\r
-        /* Negative input */\r
-        in_Q5 = -in_Q5;\r
-        if( in_Q5 >= 6 * 32 ) {\r
-            return 0;        /* Clip */\r
-        } else {\r
-            /* Linear interpolation of look up table */\r
-            ind = SKP_RSHIFT( in_Q5, 5 );\r
-            return( sigm_LUT_neg_Q15[ ind ] - SKP_SMULBB( sigm_LUT_slope_Q10[ ind ], in_Q5 & 0x1F ) );\r
-        }\r
-    } else {\r
-        /* Positive input */\r
-        if( in_Q5 >= 6 * 32 ) {\r
-            return 32767;        /* clip */\r
-        } else {\r
-            /* Linear interpolation of look up table */\r
-            ind = SKP_RSHIFT( in_Q5, 5 );\r
-            return( sigm_LUT_pos_Q15[ ind ] + SKP_SMULBB( sigm_LUT_slope_Q10[ ind ], in_Q5 & 0x1F ) );\r
-        }\r
-    }\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_sigm_Q15.c                                                       *
+ *                                                                      *
+ * Approximate sigmoid function                                         *
+ *                                                                      *
+ * Copyright 2006 (c), Skype Limited                                    *
+ * Date: 060221                                                         *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+/********************************/
+/* approximate sigmoid function */
+/********************************/
+/* fprintf(1, '%d, ', round(1024 * ([1 ./ (1 + exp(-(1:5))), 1] - 1 ./ (1 + exp(-(0:5)))))); */
+static const SKP_int32 sigm_LUT_slope_Q10[ 6 ] = {
+    237, 153, 73, 30, 12, 7
+};
+/* fprintf(1, '%d, ', round(32767 * 1 ./ (1 + exp(-(0:5))))); */
+static const SKP_int32 sigm_LUT_pos_Q15[ 6 ] = {
+    16384, 23955, 28861, 31213, 32178, 32548
+};
+/* fprintf(1, '%d, ', round(32767 * 1 ./ (1 + exp((0:5))))); */
+static const SKP_int32 sigm_LUT_neg_Q15[ 6 ] = {
+    16384, 8812, 3906, 1554, 589, 219
+};
+
+SKP_int SKP_Silk_sigm_Q15( SKP_int in_Q5 ) 
+{
+    SKP_int ind;
+
+    if( in_Q5 < 0 ) {
+        /* Negative input */
+        in_Q5 = -in_Q5;
+        if( in_Q5 >= 6 * 32 ) {
+            return 0;        /* Clip */
+        } else {
+            /* Linear interpolation of look up table */
+            ind = SKP_RSHIFT( in_Q5, 5 );
+            return( sigm_LUT_neg_Q15[ ind ] - SKP_SMULBB( sigm_LUT_slope_Q10[ ind ], in_Q5 & 0x1F ) );
+        }
+    } else {
+        /* Positive input */
+        if( in_Q5 >= 6 * 32 ) {
+            return 32767;        /* clip */
+        } else {
+            /* Linear interpolation of look up table */
+            ind = SKP_RSHIFT( in_Q5, 5 );
+            return( sigm_LUT_pos_Q15[ ind ] + SKP_SMULBB( sigm_LUT_slope_Q10[ ind ], in_Q5 & 0x1F ) );
+        }
+    }
+}
+
index 256841855e98678175777d4eef86a273814f8cc4..3374eccbadfcbf765903e5879e696e737c4aecea 100644 (file)
-/***********************************************************************\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_FIX.h"\r
-#include "SKP_Silk_tuning_parameters.h"\r
-\r
-/*****************************/\r
-/* Internal function headers */\r
-/*****************************/\r
-\r
-typedef struct {\r
-    SKP_int32 Q36_part;\r
-    SKP_int32 Q48_part;\r
-} inv_D_t;\r
-\r
-/* Factorize square matrix A into LDL form */\r
-SKP_INLINE void SKP_Silk_LDL_factorize_FIX(\r
-    SKP_int32           *A,         /* I/O Pointer to Symetric Square Matrix */\r
-    SKP_int             M,          /* I   Size of Matrix */\r
-    SKP_int32           *L_Q16,     /* I/O Pointer to Square Upper triangular Matrix */\r
-    inv_D_t             *inv_D      /* I/O Pointer to vector holding inverted diagonal elements of D */\r
-);\r
-\r
-/* Solve Lx = b, when L is lower triangular and has ones on the diagonal */\r
-SKP_INLINE void SKP_Silk_LS_SolveFirst_FIX(\r
-    const SKP_int32     *L_Q16,     /* I Pointer to Lower Triangular Matrix */\r
-    SKP_int             M,          /* I Dim of Matrix equation */\r
-    const SKP_int32     *b,         /* I b Vector */\r
-    SKP_int32           *x_Q16      /* O x Vector */  \r
-);\r
-\r
-/* Solve L^t*x = b, where L is lower triangular with ones on the diagonal */\r
-SKP_INLINE void SKP_Silk_LS_SolveLast_FIX(\r
-    const SKP_int32     *L_Q16,     /* I Pointer to Lower Triangular Matrix */\r
-    const SKP_int       M,          /* I Dim of Matrix equation */\r
-    const SKP_int32     *b,         /* I b Vector */\r
-    SKP_int32           *x_Q16      /* O x Vector */  \r
-);\r
-\r
-SKP_INLINE void SKP_Silk_LS_divide_Q16_FIX(\r
-    SKP_int32           T[],    /* I/O Numenator vector */\r
-    inv_D_t             *inv_D, /* I   1 / D vector     */\r
-    SKP_int             M       /* I   dimension        */\r
-);\r
-\r
-/* Solves Ax = b, assuming A is symmetric */\r
-void SKP_Silk_solve_LDL_FIX(\r
-    SKP_int32                       *A,                 /* I    Pointer to symetric square matrix A         */\r
-    SKP_int                         M,                  /* I    Size of matrix                              */\r
-    const SKP_int32                 *b,                 /* I    Pointer to b vector                         */\r
-    SKP_int32                       *x_Q16              /* O    Pointer to x solution vector                */\r
-)\r
-{\r
-    SKP_int32 L_Q16[  MAX_MATRIX_SIZE * MAX_MATRIX_SIZE ]; \r
-    SKP_int32 Y[      MAX_MATRIX_SIZE ];\r
-    inv_D_t   inv_D[  MAX_MATRIX_SIZE ];\r
-\r
-    SKP_assert( M <= MAX_MATRIX_SIZE );\r
-\r
-    /***************************************************\r
-    Factorize A by LDL such that A = L*D*L',\r
-    where L is lower triangular with ones on diagonal\r
-    ****************************************************/\r
-    SKP_Silk_LDL_factorize_FIX( A, M, L_Q16, inv_D );\r
-        \r
-    /****************************************************\r
-    * substitute D*L'*x = Y. ie:\r
-    L*D*L'*x = b => L*Y = b <=> Y = inv(L)*b\r
-    ******************************************************/\r
-    SKP_Silk_LS_SolveFirst_FIX( L_Q16, M, b, Y );\r
-\r
-    /****************************************************\r
-    D*L'*x = Y <=> L'*x = inv(D)*Y, because D is \r
-    diagonal just multiply with 1/d_i\r
-    ****************************************************/\r
-    SKP_Silk_LS_divide_Q16_FIX( Y, inv_D, M );\r
-\r
-    /****************************************************\r
-    x = inv(L') * inv(D) * Y\r
-    *****************************************************/\r
-    SKP_Silk_LS_SolveLast_FIX( L_Q16, M, Y, x_Q16 );\r
-}\r
-\r
-SKP_INLINE void SKP_Silk_LDL_factorize_FIX(\r
-    SKP_int32           *A,         /* I   Pointer to Symetric Square Matrix */\r
-    SKP_int             M,          /* I   Size of Matrix */\r
-    SKP_int32           *L_Q16,     /* I/O Pointer to Square Upper triangular Matrix */\r
-    inv_D_t             *inv_D      /* I/O Pointer to vector holding inverted diagonal elements of D */\r
-)\r
-{\r
-    SKP_int   i, j, k, status, loop_count;\r
-    const SKP_int32 *ptr1, *ptr2;\r
-    SKP_int32 diag_min_value, tmp_32, err;\r
-    SKP_int32 v_Q0[ MAX_MATRIX_SIZE ], D_Q0[ MAX_MATRIX_SIZE ];\r
-    SKP_int32 one_div_diag_Q36, one_div_diag_Q40, one_div_diag_Q48;\r
-\r
-    SKP_assert( M <= MAX_MATRIX_SIZE );\r
-\r
-    status = 1;\r
-    diag_min_value = SKP_max_32( SKP_SMMUL( SKP_ADD_SAT32( A[ 0 ], A[ SKP_SMULBB( M, M ) - 1 ] ), SKP_FIX_CONST( FIND_LTP_COND_FAC, 31 ) ), 1 << 9 );\r
-    for( loop_count = 0; loop_count < M && status == 1; loop_count++ ) {\r
-        status = 0;\r
-        for( j = 0; j < M; j++ ) {\r
-            ptr1 = matrix_adr( L_Q16, j, 0, M );\r
-            tmp_32 = 0;\r
-            for( i = 0; i < j; i++ ) {\r
-                v_Q0[ i ] = SKP_SMULWW(         D_Q0[ i ], ptr1[ i ] ); /* Q0 */\r
-                tmp_32    = SKP_SMLAWW( tmp_32, v_Q0[ i ], ptr1[ i ] ); /* Q0 */\r
-            }\r
-            tmp_32 = SKP_SUB32( matrix_ptr( A, j, j, M ), tmp_32 );\r
-\r
-            if( tmp_32 < diag_min_value ) {\r
-                tmp_32 = SKP_SUB32( SKP_SMULBB( loop_count + 1, diag_min_value ), tmp_32 );\r
-                /* Matrix not positive semi-definite, or ill conditioned */\r
-                for( i = 0; i < M; i++ ) {\r
-                    matrix_ptr( A, i, i, M ) = SKP_ADD32( matrix_ptr( A, i, i, M ), tmp_32 );\r
-                }\r
-                status = 1;\r
-                break;\r
-            }\r
-            D_Q0[ j ] = tmp_32;                         /* always < max(Correlation) */\r
-        \r
-            /* two-step division */\r
-            one_div_diag_Q36 = SKP_INVERSE32_varQ( tmp_32, 36 );                    /* Q36 */\r
-            one_div_diag_Q40 = SKP_LSHIFT( one_div_diag_Q36, 4 );                   /* Q40 */\r
-            err = SKP_SUB32( 1 << 24, SKP_SMULWW( tmp_32, one_div_diag_Q40 ) );     /* Q24 */\r
-            one_div_diag_Q48 = SKP_SMULWW( err, one_div_diag_Q40 );                 /* Q48 */\r
-\r
-            /* Save 1/Ds */\r
-            inv_D[ j ].Q36_part = one_div_diag_Q36;\r
-            inv_D[ j ].Q48_part = one_div_diag_Q48;\r
-\r
-            matrix_ptr( L_Q16, j, j, M ) = 65536; /* 1.0 in Q16 */\r
-            ptr1 = matrix_adr( A, j, 0, M );\r
-            ptr2 = matrix_adr( L_Q16, j + 1, 0, M );\r
-            for( i = j + 1; i < M; i++ ) { \r
-                tmp_32 = 0;\r
-                for( k = 0; k < j; k++ ) {\r
-                    tmp_32 = SKP_SMLAWW( tmp_32, v_Q0[ k ], ptr2[ k ] ); /* Q0 */\r
-                }\r
-                tmp_32 = SKP_SUB32( ptr1[ i ], tmp_32 ); /* always < max(Correlation) */\r
-\r
-                /* tmp_32 / D_Q0[j] : Divide to Q16 */\r
-                matrix_ptr( L_Q16, i, j, M ) = SKP_ADD32( SKP_SMMUL( tmp_32, one_div_diag_Q48 ),\r
-                    SKP_RSHIFT( SKP_SMULWW( tmp_32, one_div_diag_Q36 ), 4 ) );\r
-\r
-                /* go to next column */\r
-                ptr2 += M; \r
-            }\r
-        }\r
-    }\r
-\r
-    SKP_assert( status == 0 );\r
-}\r
-\r
-SKP_INLINE void SKP_Silk_LS_divide_Q16_FIX(\r
-    SKP_int32 T[],      /* I/O Numenator vector */\r
-    inv_D_t *inv_D,     /* I   1 / D vector     */\r
-    SKP_int M           /* I   Order */\r
-)\r
-{\r
-    SKP_int   i;\r
-    SKP_int32 tmp_32;\r
-    SKP_int32 one_div_diag_Q36, one_div_diag_Q48;\r
-\r
-    for( i = 0; i < M; i++ ) {\r
-        one_div_diag_Q36 = inv_D[ i ].Q36_part;\r
-        one_div_diag_Q48 = inv_D[ i ].Q48_part;\r
-\r
-        tmp_32 = T[ i ];\r
-        T[ i ] = SKP_ADD32( SKP_SMMUL( tmp_32, one_div_diag_Q48 ), SKP_RSHIFT( SKP_SMULWW( tmp_32, one_div_diag_Q36 ), 4 ) );\r
-    }\r
-}\r
-\r
-/* Solve Lx = b, when L is lower triangular and has ones on the diagonal */\r
-SKP_INLINE void SKP_Silk_LS_SolveFirst_FIX(\r
-    const SKP_int32     *L_Q16, /* I Pointer to Lower Triangular Matrix */\r
-    SKP_int             M,      /* I Dim of Matrix equation */\r
-    const SKP_int32     *b,     /* I b Vector */\r
-    SKP_int32           *x_Q16  /* O x Vector */  \r
-)\r
-{\r
-    SKP_int i, j;\r
-    const SKP_int32 *ptr32;\r
-    SKP_int32 tmp_32;\r
-\r
-    for( i = 0; i < M; i++ ) {\r
-        ptr32 = matrix_adr( L_Q16, i, 0, M );\r
-        tmp_32 = 0;\r
-        for( j = 0; j < i; j++ ) {\r
-            tmp_32 = SKP_SMLAWW( tmp_32, ptr32[ j ], x_Q16[ j ] );\r
-        }\r
-        x_Q16[ i ] = SKP_SUB32( b[ i ], tmp_32 );\r
-    }\r
-}\r
-\r
-/* Solve L^t*x = b, where L is lower triangular with ones on the diagonal */\r
-SKP_INLINE void SKP_Silk_LS_SolveLast_FIX(\r
-    const SKP_int32     *L_Q16,     /* I Pointer to Lower Triangular Matrix */\r
-    const SKP_int       M,          /* I Dim of Matrix equation */\r
-    const SKP_int32     *b,         /* I b Vector */\r
-    SKP_int32           *x_Q16      /* O x Vector */  \r
-)\r
-{\r
-    SKP_int i, j;\r
-    const SKP_int32 *ptr32;\r
-    SKP_int32 tmp_32;\r
-\r
-    for( i = M - 1; i >= 0; i-- ) {\r
-        ptr32 = matrix_adr( L_Q16, 0, i, M );\r
-        tmp_32 = 0;\r
-        for( j = M - 1; j > i; j-- ) {\r
-            tmp_32 = SKP_SMLAWW( tmp_32, ptr32[ SKP_SMULBB( j, M ) ], x_Q16[ j ] );\r
-        }\r
-        x_Q16[ i ] = SKP_SUB32( b[ i ], tmp_32 );\r
-    }\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+#include "SKP_Silk_tuning_parameters.h"
+
+/*****************************/
+/* Internal function headers */
+/*****************************/
+
+typedef struct {
+    SKP_int32 Q36_part;
+    SKP_int32 Q48_part;
+} inv_D_t;
+
+/* Factorize square matrix A into LDL form */
+SKP_INLINE void SKP_Silk_LDL_factorize_FIX(
+    SKP_int32           *A,         /* I/O Pointer to Symetric Square Matrix */
+    SKP_int             M,          /* I   Size of Matrix */
+    SKP_int32           *L_Q16,     /* I/O Pointer to Square Upper triangular Matrix */
+    inv_D_t             *inv_D      /* I/O Pointer to vector holding inverted diagonal elements of D */
+);
+
+/* Solve Lx = b, when L is lower triangular and has ones on the diagonal */
+SKP_INLINE void SKP_Silk_LS_SolveFirst_FIX(
+    const SKP_int32     *L_Q16,     /* I Pointer to Lower Triangular Matrix */
+    SKP_int             M,          /* I Dim of Matrix equation */
+    const SKP_int32     *b,         /* I b Vector */
+    SKP_int32           *x_Q16      /* O x Vector */  
+);
+
+/* Solve L^t*x = b, where L is lower triangular with ones on the diagonal */
+SKP_INLINE void SKP_Silk_LS_SolveLast_FIX(
+    const SKP_int32     *L_Q16,     /* I Pointer to Lower Triangular Matrix */
+    const SKP_int       M,          /* I Dim of Matrix equation */
+    const SKP_int32     *b,         /* I b Vector */
+    SKP_int32           *x_Q16      /* O x Vector */  
+);
+
+SKP_INLINE void SKP_Silk_LS_divide_Q16_FIX(
+    SKP_int32           T[],    /* I/O Numenator vector */
+    inv_D_t             *inv_D, /* I   1 / D vector     */
+    SKP_int             M       /* I   dimension        */
+);
+
+/* Solves Ax = b, assuming A is symmetric */
+void SKP_Silk_solve_LDL_FIX(
+    SKP_int32                       *A,                 /* I    Pointer to symetric square matrix A         */
+    SKP_int                         M,                  /* I    Size of matrix                              */
+    const SKP_int32                 *b,                 /* I    Pointer to b vector                         */
+    SKP_int32                       *x_Q16              /* O    Pointer to x solution vector                */
+)
+{
+    SKP_int32 L_Q16[  MAX_MATRIX_SIZE * MAX_MATRIX_SIZE ]; 
+    SKP_int32 Y[      MAX_MATRIX_SIZE ];
+    inv_D_t   inv_D[  MAX_MATRIX_SIZE ];
+
+    SKP_assert( M <= MAX_MATRIX_SIZE );
+
+    /***************************************************
+    Factorize A by LDL such that A = L*D*L',
+    where L is lower triangular with ones on diagonal
+    ****************************************************/
+    SKP_Silk_LDL_factorize_FIX( A, M, L_Q16, inv_D );
+        
+    /****************************************************
+    * substitute D*L'*x = Y. ie:
+    L*D*L'*x = b => L*Y = b <=> Y = inv(L)*b
+    ******************************************************/
+    SKP_Silk_LS_SolveFirst_FIX( L_Q16, M, b, Y );
+
+    /****************************************************
+    D*L'*x = Y <=> L'*x = inv(D)*Y, because D is 
+    diagonal just multiply with 1/d_i
+    ****************************************************/
+    SKP_Silk_LS_divide_Q16_FIX( Y, inv_D, M );
+
+    /****************************************************
+    x = inv(L') * inv(D) * Y
+    *****************************************************/
+    SKP_Silk_LS_SolveLast_FIX( L_Q16, M, Y, x_Q16 );
+}
+
+SKP_INLINE void SKP_Silk_LDL_factorize_FIX(
+    SKP_int32           *A,         /* I   Pointer to Symetric Square Matrix */
+    SKP_int             M,          /* I   Size of Matrix */
+    SKP_int32           *L_Q16,     /* I/O Pointer to Square Upper triangular Matrix */
+    inv_D_t             *inv_D      /* I/O Pointer to vector holding inverted diagonal elements of D */
+)
+{
+    SKP_int   i, j, k, status, loop_count;
+    const SKP_int32 *ptr1, *ptr2;
+    SKP_int32 diag_min_value, tmp_32, err;
+    SKP_int32 v_Q0[ MAX_MATRIX_SIZE ], D_Q0[ MAX_MATRIX_SIZE ];
+    SKP_int32 one_div_diag_Q36, one_div_diag_Q40, one_div_diag_Q48;
+
+    SKP_assert( M <= MAX_MATRIX_SIZE );
+
+    status = 1;
+    diag_min_value = SKP_max_32( SKP_SMMUL( SKP_ADD_SAT32( A[ 0 ], A[ SKP_SMULBB( M, M ) - 1 ] ), SKP_FIX_CONST( FIND_LTP_COND_FAC, 31 ) ), 1 << 9 );
+    for( loop_count = 0; loop_count < M && status == 1; loop_count++ ) {
+        status = 0;
+        for( j = 0; j < M; j++ ) {
+            ptr1 = matrix_adr( L_Q16, j, 0, M );
+            tmp_32 = 0;
+            for( i = 0; i < j; i++ ) {
+                v_Q0[ i ] = SKP_SMULWW(         D_Q0[ i ], ptr1[ i ] ); /* Q0 */
+                tmp_32    = SKP_SMLAWW( tmp_32, v_Q0[ i ], ptr1[ i ] ); /* Q0 */
+            }
+            tmp_32 = SKP_SUB32( matrix_ptr( A, j, j, M ), tmp_32 );
+
+            if( tmp_32 < diag_min_value ) {
+                tmp_32 = SKP_SUB32( SKP_SMULBB( loop_count + 1, diag_min_value ), tmp_32 );
+                /* Matrix not positive semi-definite, or ill conditioned */
+                for( i = 0; i < M; i++ ) {
+                    matrix_ptr( A, i, i, M ) = SKP_ADD32( matrix_ptr( A, i, i, M ), tmp_32 );
+                }
+                status = 1;
+                break;
+            }
+            D_Q0[ j ] = tmp_32;                         /* always < max(Correlation) */
+        
+            /* two-step division */
+            one_div_diag_Q36 = SKP_INVERSE32_varQ( tmp_32, 36 );                    /* Q36 */
+            one_div_diag_Q40 = SKP_LSHIFT( one_div_diag_Q36, 4 );                   /* Q40 */
+            err = SKP_SUB32( 1 << 24, SKP_SMULWW( tmp_32, one_div_diag_Q40 ) );     /* Q24 */
+            one_div_diag_Q48 = SKP_SMULWW( err, one_div_diag_Q40 );                 /* Q48 */
+
+            /* Save 1/Ds */
+            inv_D[ j ].Q36_part = one_div_diag_Q36;
+            inv_D[ j ].Q48_part = one_div_diag_Q48;
+
+            matrix_ptr( L_Q16, j, j, M ) = 65536; /* 1.0 in Q16 */
+            ptr1 = matrix_adr( A, j, 0, M );
+            ptr2 = matrix_adr( L_Q16, j + 1, 0, M );
+            for( i = j + 1; i < M; i++ ) { 
+                tmp_32 = 0;
+                for( k = 0; k < j; k++ ) {
+                    tmp_32 = SKP_SMLAWW( tmp_32, v_Q0[ k ], ptr2[ k ] ); /* Q0 */
+                }
+                tmp_32 = SKP_SUB32( ptr1[ i ], tmp_32 ); /* always < max(Correlation) */
+
+                /* tmp_32 / D_Q0[j] : Divide to Q16 */
+                matrix_ptr( L_Q16, i, j, M ) = SKP_ADD32( SKP_SMMUL( tmp_32, one_div_diag_Q48 ),
+                    SKP_RSHIFT( SKP_SMULWW( tmp_32, one_div_diag_Q36 ), 4 ) );
+
+                /* go to next column */
+                ptr2 += M; 
+            }
+        }
+    }
+
+    SKP_assert( status == 0 );
+}
+
+SKP_INLINE void SKP_Silk_LS_divide_Q16_FIX(
+    SKP_int32 T[],      /* I/O Numenator vector */
+    inv_D_t *inv_D,     /* I   1 / D vector     */
+    SKP_int M           /* I   Order */
+)
+{
+    SKP_int   i;
+    SKP_int32 tmp_32;
+    SKP_int32 one_div_diag_Q36, one_div_diag_Q48;
+
+    for( i = 0; i < M; i++ ) {
+        one_div_diag_Q36 = inv_D[ i ].Q36_part;
+        one_div_diag_Q48 = inv_D[ i ].Q48_part;
+
+        tmp_32 = T[ i ];
+        T[ i ] = SKP_ADD32( SKP_SMMUL( tmp_32, one_div_diag_Q48 ), SKP_RSHIFT( SKP_SMULWW( tmp_32, one_div_diag_Q36 ), 4 ) );
+    }
+}
+
+/* Solve Lx = b, when L is lower triangular and has ones on the diagonal */
+SKP_INLINE void SKP_Silk_LS_SolveFirst_FIX(
+    const SKP_int32     *L_Q16, /* I Pointer to Lower Triangular Matrix */
+    SKP_int             M,      /* I Dim of Matrix equation */
+    const SKP_int32     *b,     /* I b Vector */
+    SKP_int32           *x_Q16  /* O x Vector */  
+)
+{
+    SKP_int i, j;
+    const SKP_int32 *ptr32;
+    SKP_int32 tmp_32;
+
+    for( i = 0; i < M; i++ ) {
+        ptr32 = matrix_adr( L_Q16, i, 0, M );
+        tmp_32 = 0;
+        for( j = 0; j < i; j++ ) {
+            tmp_32 = SKP_SMLAWW( tmp_32, ptr32[ j ], x_Q16[ j ] );
+        }
+        x_Q16[ i ] = SKP_SUB32( b[ i ], tmp_32 );
+    }
+}
+
+/* Solve L^t*x = b, where L is lower triangular with ones on the diagonal */
+SKP_INLINE void SKP_Silk_LS_SolveLast_FIX(
+    const SKP_int32     *L_Q16,     /* I Pointer to Lower Triangular Matrix */
+    const SKP_int       M,          /* I Dim of Matrix equation */
+    const SKP_int32     *b,         /* I b Vector */
+    SKP_int32           *x_Q16      /* O x Vector */  
+)
+{
+    SKP_int i, j;
+    const SKP_int32 *ptr32;
+    SKP_int32 tmp_32;
+
+    for( i = M - 1; i >= 0; i-- ) {
+        ptr32 = matrix_adr( L_Q16, 0, i, M );
+        tmp_32 = 0;
+        for( j = M - 1; j > i; j-- ) {
+            tmp_32 = SKP_SMLAWW( tmp_32, ptr32[ SKP_SMULBB( j, M ) ], x_Q16[ j ] );
+        }
+        x_Q16[ i ] = SKP_SUB32( b[ i ], tmp_32 );
+    }
+}
index b81e01e15131a35ca53b5b5d6731baa9c2f2f5d1..3bfeed16c5d4127edd3535cb2f6dcf1feeb8c421 100644 (file)
-/***********************************************************************\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
-/* Insertion sort (fast for already almost sorted arrays):   */\r
-/* Best case:  O(n)   for an already sorted array            */\r
-/* Worst case: O(n^2) for an inversely sorted array          */\r
-/*                                                           */\r
-/* Shell short:    http://en.wikipedia.org/wiki/Shell_sort   */\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-void SKP_Silk_insertion_sort_increasing(\r
-    SKP_int32           *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 output positions   */\r
-)\r
-{\r
-    SKP_int32    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 for, 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_int16(\r
-    SKP_int16           *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 output positions    */\r
-)\r
-{\r
-    SKP_int i, j;\r
-    SKP_int value;\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, decreasing 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 for, 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_increasing_all_values(\r
-    SKP_int             *a,             /* I/O: Unsorted / Sorted vector                */\r
-    const SKP_int       L               /* I:   Vector length                           */\r
-)\r
-{\r
-    SKP_int    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
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/* Insertion sort (fast for already almost sorted arrays):   */
+/* Best case:  O(n)   for an already sorted array            */
+/* Worst case: O(n^2) for an inversely sorted array          */
+/*                                                           */
+/* Shell short:    http://en.wikipedia.org/wiki/Shell_sort   */
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+void SKP_Silk_insertion_sort_increasing(
+    SKP_int32           *a,             /* I/O:  Unsorted / Sorted vector               */
+    SKP_int             *index,         /* O:    Index vector for the sorted elements   */
+    const SKP_int       L,              /* I:    Vector length                          */
+    const SKP_int       K               /* I:    Number of correctly sorted output positions   */
+)
+{
+    SKP_int32    value;
+    SKP_int        i, j;
+
+    /* Safety checks */
+    SKP_assert( K >  0 );
+    SKP_assert( L >  0 );
+    SKP_assert( L >= K );
+
+    /* Write start indices in index vector */
+    for( i = 0; i < K; i++ ) {
+        index[ i ] = i;
+    }
+
+    /* Sort vector elements by value, increasing order */
+    for( i = 1; i < K; i++ ) {
+        value = a[ i ];
+        for( j = i - 1; ( j >= 0 ) && ( value < a[ j ] ); j-- ) {
+            a[ j + 1 ]     = a[ j ];     /* Shift value */
+            index[ j + 1 ] = index[ j ]; /* Shift index */
+        }
+        a[ j + 1 ]     = value; /* Write value */
+        index[ j + 1 ] = i;     /* Write index */
+    }
+
+    /* If less than L values are asked for, check the remaining values, */
+    /* but only spend CPU to ensure that the K first values are correct */
+    for( i = K; i < L; i++ ) {
+        value = a[ i ];
+        if( value < a[ K - 1 ] ) {
+            for( j = K - 2; ( j >= 0 ) && ( value < a[ j ] ); j-- ) {
+                a[ j + 1 ]     = a[ j ];     /* Shift value */
+                index[ j + 1 ] = index[ j ]; /* Shift index */
+            }
+            a[ j + 1 ]     = value; /* Write value */
+            index[ j + 1 ] = i;        /* Write index */
+        }
+    }
+}
+
+void SKP_Silk_insertion_sort_decreasing_int16(
+    SKP_int16           *a,             /* I/O: Unsorted / Sorted vector                */
+    SKP_int             *index,         /* O:   Index vector for the sorted elements    */
+    const SKP_int       L,              /* I:   Vector length                           */
+    const SKP_int       K               /* I:   Number of correctly sorted output positions    */
+)
+{
+    SKP_int i, j;
+    SKP_int value;
+
+    /* Safety checks */
+    SKP_assert( K >  0 );
+    SKP_assert( L >  0 );
+    SKP_assert( L >= K );
+
+    /* Write start indices in index vector */
+    for( i = 0; i < K; i++ ) {
+        index[ i ] = i;
+    }
+
+    /* Sort vector elements by value, decreasing order */
+    for( i = 1; i < K; i++ ) {
+        value = a[ i ];
+        for( j = i - 1; ( j >= 0 ) && ( value > a[ j ] ); j-- ) {    
+            a[ j + 1 ]     = a[ j ];     /* Shift value */
+            index[ j + 1 ] = index[ j ]; /* Shift index */
+        }
+        a[ j + 1 ]     = value; /* Write value */
+        index[ j + 1 ] = i;     /* Write index */
+    }
+
+    /* If less than L values are asked for, check the remaining values, */
+    /* but only spend CPU to ensure that the K first values are correct */
+    for( i = K; i < L; i++ ) {
+        value = a[ i ];
+        if( value > a[ K - 1 ] ) {
+            for( j = K - 2; ( j >= 0 ) && ( value > a[ j ] ); j-- ) {    
+                a[ j + 1 ]     = a[ j ];     /* Shift value */
+                index[ j + 1 ] = index[ j ]; /* Shift index */
+            }
+            a[ j + 1 ]     = value; /* Write value */
+            index[ j + 1 ] = i;     /* Write index */
+        }
+    }
+}
+
+void SKP_Silk_insertion_sort_increasing_all_values(
+    SKP_int             *a,             /* I/O: Unsorted / Sorted vector                */
+    const SKP_int       L               /* I:   Vector length                           */
+)
+{
+    SKP_int    value;
+    SKP_int    i, j;
+
+    /* Safety checks */
+    SKP_assert( L >  0 );
+
+    /* Sort vector elements by value, increasing order */
+    for( i = 1; i < L; i++ ) {
+        value = a[ i ];
+        for( j = i - 1; ( j >= 0 ) && ( value < a[ j ] ); j-- ) {
+            a[ j + 1 ] = a[ j ]; /* Shift value */
+        }
+        a[ j + 1 ] = value; /* Write value */
+    }
+}
+
index f436ffaa16d52871caac1f78996b5c55f1c4d1ee..c81196e0336a6b1aa1088b892a16811363839bef 100644 (file)
-/***********************************************************************\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
-#ifndef SKP_SILK_STRUCTS_H\r
-#define SKP_SILK_STRUCTS_H\r
-\r
-#include "SKP_Silk_typedef.h"\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-#include "SKP_Silk_define.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-\r
-/************************************/\r
-/* Noise shaping quantization state */\r
-/************************************/\r
-typedef struct {\r
-    SKP_int16   xq[           2 * MAX_FRAME_LENGTH ]; /* Buffer for quantized output signal */\r
-    SKP_int32   sLTP_shp_Q10[ 2 * MAX_FRAME_LENGTH ];\r
-    SKP_int32   sLPC_Q14[ MAX_FRAME_LENGTH / NB_SUBFR + NSQ_LPC_BUF_LENGTH ];\r
-    SKP_int32   sAR2_Q14[ MAX_SHAPE_LPC_ORDER ];\r
-    SKP_int32   sLF_AR_shp_Q12;\r
-    SKP_int     lagPrev;\r
-    SKP_int     sLTP_buf_idx;\r
-    SKP_int     sLTP_shp_buf_idx;\r
-    SKP_int32   rand_seed;\r
-    SKP_int32   prev_inv_gain_Q16;\r
-    SKP_int     rewhite_flag;\r
-} SKP_Silk_nsq_state; /* FIX*/\r
-\r
-/* Struct for Low BitRate Redundant (LBRR) information */\r
-typedef struct {\r
-    SKP_uint8   payload[ MAX_ARITHM_BYTES ];    \r
-    SKP_int     nBytes;                         /* Number of bytes in payload                               */\r
-    SKP_int     usage;                          /* Tells how the payload should be used as FEC              */\r
-} SKP_SILK_LBRR_struct;\r
-\r
-/********************************/\r
-/* VAD state                    */\r
-/********************************/\r
-typedef struct {\r
-    SKP_int32   AnaState[ 2 ];                  /* Analysis filterbank state: 0-8 kHz                       */\r
-    SKP_int32   AnaState1[ 2 ];                 /* Analysis filterbank state: 0-4 kHz                       */\r
-    SKP_int32   AnaState2[ 2 ];                 /* Analysis filterbank state: 0-2 kHz                       */\r
-    SKP_int32   XnrgSubfr[ VAD_N_BANDS ];       /* Subframe energies                                        */\r
-    SKP_int32   NrgRatioSmth_Q8[ VAD_N_BANDS ]; /* Smoothed energy level in each band                       */\r
-    SKP_int16   HPstate;                        /* State of differentiator in the lowest band               */\r
-    SKP_int32   NL[ VAD_N_BANDS ];              /* Noise energy level in each band                          */\r
-    SKP_int32   inv_NL[ VAD_N_BANDS ];          /* Inverse noise energy level in each band                  */\r
-    SKP_int32   NoiseLevelBias[ VAD_N_BANDS ];  /* Noise level estimator bias/offset                        */\r
-    SKP_int32   counter;                        /* Frame counter used in the initial phase                  */\r
-} SKP_Silk_VAD_state;\r
-\r
-/*******************************/\r
-/* Range encoder/decoder state */\r
-/*******************************/\r
-typedef struct {\r
-    SKP_int32   bufferLength;\r
-    SKP_int32   bufferIx;\r
-    SKP_uint32  base_Q32;\r
-    SKP_uint32  range_Q16;\r
-    SKP_int32   error;\r
-    SKP_uint8   buffer[ MAX_ARITHM_BYTES ];     /* Buffer containing payload                                */\r
-} SKP_Silk_range_coder_state;\r
-\r
-/* Input frequency range detection struct */\r
-typedef struct {\r
-    SKP_int32                   S_HP_8_kHz[ NB_SOS ][ 2 ];  /* HP filter State */\r
-    SKP_int32                   ConsecSmplsAboveThres;\r
-    SKP_int32                   ActiveSpeech_ms;            /* Accumulated time with active speech */\r
-    SKP_int                     SWB_detected;               /* Flag to indicate SWB input */\r
-    SKP_int                     WB_detected;                /* Flag to indicate WB input */\r
-} SKP_Silk_detect_SWB_state;\r
-\r
-#if SWITCH_TRANSITION_FILTERING\r
-/* Variable cut-off low-pass filter state */\r
-typedef struct {\r
-    SKP_int32                   In_LP_State[ 2 ];           /* Low pass filter state */\r
-    SKP_int32                   transition_frame_no;        /* Counter which is mapped to a cut-off frequency */\r
-    SKP_int                     mode;                       /* Operating mode, 0: switch down, 1: switch up */\r
-} SKP_Silk_LP_state;\r
-#endif\r
-\r
-/* Structure for one stage of MSVQ */\r
-typedef struct {\r
-    const SKP_int32             nVectors;\r
-    const SKP_int16             *CB_NLSF_Q15;\r
-    const SKP_int16             *Rates_Q5;\r
-} SKP_Silk_NLSF_CBS;\r
-\r
-/* Structure containing NLSF MSVQ codebook */\r
-typedef struct {\r
-    const SKP_int32             nStages;\r
-\r
-    /* Fields for (de)quantizing */\r
-    const SKP_Silk_NLSF_CBS     *CBStages;\r
-    const SKP_int               *NDeltaMin_Q15;\r
-\r
-    /* Fields for arithmetic (de)coding */\r
-    const SKP_uint16            *CDF;\r
-    const SKP_uint16 * const    *StartPtr;\r
-    const SKP_int               *MiddleIx;\r
-} SKP_Silk_NLSF_CB_struct;\r
-\r
-/********************************/\r
-/* Encoder state                */\r
-/********************************/\r
-typedef struct {\r
-    SKP_Silk_range_coder_state      sRC;                            /* Range coder state                                                    */\r
-    SKP_Silk_range_coder_state      sRC_LBRR;                       /* Range coder state (for low bitrate redundancy)                       */\r
-#if HIGH_PASS_INPUT\r
-    SKP_int32                       In_HP_State[ 2 ];               /* High pass filter state                                               */\r
-#endif\r
-#if SWITCH_TRANSITION_FILTERING\r
-    SKP_Silk_LP_state               sLP;                            /* Low pass filter state */\r
-#endif\r
-    SKP_Silk_VAD_state              sVAD;                           /* Voice activity detector state                                        */\r
-\r
-    SKP_int                         LBRRprevLastGainIndex;\r
-    SKP_int                         prev_sigtype;\r
-    SKP_int                         typeOffsetPrev;                 /* Previous signal type and quantization offset                         */\r
-    SKP_int                         prevLag;\r
-    SKP_int                         prev_lagIndex;\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                         fs_kHz;                         /* Internal sampling frequency (kHz)                                    */\r
-    SKP_int                         fs_kHz_changed;                 /* Did we switch yet?                                                   */\r
-    SKP_int                         frame_length;                   /* Frame length (samples)                                               */\r
-    SKP_int                         subfr_length;                   /* Subframe length (samples)                                            */\r
-    SKP_int                         la_pitch;                       /* Look-ahead for pitch analysis (samples)                              */\r
-    SKP_int                         la_shape;                       /* Look-ahead for noise shape analysis (samples)                        */\r
-    SKP_int                         shapeWinLength;                 /* Window length for noise shape analysis (samples)                     */\r
-    SKP_int32                       TargetRate_bps;                 /* Target bitrate (bps)                                                 */\r
-    SKP_int                         PacketSize_ms;                  /* Number of milliseconds to put in each packet                         */\r
-    SKP_int                         PacketLoss_perc;                /* Packet loss rate measured by farend                                  */\r
-    SKP_int32                       frameCounter;\r
-    SKP_int                         Complexity;                     /* Complexity setting: 0-> low; 1-> medium; 2->high                     */\r
-    SKP_int                         nStatesDelayedDecision;         /* Number of states in delayed decision quantization                    */\r
-    SKP_int                         useInterpolatedNLSFs;           /* Flag for using NLSF interpolation                                    */\r
-    SKP_int                         shapingLPCOrder;                /* Filter order for noise shaping filters                               */\r
-    SKP_int                         predictLPCOrder;                /* Filter order for prediction filters                                  */\r
-    SKP_int                         pitchEstimationComplexity;      /* Complexity level for pitch estimator                                 */\r
-    SKP_int                         pitchEstimationLPCOrder;        /* Whitening filter order for pitch estimator                           */\r
-    SKP_int32                       pitchEstimationThreshold_Q16;   /* Threshold for pitch estimator                                        */\r
-    SKP_int                         LTPQuantLowComplexity;          /* Flag for low complexity LTP quantization                             */\r
-    SKP_int                         NLSF_MSVQ_Survivors;            /* Number of survivors in NLSF MSVQ                                     */\r
-    SKP_int                         first_frame_after_reset;        /* Flag for deactivating NLSF interp. and fluc. reduction after resets  */\r
-    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
-\r
-    /* Input/output buffering */\r
-    SKP_int16                       inputBuf[ MAX_FRAME_LENGTH ];   /* buffer containin input signal                                        */\r
-    SKP_int                         inputBufIx;\r
-    SKP_int                         nFramesInPayloadBuf;            /* number of frames sitting in outputBuf                                */\r
-    SKP_int                         nBytesInPayloadBuf;             /* number of bytes sitting in outputBuf                                 */\r
-\r
-    /* Parameters For LTP scaling Control */\r
-    SKP_int                         frames_since_onset;\r
-\r
-    const SKP_Silk_NLSF_CB_struct   *psNLSF_CB[ 2 ];                /* Pointers to voiced/unvoiced NLSF codebooks */\r
-\r
-    /* Struct for Inband LBRR */ \r
-    SKP_SILK_LBRR_struct            LBRR_buffer[ MAX_LBRR_DELAY ];\r
-    SKP_int                         oldest_LBRR_idx;\r
-    SKP_int                         useInBandFEC;                   /* Saves the API setting for query                                      */\r
-    SKP_int                         LBRR_enabled;\r
-    SKP_int                         LBRR_GainIncreases;             /* Number of shifts to Gains to get LBRR rate Voiced frames             */\r
-\r
-    /* Bitrate control */\r
-    SKP_int32                       bitrateDiff;                    /* Accumulated diff. between the target bitrate and the switch bitrates */\r
-    SKP_int32                       bitrate_threshold_up;           /* Threshold for switching to a higher internal sample frequency        */\r
-    SKP_int32                       bitrate_threshold_down;         /* Threshold for switching to a lower internal sample frequency         */\r
-\r
-    SKP_Silk_resampler_state_struct  resampler_state;\r
-\r
-    /* DTX */\r
-    SKP_int                         noSpeechCounter;                /* Counts concecutive nonactive frames, used by DTX                     */\r
-    SKP_int                         useDTX;                         /* Flag to enable DTX                                                   */\r
-    SKP_int                         inDTX;                          /* Flag to signal DTX period                                            */\r
-    SKP_int                         vadFlag;                        /* Flag to indicate Voice Activity                                      */\r
-\r
-    /* Struct for detecting SWB input */\r
-    SKP_Silk_detect_SWB_state       sSWBdetect;\r
-\r
-\r
-    /* Buffers */\r
-    SKP_int8                        q[ MAX_FRAME_LENGTH ];      /* pulse signal buffer */\r
-    SKP_int8                        q_LBRR[ MAX_FRAME_LENGTH ]; /* pulse signal buffer */\r
-\r
-} SKP_Silk_encoder_state;\r
-\r
-\r
-/************************/\r
-/* Encoder control      */\r
-/************************/\r
-typedef struct {\r
-    /* Quantization indices */\r
-    SKP_int     lagIndex;\r
-    SKP_int     contourIndex;\r
-    SKP_int     PERIndex;\r
-    SKP_int     LTPIndex[ NB_SUBFR ];\r
-    SKP_int     NLSFIndices[ NLSF_MSVQ_MAX_CB_STAGES ];  /* NLSF path of quantized LSF vector   */\r
-    SKP_int     NLSFInterpCoef_Q2;\r
-    SKP_int     GainsIndices[ NB_SUBFR ];\r
-    SKP_int32   Seed;\r
-    SKP_int     LTP_scaleIndex;\r
-    SKP_int     RateLevelIndex;\r
-    SKP_int     QuantOffsetType;\r
-    SKP_int     sigtype;\r
-\r
-    /* Prediction and coding parameters */\r
-    SKP_int     pitchL[ NB_SUBFR ];\r
-\r
-    SKP_int     LBRR_usage;                     /* Low bitrate redundancy usage                             */\r
-} SKP_Silk_encoder_control;\r
-\r
-/* Struct for Packet Loss Concealment */\r
-typedef struct {\r
-    SKP_int32   pitchL_Q8;                      /* Pitch lag to use for voiced concealment                  */\r
-    SKP_int16   LTPCoef_Q14[ LTP_ORDER ];       /* LTP coeficients to use for voiced concealment            */\r
-    SKP_int16   prevLPC_Q12[ MAX_LPC_ORDER ];\r
-    SKP_int     last_frame_lost;                /* Was previous frame lost                                  */\r
-    SKP_int32   rand_seed;                      /* Seed for unvoiced signal generation                      */\r
-    SKP_int16   randScale_Q14;                  /* Scaling of unvoiced random signal                        */\r
-    SKP_int32   conc_energy;\r
-    SKP_int     conc_energy_shift;\r
-    SKP_int16   prevLTP_scale_Q14;\r
-    SKP_int32   prevGain_Q16[ NB_SUBFR ];\r
-    SKP_int     fs_kHz;\r
-} SKP_Silk_PLC_struct;\r
-\r
-/* Struct for CNG */\r
-typedef struct {\r
-    SKP_int32   CNG_exc_buf_Q10[ MAX_FRAME_LENGTH ];\r
-    SKP_int     CNG_smth_NLSF_Q15[ MAX_LPC_ORDER ];\r
-    SKP_int32   CNG_synth_state[ MAX_LPC_ORDER ];\r
-    SKP_int32   CNG_smth_Gain_Q16;\r
-    SKP_int32   rand_seed;\r
-    SKP_int     fs_kHz;\r
-} SKP_Silk_CNG_struct;\r
-\r
-/********************************/\r
-/* Decoder state                */\r
-/********************************/\r
-typedef struct {\r
-    SKP_Silk_range_coder_state  sRC;                            /* Range coder state                                                    */\r
-    SKP_int32       prev_inv_gain_Q16;\r
-    SKP_int32       sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];\r
-    SKP_int32       sLPC_Q14[ MAX_FRAME_LENGTH / NB_SUBFR + MAX_LPC_ORDER ];\r
-    SKP_int32       exc_Q10[ MAX_FRAME_LENGTH ];\r
-    SKP_int32       res_Q10[ MAX_FRAME_LENGTH ];\r
-    SKP_int16       outBuf[ 2 * MAX_FRAME_LENGTH ];             /* Buffer for output signal                                             */\r
-    SKP_int         lagPrev;                                    /* Previous Lag                                                         */\r
-    SKP_int         LastGainIndex;                              /* Previous gain index                                                  */\r
-    SKP_int         LastGainIndex_EnhLayer;                     /* Previous gain index                                                  */\r
-    SKP_int         typeOffsetPrev;                             /* Previous signal type and quantization offset                         */\r
-    SKP_int32       HPState[ DEC_HP_ORDER ];                    /* HP filter state                                                      */\r
-    const SKP_int16 *HP_A;                                      /* HP filter AR coefficients                                            */\r
-    const SKP_int16 *HP_B;                                      /* HP filter MA coefficients                                            */\r
-    SKP_int         fs_kHz;                                     /* Sampling frequency in kHz                                            */\r
-    SKP_int32       prev_API_sampleRate;                        /* Previous API sample frequency (Hz)                                   */\r
-    SKP_int         frame_length;                               /* Frame length (samples)                                               */\r
-    SKP_int         subfr_length;                               /* Subframe length (samples)                                            */\r
-    SKP_int         LPC_order;                                  /* LPC order                                                            */\r
-    SKP_int         prevNLSF_Q15[ MAX_LPC_ORDER ];              /* Used to interpolate LSFs                                             */\r
-    SKP_int         first_frame_after_reset;                    /* Flag for deactivating NLSF interp. and fluc. reduction after resets  */\r
-\r
-    /* For buffering payload in case of more frames per packet */\r
-    SKP_int         nBytesLeft;\r
-    SKP_int         nFramesDecoded;\r
-    SKP_int         nFramesInPacket;\r
-    SKP_int         moreInternalDecoderFrames;\r
-    SKP_int         FrameTermination;\r
-\r
-    SKP_Silk_resampler_state_struct  resampler_state;\r
-\r
-    const SKP_Silk_NLSF_CB_struct *psNLSF_CB[ 2 ];      /* Pointers to voiced/unvoiced NLSF codebooks */\r
-\r
-    /* Parameters used to investigate if inband FEC is used */\r
-    SKP_int         vadFlag;\r
-    SKP_int         no_FEC_counter;                             /* Counts number of frames wo inband FEC                                */\r
-    SKP_int         inband_FEC_offset;                          /* 0: no FEC, 1: FEC with 1 packet offset, 2: FEC w 2 packets offset    */ \r
-\r
-    /* CNG state */\r
-    SKP_Silk_CNG_struct sCNG;\r
-\r
-    /* Stuff used for PLC */\r
-    SKP_int         lossCnt;\r
-    SKP_int         prev_sigtype;                               /* Previous sigtype                                                     */\r
-\r
-    SKP_Silk_PLC_struct sPLC;\r
-\r
-\r
-\r
-} SKP_Silk_decoder_state;\r
-\r
-/************************/\r
-/* Decoder control      */\r
-/************************/\r
-typedef struct {\r
-    /* prediction and coding parameters */\r
-    SKP_int             pitchL[ NB_SUBFR ];\r
-    SKP_int32           Gains_Q16[ NB_SUBFR ];\r
-    SKP_int32           Seed;\r
-    /* holds interpolated and final coefficients, 4-byte aligned */\r
-    SKP_DWORD_ALIGN SKP_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];\r
-    SKP_int16           LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ];\r
-    SKP_int             LTP_scale_Q14;\r
-\r
-    /* quantization indices */\r
-    SKP_int             PERIndex;\r
-    SKP_int             RateLevelIndex;\r
-    SKP_int             QuantOffsetType;\r
-    SKP_int             sigtype;\r
-    SKP_int             NLSFInterpCoef_Q2;\r
-} SKP_Silk_decoder_control;\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_STRUCTS_H
+#define SKP_SILK_STRUCTS_H
+
+#include "SKP_Silk_typedef.h"
+#include "SKP_Silk_SigProc_FIX.h"
+#include "SKP_Silk_define.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/************************************/
+/* Noise shaping quantization state */
+/************************************/
+typedef struct {
+    SKP_int16   xq[           2 * MAX_FRAME_LENGTH ]; /* Buffer for quantized output signal */
+    SKP_int32   sLTP_shp_Q10[ 2 * MAX_FRAME_LENGTH ];
+    SKP_int32   sLPC_Q14[ MAX_FRAME_LENGTH / NB_SUBFR + NSQ_LPC_BUF_LENGTH ];
+    SKP_int32   sAR2_Q14[ MAX_SHAPE_LPC_ORDER ];
+    SKP_int32   sLF_AR_shp_Q12;
+    SKP_int     lagPrev;
+    SKP_int     sLTP_buf_idx;
+    SKP_int     sLTP_shp_buf_idx;
+    SKP_int32   rand_seed;
+    SKP_int32   prev_inv_gain_Q16;
+    SKP_int     rewhite_flag;
+} SKP_Silk_nsq_state; /* FIX*/
+
+/* Struct for Low BitRate Redundant (LBRR) information */
+typedef struct {
+    SKP_uint8   payload[ MAX_ARITHM_BYTES ];    
+    SKP_int     nBytes;                         /* Number of bytes in payload                               */
+    SKP_int     usage;                          /* Tells how the payload should be used as FEC              */
+} SKP_SILK_LBRR_struct;
+
+/********************************/
+/* VAD state                    */
+/********************************/
+typedef struct {
+    SKP_int32   AnaState[ 2 ];                  /* Analysis filterbank state: 0-8 kHz                       */
+    SKP_int32   AnaState1[ 2 ];                 /* Analysis filterbank state: 0-4 kHz                       */
+    SKP_int32   AnaState2[ 2 ];                 /* Analysis filterbank state: 0-2 kHz                       */
+    SKP_int32   XnrgSubfr[ VAD_N_BANDS ];       /* Subframe energies                                        */
+    SKP_int32   NrgRatioSmth_Q8[ VAD_N_BANDS ]; /* Smoothed energy level in each band                       */
+    SKP_int16   HPstate;                        /* State of differentiator in the lowest band               */
+    SKP_int32   NL[ VAD_N_BANDS ];              /* Noise energy level in each band                          */
+    SKP_int32   inv_NL[ VAD_N_BANDS ];          /* Inverse noise energy level in each band                  */
+    SKP_int32   NoiseLevelBias[ VAD_N_BANDS ];  /* Noise level estimator bias/offset                        */
+    SKP_int32   counter;                        /* Frame counter used in the initial phase                  */
+} SKP_Silk_VAD_state;
+
+/*******************************/
+/* Range encoder/decoder state */
+/*******************************/
+typedef struct {
+    SKP_int32   bufferLength;
+    SKP_int32   bufferIx;
+    SKP_uint32  base_Q32;
+    SKP_uint32  range_Q16;
+    SKP_int32   error;
+    SKP_uint8   buffer[ MAX_ARITHM_BYTES ];     /* Buffer containing payload                                */
+} SKP_Silk_range_coder_state;
+
+/* Input frequency range detection struct */
+typedef struct {
+    SKP_int32                   S_HP_8_kHz[ NB_SOS ][ 2 ];  /* HP filter State */
+    SKP_int32                   ConsecSmplsAboveThres;
+    SKP_int32                   ActiveSpeech_ms;            /* Accumulated time with active speech */
+    SKP_int                     SWB_detected;               /* Flag to indicate SWB input */
+    SKP_int                     WB_detected;                /* Flag to indicate WB input */
+} SKP_Silk_detect_SWB_state;
+
+#if SWITCH_TRANSITION_FILTERING
+/* Variable cut-off low-pass filter state */
+typedef struct {
+    SKP_int32                   In_LP_State[ 2 ];           /* Low pass filter state */
+    SKP_int32                   transition_frame_no;        /* Counter which is mapped to a cut-off frequency */
+    SKP_int                     mode;                       /* Operating mode, 0: switch down, 1: switch up */
+} SKP_Silk_LP_state;
+#endif
+
+/* Structure for one stage of MSVQ */
+typedef struct {
+    const SKP_int32             nVectors;
+    const SKP_int16             *CB_NLSF_Q15;
+    const SKP_int16             *Rates_Q5;
+} SKP_Silk_NLSF_CBS;
+
+/* Structure containing NLSF MSVQ codebook */
+typedef struct {
+    const SKP_int32             nStages;
+
+    /* Fields for (de)quantizing */
+    const SKP_Silk_NLSF_CBS     *CBStages;
+    const SKP_int               *NDeltaMin_Q15;
+
+    /* Fields for arithmetic (de)coding */
+    const SKP_uint16            *CDF;
+    const SKP_uint16 * const    *StartPtr;
+    const SKP_int               *MiddleIx;
+} SKP_Silk_NLSF_CB_struct;
+
+/********************************/
+/* Encoder state                */
+/********************************/
+typedef struct {
+    SKP_Silk_range_coder_state      sRC;                            /* Range coder state                                                    */
+    SKP_Silk_range_coder_state      sRC_LBRR;                       /* Range coder state (for low bitrate redundancy)                       */
+#if HIGH_PASS_INPUT
+    SKP_int32                       In_HP_State[ 2 ];               /* High pass filter state                                               */
+#endif
+#if SWITCH_TRANSITION_FILTERING
+    SKP_Silk_LP_state               sLP;                            /* Low pass filter state */
+#endif
+    SKP_Silk_VAD_state              sVAD;                           /* Voice activity detector state                                        */
+
+    SKP_int                         LBRRprevLastGainIndex;
+    SKP_int                         prev_sigtype;
+    SKP_int                         typeOffsetPrev;                 /* Previous signal type and quantization offset                         */
+    SKP_int                         prevLag;
+    SKP_int                         prev_lagIndex;
+    SKP_int32                       API_fs_Hz;                      /* API sampling frequency (Hz)                                          */
+    SKP_int32                       prev_API_fs_Hz;                 /* Previous API sampling frequency (Hz)                                 */
+    SKP_int                         maxInternal_fs_kHz;             /* Maximum internal sampling frequency (kHz)                            */
+    SKP_int                         fs_kHz;                         /* Internal sampling frequency (kHz)                                    */
+    SKP_int                         fs_kHz_changed;                 /* Did we switch yet?                                                   */
+    SKP_int                         frame_length;                   /* Frame length (samples)                                               */
+    SKP_int                         subfr_length;                   /* Subframe length (samples)                                            */
+    SKP_int                         la_pitch;                       /* Look-ahead for pitch analysis (samples)                              */
+    SKP_int                         la_shape;                       /* Look-ahead for noise shape analysis (samples)                        */
+    SKP_int                         shapeWinLength;                 /* Window length for noise shape analysis (samples)                     */
+    SKP_int32                       TargetRate_bps;                 /* Target bitrate (bps)                                                 */
+    SKP_int                         PacketSize_ms;                  /* Number of milliseconds to put in each packet                         */
+    SKP_int                         PacketLoss_perc;                /* Packet loss rate measured by farend                                  */
+    SKP_int32                       frameCounter;
+    SKP_int                         Complexity;                     /* Complexity setting: 0-> low; 1-> medium; 2->high                     */
+    SKP_int                         nStatesDelayedDecision;         /* Number of states in delayed decision quantization                    */
+    SKP_int                         useInterpolatedNLSFs;           /* Flag for using NLSF interpolation                                    */
+    SKP_int                         shapingLPCOrder;                /* Filter order for noise shaping filters                               */
+    SKP_int                         predictLPCOrder;                /* Filter order for prediction filters                                  */
+    SKP_int                         pitchEstimationComplexity;      /* Complexity level for pitch estimator                                 */
+    SKP_int                         pitchEstimationLPCOrder;        /* Whitening filter order for pitch estimator                           */
+    SKP_int32                       pitchEstimationThreshold_Q16;   /* Threshold for pitch estimator                                        */
+    SKP_int                         LTPQuantLowComplexity;          /* Flag for low complexity LTP quantization                             */
+    SKP_int                         NLSF_MSVQ_Survivors;            /* Number of survivors in NLSF MSVQ                                     */
+    SKP_int                         first_frame_after_reset;        /* Flag for deactivating NLSF interp. and fluc. reduction after resets  */
+    SKP_int                         controlled_since_last_payload;  /* Flag for ensuring codec_control only runs once per packet            */
+       SKP_int                         warping_Q16;                    /* Warping parameter for warped noise shaping                           */
+
+    /* Input/output buffering */
+    SKP_int16                       inputBuf[ MAX_FRAME_LENGTH ];   /* buffer containin input signal                                        */
+    SKP_int                         inputBufIx;
+    SKP_int                         nFramesInPayloadBuf;            /* number of frames sitting in outputBuf                                */
+    SKP_int                         nBytesInPayloadBuf;             /* number of bytes sitting in outputBuf                                 */
+
+    /* Parameters For LTP scaling Control */
+    SKP_int                         frames_since_onset;
+
+    const SKP_Silk_NLSF_CB_struct   *psNLSF_CB[ 2 ];                /* Pointers to voiced/unvoiced NLSF codebooks */
+
+    /* Struct for Inband LBRR */ 
+    SKP_SILK_LBRR_struct            LBRR_buffer[ MAX_LBRR_DELAY ];
+    SKP_int                         oldest_LBRR_idx;
+    SKP_int                         useInBandFEC;                   /* Saves the API setting for query                                      */
+    SKP_int                         LBRR_enabled;
+    SKP_int                         LBRR_GainIncreases;             /* Number of shifts to Gains to get LBRR rate Voiced frames             */
+
+    /* Bitrate control */
+    SKP_int32                       bitrateDiff;                    /* Accumulated diff. between the target bitrate and the switch bitrates */
+    SKP_int32                       bitrate_threshold_up;           /* Threshold for switching to a higher internal sample frequency        */
+    SKP_int32                       bitrate_threshold_down;         /* Threshold for switching to a lower internal sample frequency         */
+
+    SKP_Silk_resampler_state_struct  resampler_state;
+
+    /* DTX */
+    SKP_int                         noSpeechCounter;                /* Counts concecutive nonactive frames, used by DTX                     */
+    SKP_int                         useDTX;                         /* Flag to enable DTX                                                   */
+    SKP_int                         inDTX;                          /* Flag to signal DTX period                                            */
+    SKP_int                         vadFlag;                        /* Flag to indicate Voice Activity                                      */
+
+    /* Struct for detecting SWB input */
+    SKP_Silk_detect_SWB_state       sSWBdetect;
+
+
+    /* Buffers */
+    SKP_int8                        q[ MAX_FRAME_LENGTH ];      /* pulse signal buffer */
+    SKP_int8                        q_LBRR[ MAX_FRAME_LENGTH ]; /* pulse signal buffer */
+
+} SKP_Silk_encoder_state;
+
+
+/************************/
+/* Encoder control      */
+/************************/
+typedef struct {
+    /* Quantization indices */
+    SKP_int     lagIndex;
+    SKP_int     contourIndex;
+    SKP_int     PERIndex;
+    SKP_int     LTPIndex[ NB_SUBFR ];
+    SKP_int     NLSFIndices[ NLSF_MSVQ_MAX_CB_STAGES ];  /* NLSF path of quantized LSF vector   */
+    SKP_int     NLSFInterpCoef_Q2;
+    SKP_int     GainsIndices[ NB_SUBFR ];
+    SKP_int32   Seed;
+    SKP_int     LTP_scaleIndex;
+    SKP_int     RateLevelIndex;
+    SKP_int     QuantOffsetType;
+    SKP_int     sigtype;
+
+    /* Prediction and coding parameters */
+    SKP_int     pitchL[ NB_SUBFR ];
+
+    SKP_int     LBRR_usage;                     /* Low bitrate redundancy usage                             */
+} SKP_Silk_encoder_control;
+
+/* Struct for Packet Loss Concealment */
+typedef struct {
+    SKP_int32   pitchL_Q8;                      /* Pitch lag to use for voiced concealment                  */
+    SKP_int16   LTPCoef_Q14[ LTP_ORDER ];       /* LTP coeficients to use for voiced concealment            */
+    SKP_int16   prevLPC_Q12[ MAX_LPC_ORDER ];
+    SKP_int     last_frame_lost;                /* Was previous frame lost                                  */
+    SKP_int32   rand_seed;                      /* Seed for unvoiced signal generation                      */
+    SKP_int16   randScale_Q14;                  /* Scaling of unvoiced random signal                        */
+    SKP_int32   conc_energy;
+    SKP_int     conc_energy_shift;
+    SKP_int16   prevLTP_scale_Q14;
+    SKP_int32   prevGain_Q16[ NB_SUBFR ];
+    SKP_int     fs_kHz;
+} SKP_Silk_PLC_struct;
+
+/* Struct for CNG */
+typedef struct {
+    SKP_int32   CNG_exc_buf_Q10[ MAX_FRAME_LENGTH ];
+    SKP_int     CNG_smth_NLSF_Q15[ MAX_LPC_ORDER ];
+    SKP_int32   CNG_synth_state[ MAX_LPC_ORDER ];
+    SKP_int32   CNG_smth_Gain_Q16;
+    SKP_int32   rand_seed;
+    SKP_int     fs_kHz;
+} SKP_Silk_CNG_struct;
+
+/********************************/
+/* Decoder state                */
+/********************************/
+typedef struct {
+    SKP_Silk_range_coder_state  sRC;                            /* Range coder state                                                    */
+    SKP_int32       prev_inv_gain_Q16;
+    SKP_int32       sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];
+    SKP_int32       sLPC_Q14[ MAX_FRAME_LENGTH / NB_SUBFR + MAX_LPC_ORDER ];
+    SKP_int32       exc_Q10[ MAX_FRAME_LENGTH ];
+    SKP_int32       res_Q10[ MAX_FRAME_LENGTH ];
+    SKP_int16       outBuf[ 2 * MAX_FRAME_LENGTH ];             /* Buffer for output signal                                             */
+    SKP_int         lagPrev;                                    /* Previous Lag                                                         */
+    SKP_int         LastGainIndex;                              /* Previous gain index                                                  */
+    SKP_int         LastGainIndex_EnhLayer;                     /* Previous gain index                                                  */
+    SKP_int         typeOffsetPrev;                             /* Previous signal type and quantization offset                         */
+    SKP_int32       HPState[ DEC_HP_ORDER ];                    /* HP filter state                                                      */
+    const SKP_int16 *HP_A;                                      /* HP filter AR coefficients                                            */
+    const SKP_int16 *HP_B;                                      /* HP filter MA coefficients                                            */
+    SKP_int         fs_kHz;                                     /* Sampling frequency in kHz                                            */
+    SKP_int32       prev_API_sampleRate;                        /* Previous API sample frequency (Hz)                                   */
+    SKP_int         frame_length;                               /* Frame length (samples)                                               */
+    SKP_int         subfr_length;                               /* Subframe length (samples)                                            */
+    SKP_int         LPC_order;                                  /* LPC order                                                            */
+    SKP_int         prevNLSF_Q15[ MAX_LPC_ORDER ];              /* Used to interpolate LSFs                                             */
+    SKP_int         first_frame_after_reset;                    /* Flag for deactivating NLSF interp. and fluc. reduction after resets  */
+
+    /* For buffering payload in case of more frames per packet */
+    SKP_int         nBytesLeft;
+    SKP_int         nFramesDecoded;
+    SKP_int         nFramesInPacket;
+    SKP_int         moreInternalDecoderFrames;
+    SKP_int         FrameTermination;
+
+    SKP_Silk_resampler_state_struct  resampler_state;
+
+    const SKP_Silk_NLSF_CB_struct *psNLSF_CB[ 2 ];      /* Pointers to voiced/unvoiced NLSF codebooks */
+
+    /* Parameters used to investigate if inband FEC is used */
+    SKP_int         vadFlag;
+    SKP_int         no_FEC_counter;                             /* Counts number of frames wo inband FEC                                */
+    SKP_int         inband_FEC_offset;                          /* 0: no FEC, 1: FEC with 1 packet offset, 2: FEC w 2 packets offset    */ 
+
+    /* CNG state */
+    SKP_Silk_CNG_struct sCNG;
+
+    /* Stuff used for PLC */
+    SKP_int         lossCnt;
+    SKP_int         prev_sigtype;                               /* Previous sigtype                                                     */
+
+    SKP_Silk_PLC_struct sPLC;
+
+
+
+} SKP_Silk_decoder_state;
+
+/************************/
+/* Decoder control      */
+/************************/
+typedef struct {
+    /* prediction and coding parameters */
+    SKP_int             pitchL[ NB_SUBFR ];
+    SKP_int32           Gains_Q16[ NB_SUBFR ];
+    SKP_int32           Seed;
+    /* holds interpolated and final coefficients, 4-byte aligned */
+    SKP_DWORD_ALIGN SKP_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
+    SKP_int16           LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ];
+    SKP_int             LTP_scale_Q14;
+
+    /* quantization indices */
+    SKP_int             PERIndex;
+    SKP_int             RateLevelIndex;
+    SKP_int             QuantOffsetType;
+    SKP_int             sigtype;
+    SKP_int             NLSFInterpCoef_Q2;
+} SKP_Silk_decoder_control;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 36518651060631b9ced4f15650655ef51201001e..8140dc8eb4c08b3480e7aefc2ceef0a534436673 100644 (file)
-/***********************************************************************\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
-#ifndef SKP_SILK_STRUCTS_FIX_H\r
-#define SKP_SILK_STRUCTS_FIX_H\r
-\r
-#include "SKP_Silk_typedef.h"\r
-#include "SKP_Silk_main.h"\r
-#include "SKP_Silk_structs.h"\r
-\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-/********************************/\r
-/* Noise shaping analysis state */\r
-/********************************/\r
-typedef struct {\r
-    SKP_int     LastGainIndex;\r
-    SKP_int32   HarmBoost_smth_Q16;\r
-    SKP_int32   HarmShapeGain_smth_Q16;\r
-    SKP_int32   Tilt_smth_Q16;\r
-} SKP_Silk_shape_state_FIX;\r
-\r
-/********************************/\r
-/* Prefilter state              */\r
-/********************************/\r
-typedef struct {\r
-    SKP_int16   sLTP_shp[ LTP_BUF_LENGTH ];\r
-    SKP_int32   sAR_shp[ MAX_SHAPE_LPC_ORDER + 1 ];\r
-    SKP_int     sLTP_shp_buf_idx;\r
-    SKP_int32   sLF_AR_shp_Q12;\r
-    SKP_int32   sLF_MA_shp_Q12;\r
-    SKP_int     sHarmHP;\r
-    SKP_int32   rand_seed;\r
-    SKP_int     lagPrev;\r
-} SKP_Silk_prefilter_state_FIX;\r
-\r
-/*****************************/\r
-/* Prediction analysis state */\r
-/*****************************/\r
-typedef struct {\r
-    SKP_int   pitch_LPC_win_length;\r
-    SKP_int   min_pitch_lag;                                        /* Lowest possible pitch lag (samples)  */\r
-    SKP_int   max_pitch_lag;                                        /* Highest possible pitch lag (samples) */\r
-    SKP_int   prev_NLSFq_Q15[ MAX_LPC_ORDER ];                      /* Previously quantized NLSF vector     */\r
-} SKP_Silk_predict_state_FIX;\r
-\r
-\r
-/********************************/\r
-/* Encoder state FIX            */\r
-/********************************/\r
-typedef struct {\r
-    SKP_Silk_encoder_state          sCmn;                           /* Common struct, shared with floating-point code */\r
-\r
-#if HIGH_PASS_INPUT\r
-    SKP_int32                       variable_HP_smth1_Q15;          /* State of first smoother                                              */\r
-    SKP_int32                       variable_HP_smth2_Q15;          /* State of second smoother                                             */\r
-#endif\r
-    SKP_Silk_shape_state_FIX        sShape;                         /* Shape state                                                          */\r
-    SKP_Silk_prefilter_state_FIX    sPrefilt;                       /* Prefilter State                                                      */\r
-    SKP_Silk_predict_state_FIX      sPred;                          /* Prediction state                                                     */\r
-    SKP_Silk_nsq_state              sNSQ;                           /* Noise Shape Quantizer State                                          */\r
-    SKP_Silk_nsq_state              sNSQ_LBRR;                      /* Noise Shape Quantizer State ( for low bitrate redundancy )           */\r
-\r
-    /* 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_int                         mu_LTP_Q8;                      /* Rate-distortion tradeoff in LTP quantization                         */\r
-    SKP_int32                       SNR_dB_Q7;                      /* Quality setting                                                      */\r
-    SKP_int32                       avgGain_Q16;                    /* average gain during active speech                                    */\r
-    SKP_int32                       avgGain_Q16_one_bit_per_sample; /* average gain during active speech                                    */\r
-    SKP_int                         BufferedInChannel_ms;           /* Simulated number of ms buffer because of exceeded TargetRate_bps     */\r
-    SKP_int                         speech_activity_Q8;             /* Speech activity in Q8                                                */\r
-\r
-    /* Parameters For LTP scaling Control */\r
-    SKP_int                         prevLTPredCodGain_Q7;\r
-    SKP_int                         HPLTPredCodGain_Q7;\r
-\r
-    SKP_int32                       inBandFEC_SNR_comp_Q8;          /* Compensation to SNR_dB when using inband FEC Voiced      */\r
-\r
-} SKP_Silk_encoder_state_FIX;\r
-\r
-/************************/\r
-/* Encoder control FIX  */\r
-/************************/\r
-typedef struct {\r
-    SKP_Silk_encoder_control        sCmn;                           /* Common struct, shared with floating-point code */\r
-\r
-    /* Prediction and coding parameters */\r
-    SKP_int32                   Gains_Q16[ NB_SUBFR ];\r
-    SKP_DWORD_ALIGN SKP_int16   PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];\r
-    SKP_int16                   LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ];\r
-    SKP_int                     LTP_scale_Q14;\r
-\r
-    /* Noise shaping parameters */\r
-    /* Testing */\r
-    SKP_DWORD_ALIGN SKP_int16 AR1_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ];\r
-    SKP_DWORD_ALIGN SKP_int16 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ];\r
-    SKP_int32   LF_shp_Q14[        NB_SUBFR ];          /* Packs two int16 coefficients per int32 value             */\r
-    SKP_int     GainsPre_Q14[      NB_SUBFR ];\r
-    SKP_int     HarmBoost_Q14[     NB_SUBFR ];\r
-    SKP_int     Tilt_Q14[          NB_SUBFR ];\r
-    SKP_int     HarmShapeGain_Q14[ NB_SUBFR ];\r
-    SKP_int     Lambda_Q10;\r
-    SKP_int     input_quality_Q14;\r
-    SKP_int     coding_quality_Q14;\r
-    SKP_int32   pitch_freq_low_Hz;\r
-    SKP_int     current_SNR_dB_Q7;\r
-\r
-    /* measures */\r
-    SKP_int     sparseness_Q8;\r
-    SKP_int32   predGain_Q16;\r
-    SKP_int     LTPredCodGain_Q7;\r
-    SKP_int     input_quality_bands_Q15[ VAD_N_BANDS ];\r
-    SKP_int     input_tilt_Q15;\r
-    SKP_int32   ResNrg[ NB_SUBFR ];             /* Residual energy per subframe                             */\r
-    SKP_int     ResNrgQ[ NB_SUBFR ];            /* Q domain for the residual energy > 0                     */\r
-    \r
-} SKP_Silk_encoder_control_FIX;\r
-\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_STRUCTS_FIX_H
+#define SKP_SILK_STRUCTS_FIX_H
+
+#include "SKP_Silk_typedef.h"
+#include "SKP_Silk_main.h"
+#include "SKP_Silk_structs.h"
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/********************************/
+/* Noise shaping analysis state */
+/********************************/
+typedef struct {
+    SKP_int     LastGainIndex;
+    SKP_int32   HarmBoost_smth_Q16;
+    SKP_int32   HarmShapeGain_smth_Q16;
+    SKP_int32   Tilt_smth_Q16;
+} SKP_Silk_shape_state_FIX;
+
+/********************************/
+/* Prefilter state              */
+/********************************/
+typedef struct {
+    SKP_int16   sLTP_shp[ LTP_BUF_LENGTH ];
+    SKP_int32   sAR_shp[ MAX_SHAPE_LPC_ORDER + 1 ];
+    SKP_int     sLTP_shp_buf_idx;
+    SKP_int32   sLF_AR_shp_Q12;
+    SKP_int32   sLF_MA_shp_Q12;
+    SKP_int     sHarmHP;
+    SKP_int32   rand_seed;
+    SKP_int     lagPrev;
+} SKP_Silk_prefilter_state_FIX;
+
+/*****************************/
+/* Prediction analysis state */
+/*****************************/
+typedef struct {
+    SKP_int   pitch_LPC_win_length;
+    SKP_int   min_pitch_lag;                                        /* Lowest possible pitch lag (samples)  */
+    SKP_int   max_pitch_lag;                                        /* Highest possible pitch lag (samples) */
+    SKP_int   prev_NLSFq_Q15[ MAX_LPC_ORDER ];                      /* Previously quantized NLSF vector     */
+} SKP_Silk_predict_state_FIX;
+
+
+/********************************/
+/* Encoder state FIX            */
+/********************************/
+typedef struct {
+    SKP_Silk_encoder_state          sCmn;                           /* Common struct, shared with floating-point code */
+
+#if HIGH_PASS_INPUT
+    SKP_int32                       variable_HP_smth1_Q15;          /* State of first smoother                                              */
+    SKP_int32                       variable_HP_smth2_Q15;          /* State of second smoother                                             */
+#endif
+    SKP_Silk_shape_state_FIX        sShape;                         /* Shape state                                                          */
+    SKP_Silk_prefilter_state_FIX    sPrefilt;                       /* Prefilter State                                                      */
+    SKP_Silk_predict_state_FIX      sPred;                          /* Prediction state                                                     */
+    SKP_Silk_nsq_state              sNSQ;                           /* Noise Shape Quantizer State                                          */
+    SKP_Silk_nsq_state              sNSQ_LBRR;                      /* Noise Shape Quantizer State ( for low bitrate redundancy )           */
+
+    /* Buffer for find pitch and noise shape analysis */
+    SKP_DWORD_ALIGN SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];
+    SKP_int                         LTPCorr_Q15;                    /* Normalized correlation from pitch lag estimator                      */
+    SKP_int                         mu_LTP_Q8;                      /* Rate-distortion tradeoff in LTP quantization                         */
+    SKP_int32                       SNR_dB_Q7;                      /* Quality setting                                                      */
+    SKP_int32                       avgGain_Q16;                    /* average gain during active speech                                    */
+    SKP_int32                       avgGain_Q16_one_bit_per_sample; /* average gain during active speech                                    */
+    SKP_int                         BufferedInChannel_ms;           /* Simulated number of ms buffer because of exceeded TargetRate_bps     */
+    SKP_int                         speech_activity_Q8;             /* Speech activity in Q8                                                */
+
+    /* Parameters For LTP scaling Control */
+    SKP_int                         prevLTPredCodGain_Q7;
+    SKP_int                         HPLTPredCodGain_Q7;
+
+    SKP_int32                       inBandFEC_SNR_comp_Q8;          /* Compensation to SNR_dB when using inband FEC Voiced      */
+
+} SKP_Silk_encoder_state_FIX;
+
+/************************/
+/* Encoder control FIX  */
+/************************/
+typedef struct {
+    SKP_Silk_encoder_control        sCmn;                           /* Common struct, shared with floating-point code */
+
+    /* Prediction and coding parameters */
+    SKP_int32                   Gains_Q16[ NB_SUBFR ];
+    SKP_DWORD_ALIGN SKP_int16   PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
+    SKP_int16                   LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ];
+    SKP_int                     LTP_scale_Q14;
+
+    /* Noise shaping parameters */
+    /* Testing */
+    SKP_DWORD_ALIGN SKP_int16 AR1_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ];
+    SKP_DWORD_ALIGN SKP_int16 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ];
+    SKP_int32   LF_shp_Q14[        NB_SUBFR ];          /* Packs two int16 coefficients per int32 value             */
+    SKP_int     GainsPre_Q14[      NB_SUBFR ];
+    SKP_int     HarmBoost_Q14[     NB_SUBFR ];
+    SKP_int     Tilt_Q14[          NB_SUBFR ];
+    SKP_int     HarmShapeGain_Q14[ NB_SUBFR ];
+    SKP_int     Lambda_Q10;
+    SKP_int     input_quality_Q14;
+    SKP_int     coding_quality_Q14;
+    SKP_int32   pitch_freq_low_Hz;
+    SKP_int     current_SNR_dB_Q7;
+
+    /* measures */
+    SKP_int     sparseness_Q8;
+    SKP_int32   predGain_Q16;
+    SKP_int     LTPredCodGain_Q7;
+    SKP_int     input_quality_bands_Q15[ VAD_N_BANDS ];
+    SKP_int     input_tilt_Q15;
+    SKP_int32   ResNrg[ NB_SUBFR ];             /* Residual energy per subframe                             */
+    SKP_int     ResNrgQ[ NB_SUBFR ];            /* Q domain for the residual energy > 0                     */
+    
+} SKP_Silk_encoder_control_FIX;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index a7cd6915425e1eb10080630811547ffaf055912d..f918d3df51b85d0fec8ff380ef553e12fc954b2c 100644 (file)
-/***********************************************************************\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_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
-/* 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
-    SKP_int32            *energy,            /* O    Energy of x, after shifting to the right            */\r
-    SKP_int              *shift,             /* O    Number of bits right shift applied to energy        */\r
-    const SKP_int16      *x,                 /* I    Input vector                                        */\r
-    SKP_int              len                 /* I    Length of input vector                              */\r
-)\r
-{\r
-    SKP_int   i, shft;\r
-    SKP_int32 in32, 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
-    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
-        if( nrg < 0 ) {\r
-            /* Scale down */\r
-            nrg = (SKP_int32)SKP_RSHIFT_uint( (SKP_uint32)nrg, 2 );\r
-            shft = 2;\r
-            break;\r
-        }\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 = (SKP_int32)SKP_ADD_RSHIFT_uint( nrg, (SKP_uint32)nrg_tmp, shft );\r
-        if( nrg < 0 ) {\r
-            /* Scale down */\r
-            nrg = (SKP_int32)SKP_RSHIFT_uint( (SKP_uint32)nrg, 2 );\r
-            shft += 2;\r
-        }\r
-    }\r
-    if( i == len ) {\r
-        /* One sample left to process */\r
-        nrg_tmp = SKP_SMULBB( x[ i ], x[ i ] );\r
-        nrg = (SKP_int32)SKP_ADD_RSHIFT_uint( nrg, nrg_tmp, shft );\r
-    }\r
-\r
-    /* Make sure to have at least one extra leading zero (two leading zeros in total) */\r
-    if( nrg & 0xC0000000 ) {\r
-        nrg = SKP_RSHIFT_uint( (SKP_uint32)nrg, 2 );\r
-        shft += 2;\r
-    }\r
-\r
-    /* Output arguments */\r
-    *shift  = shft;\r
-    *energy = nrg;\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*                                                                      *
+ * SKP_Silk_sum_sqr_shift.c                                           *
+ *                                                                      *
+ * compute number of bits to right shift the sum of squares of a vector *
+ * of int16s to make it fit in an int32                                 *
+ *                                                                      *
+ * Copyright 2006-2008 (c), Skype Limited                               *
+ *                                                                      */
+#include "SKP_Silk_SigProc_FIX.h"
+/* Compute number of bits to right shift the sum of squares of a vector */
+/* of int16s to make it fit in an int32                                 */
+void SKP_Silk_sum_sqr_shift(
+    SKP_int32            *energy,            /* O    Energy of x, after shifting to the right            */
+    SKP_int              *shift,             /* O    Number of bits right shift applied to energy        */
+    const SKP_int16      *x,                 /* I    Input vector                                        */
+    SKP_int              len                 /* I    Length of input vector                              */
+)
+{
+    SKP_int   i, shft;
+    SKP_int32 in32, nrg_tmp, nrg;
+
+    if( (SKP_int32)( (SKP_int_ptr_size)x & 2 ) != 0 ) {
+        /* Input is not 4-byte aligned */
+        nrg = SKP_SMULBB( x[ 0 ], x[ 0 ] );
+        i = 1;
+    } else {
+        nrg = 0;
+        i   = 0;
+    }
+    shft = 0;
+    len--;
+    while( i < len ) {
+        /* Load two values at once */
+        in32 = *( (SKP_int32 *)&x[ i ] );
+        nrg = SKP_SMLABB_ovflw( nrg, in32, in32 );
+        nrg = SKP_SMLATT_ovflw( nrg, in32, in32 );
+        i += 2;
+        if( nrg < 0 ) {
+            /* Scale down */
+            nrg = (SKP_int32)SKP_RSHIFT_uint( (SKP_uint32)nrg, 2 );
+            shft = 2;
+            break;
+        }
+    }
+    for( ; i < len; i += 2 ) {
+        /* Load two values at once */
+        in32 = *( (SKP_int32 *)&x[ i ] );
+        nrg_tmp = SKP_SMULBB( in32, in32 );
+        nrg_tmp = SKP_SMLATT_ovflw( nrg_tmp, in32, in32 );
+        nrg = (SKP_int32)SKP_ADD_RSHIFT_uint( nrg, (SKP_uint32)nrg_tmp, shft );
+        if( nrg < 0 ) {
+            /* Scale down */
+            nrg = (SKP_int32)SKP_RSHIFT_uint( (SKP_uint32)nrg, 2 );
+            shft += 2;
+        }
+    }
+    if( i == len ) {
+        /* One sample left to process */
+        nrg_tmp = SKP_SMULBB( x[ i ], x[ i ] );
+        nrg = (SKP_int32)SKP_ADD_RSHIFT_uint( nrg, nrg_tmp, shft );
+    }
+
+    /* Make sure to have at least one extra leading zero (two leading zeros in total) */
+    if( nrg & 0xC0000000 ) {
+        nrg = SKP_RSHIFT_uint( (SKP_uint32)nrg, 2 );
+        shft += 2;
+    }
+
+    /* Output arguments */
+    *shift  = shft;
+    *energy = nrg;
+}
+
index 543a0f47f5909bc28a8f45ad1d881615c8e27143..956221eaf3985963b33436902d22222935ea2325 100644 (file)
-/***********************************************************************\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
-#ifndef SKP_SILK_TABLES_H\r
-#define SKP_SILK_TABLES_H\r
-\r
-#include "SKP_Silk_define.h"\r
-#include "SKP_Silk_structs.h"\r
-\r
-#define PITCH_EST_MAX_LAG_MS                18          /* 18 ms -> 56 Hz */\r
-#define PITCH_EST_MIN_LAG_MS                2           /* 2 ms -> 500 Hz */\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-/* entropy coding tables */\r
-extern const SKP_uint16 SKP_Silk_type_offset_CDF[ 5 ];                                              /*   5 */\r
-extern const SKP_uint16 SKP_Silk_type_offset_joint_CDF[ 4 ][ 5 ];                                   /*  20 */\r
-extern const SKP_int    SKP_Silk_type_offset_CDF_offset;\r
-\r
-extern const SKP_uint16 SKP_Silk_gain_CDF[ 2 ][ N_LEVELS_QGAIN + 1 ];                               /* 130 */\r
-extern const SKP_int    SKP_Silk_gain_CDF_offset;\r
-extern const SKP_uint16 SKP_Silk_delta_gain_CDF[ MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 2 ]; /*  46 */\r
-extern const SKP_int    SKP_Silk_delta_gain_CDF_offset;\r
-\r
-extern const SKP_uint16 SKP_Silk_pitch_lag_NB_CDF[ 8 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ];   /* 130 */\r
-extern const SKP_int    SKP_Silk_pitch_lag_NB_CDF_offset;\r
-extern const SKP_uint16 SKP_Silk_pitch_lag_MB_CDF[ 12 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ];  /* 194 */\r
-extern const SKP_int    SKP_Silk_pitch_lag_MB_CDF_offset;\r
-extern const SKP_uint16 SKP_Silk_pitch_lag_WB_CDF[ 16 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ];  /* 258 */\r
-extern const SKP_int    SKP_Silk_pitch_lag_WB_CDF_offset;\r
-extern const SKP_uint16 SKP_Silk_pitch_lag_SWB_CDF[ 24 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ]; /* 386 */\r
-extern const SKP_int    SKP_Silk_pitch_lag_SWB_CDF_offset;\r
-\r
-extern const SKP_uint16 SKP_Silk_pitch_contour_CDF[ 35 ];                                           /*  35 */\r
-extern const SKP_int    SKP_Silk_pitch_contour_CDF_offset;\r
-extern const SKP_uint16 SKP_Silk_pitch_contour_NB_CDF[ 12 ];                                        /*  12 */\r
-extern const SKP_int    SKP_Silk_pitch_contour_NB_CDF_offset;\r
-extern const SKP_uint16 SKP_Silk_pitch_delta_CDF[23];                                               /* 23 */\r
-extern const SKP_int    SKP_Silk_pitch_delta_CDF_offset;\r
-\r
-extern const SKP_uint16 SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS ][ MAX_PULSES + 3 ];           /* 210 */\r
-extern const SKP_int    SKP_Silk_pulses_per_block_CDF_offset;\r
-extern const SKP_int16  SKP_Silk_pulses_per_block_BITS_Q6[ N_RATE_LEVELS - 1 ][ MAX_PULSES + 2 ];   /* 180 */\r
-\r
-extern const SKP_uint16 SKP_Silk_rate_levels_CDF[ 2 ][ N_RATE_LEVELS ];                             /*  20 */\r
-extern const SKP_int    SKP_Silk_rate_levels_CDF_offset;\r
-extern const SKP_int16  SKP_Silk_rate_levels_BITS_Q6[ 2 ][ N_RATE_LEVELS - 1 ];                     /*  18 */\r
-\r
-extern const SKP_int    SKP_Silk_max_pulses_table[ 4 ];                                             /*   4 */\r
-\r
-extern const SKP_uint16 SKP_Silk_shell_code_table0[  33 ];                                          /*  33 */\r
-extern const SKP_uint16 SKP_Silk_shell_code_table1[  52 ];                                          /*  52 */\r
-extern const SKP_uint16 SKP_Silk_shell_code_table2[ 102 ];                                          /* 102 */\r
-extern const SKP_uint16 SKP_Silk_shell_code_table3[ 207 ];                                          /* 207 */\r
-extern const SKP_uint16 SKP_Silk_shell_code_table_offsets[ 19 ];                                    /*  19 */\r
-\r
-extern const SKP_uint16 SKP_Silk_lsb_CDF[ 3 ];                                                      /*   3 */\r
-\r
-extern const SKP_uint16 SKP_Silk_sign_CDF[ 36 ];                                                    /*  36 */\r
-\r
-extern const SKP_uint16 SKP_Silk_LTP_per_index_CDF[ 4 ];                                            /*   4 */\r
-extern const SKP_int    SKP_Silk_LTP_per_index_CDF_offset;\r
-extern const SKP_int16  * const SKP_Silk_LTP_gain_BITS_Q6_ptrs[ NB_LTP_CBKS ];                      /*   3 */\r
-extern const SKP_uint16 * const SKP_Silk_LTP_gain_CDF_ptrs[ NB_LTP_CBKS ];                          /*   3 */\r
-extern const SKP_int    SKP_Silk_LTP_gain_CDF_offsets[ NB_LTP_CBKS ];                               /*   3 */\r
-extern const SKP_int32  SKP_Silk_LTP_gain_middle_avg_RD_Q14;\r
-extern const SKP_uint16 SKP_Silk_LTPscale_CDF[ 4 ];                                                 /*   4 */\r
-extern const SKP_int    SKP_Silk_LTPscale_offset;\r
-\r
-/* Tables for LTPScale */\r
-extern const SKP_int16  SKP_Silk_LTPScales_table_Q14[ 3 ];\r
-\r
-extern const SKP_uint16 SKP_Silk_vadflag_CDF[ 3 ];                                                  /*   3 */\r
-extern const SKP_int    SKP_Silk_vadflag_offset;\r
-\r
-extern const SKP_int    SKP_Silk_SamplingRates_table[ 4 ];                                          /*   4 */\r
-extern const SKP_uint16 SKP_Silk_SamplingRates_CDF[ 5 ];                                            /*   5 */\r
-extern const SKP_int    SKP_Silk_SamplingRates_offset;\r
-\r
-extern const SKP_uint16 SKP_Silk_NLSF_interpolation_factor_CDF[ 6 ];\r
-extern const SKP_int    SKP_Silk_NLSF_interpolation_factor_offset;\r
-\r
-/* NLSF codebooks */\r
-extern const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_16, SKP_Silk_NLSF_CB1_16;\r
-extern const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_10, SKP_Silk_NLSF_CB1_10;\r
-\r
-/* quantization tables */\r
-extern const SKP_int16 * const SKP_Silk_LTP_vq_ptrs_Q14[ NB_LTP_CBKS ];                             /* 168 */\r
-extern const SKP_int    SKP_Silk_LTP_vq_sizes[ NB_LTP_CBKS ];                                       /*   3 */\r
-\r
-/* Piece-wise linear mapping from bitrate in kbps to coding quality in dB SNR */\r
-extern const SKP_int32  TargetRate_table_NB[  TARGET_RATE_TAB_SZ ];\r
-extern const SKP_int32  TargetRate_table_MB[  TARGET_RATE_TAB_SZ ];\r
-extern const SKP_int32  TargetRate_table_WB[  TARGET_RATE_TAB_SZ ];\r
-extern const SKP_int32  TargetRate_table_SWB[ TARGET_RATE_TAB_SZ ];\r
-extern const SKP_int32  SNR_table_Q1[         TARGET_RATE_TAB_SZ ];\r
-\r
-extern const SKP_int32  SNR_table_one_bit_per_sample_Q7[ 4 ];\r
-\r
-/* Filter coeficicnts for HP filter: 4. Order filter implementad as two biquad filters  */\r
-extern const SKP_int16  SKP_Silk_SWB_detect_B_HP_Q13[ NB_SOS ][ 3 ];\r
-extern const SKP_int16  SKP_Silk_SWB_detect_A_HP_Q13[ NB_SOS ][ 2 ];\r
-\r
-/* Decoder high-pass filter coefficients for 24 kHz sampling */\r
-extern const SKP_int16  SKP_Silk_Dec_A_HP_24[ DEC_HP_ORDER ];                                       /*   2 */\r
-extern const SKP_int16  SKP_Silk_Dec_B_HP_24[ DEC_HP_ORDER + 1 ];                                   /*   3 */\r
-\r
-/* Decoder high-pass filter coefficients for 16 kHz sampling */\r
-extern const SKP_int16  SKP_Silk_Dec_A_HP_16[ DEC_HP_ORDER ];                                       /*   2 */\r
-extern const SKP_int16  SKP_Silk_Dec_B_HP_16[ DEC_HP_ORDER + 1 ];                                   /*   3 */\r
-\r
-/* Decoder high-pass filter coefficients for 12 kHz sampling */\r
-extern const SKP_int16  SKP_Silk_Dec_A_HP_12[ DEC_HP_ORDER ];                                       /*   2 */\r
-extern const SKP_int16  SKP_Silk_Dec_B_HP_12[ DEC_HP_ORDER + 1 ];                                   /*   3 */\r
-\r
-/* Decoder high-pass filter coefficients for 8 kHz sampling */\r
-extern const SKP_int16  SKP_Silk_Dec_A_HP_8[ DEC_HP_ORDER ];                                        /*   2 */\r
-extern const SKP_int16  SKP_Silk_Dec_B_HP_8[ DEC_HP_ORDER + 1 ];                                    /*   3 */\r
-\r
-/* Table for frame termination indication */\r
-extern const SKP_uint16 SKP_Silk_FrameTermination_CDF[ 5 ];\r
-extern const SKP_int    SKP_Silk_FrameTermination_offset;\r
-\r
-/* Table for random seed */\r
-extern const SKP_uint16 SKP_Silk_Seed_CDF[ 5 ];\r
-extern const SKP_int    SKP_Silk_Seed_offset;\r
-\r
-/* Quantization offsets */\r
-extern const SKP_int16  SKP_Silk_Quantization_Offsets_Q10[ 2 ][ 2 ];\r
-\r
-#if SWITCH_TRANSITION_FILTERING\r
-/* Interpolation points for filter coefficients used in the bandwidth transition smoother */\r
-extern const SKP_int32 SKP_Silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NB ];\r
-extern const SKP_int32 SKP_Silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NA ];\r
-#endif\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_TABLES_H
+#define SKP_SILK_TABLES_H
+
+#include "SKP_Silk_define.h"
+#include "SKP_Silk_structs.h"
+
+#define PITCH_EST_MAX_LAG_MS                18          /* 18 ms -> 56 Hz */
+#define PITCH_EST_MIN_LAG_MS                2           /* 2 ms -> 500 Hz */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* entropy coding tables */
+extern const SKP_uint16 SKP_Silk_type_offset_CDF[ 5 ];                                              /*   5 */
+extern const SKP_uint16 SKP_Silk_type_offset_joint_CDF[ 4 ][ 5 ];                                   /*  20 */
+extern const SKP_int    SKP_Silk_type_offset_CDF_offset;
+
+extern const SKP_uint16 SKP_Silk_gain_CDF[ 2 ][ N_LEVELS_QGAIN + 1 ];                               /* 130 */
+extern const SKP_int    SKP_Silk_gain_CDF_offset;
+extern const SKP_uint16 SKP_Silk_delta_gain_CDF[ MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 2 ]; /*  46 */
+extern const SKP_int    SKP_Silk_delta_gain_CDF_offset;
+
+extern const SKP_uint16 SKP_Silk_pitch_lag_NB_CDF[ 8 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ];   /* 130 */
+extern const SKP_int    SKP_Silk_pitch_lag_NB_CDF_offset;
+extern const SKP_uint16 SKP_Silk_pitch_lag_MB_CDF[ 12 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ];  /* 194 */
+extern const SKP_int    SKP_Silk_pitch_lag_MB_CDF_offset;
+extern const SKP_uint16 SKP_Silk_pitch_lag_WB_CDF[ 16 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ];  /* 258 */
+extern const SKP_int    SKP_Silk_pitch_lag_WB_CDF_offset;
+extern const SKP_uint16 SKP_Silk_pitch_lag_SWB_CDF[ 24 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ]; /* 386 */
+extern const SKP_int    SKP_Silk_pitch_lag_SWB_CDF_offset;
+
+extern const SKP_uint16 SKP_Silk_pitch_contour_CDF[ 35 ];                                           /*  35 */
+extern const SKP_int    SKP_Silk_pitch_contour_CDF_offset;
+extern const SKP_uint16 SKP_Silk_pitch_contour_NB_CDF[ 12 ];                                        /*  12 */
+extern const SKP_int    SKP_Silk_pitch_contour_NB_CDF_offset;
+extern const SKP_uint16 SKP_Silk_pitch_delta_CDF[23];                                               /* 23 */
+extern const SKP_int    SKP_Silk_pitch_delta_CDF_offset;
+
+extern const SKP_uint16 SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS ][ MAX_PULSES + 3 ];           /* 210 */
+extern const SKP_int    SKP_Silk_pulses_per_block_CDF_offset;
+extern const SKP_int16  SKP_Silk_pulses_per_block_BITS_Q6[ N_RATE_LEVELS - 1 ][ MAX_PULSES + 2 ];   /* 180 */
+
+extern const SKP_uint16 SKP_Silk_rate_levels_CDF[ 2 ][ N_RATE_LEVELS ];                             /*  20 */
+extern const SKP_int    SKP_Silk_rate_levels_CDF_offset;
+extern const SKP_int16  SKP_Silk_rate_levels_BITS_Q6[ 2 ][ N_RATE_LEVELS - 1 ];                     /*  18 */
+
+extern const SKP_int    SKP_Silk_max_pulses_table[ 4 ];                                             /*   4 */
+
+extern const SKP_uint16 SKP_Silk_shell_code_table0[  33 ];                                          /*  33 */
+extern const SKP_uint16 SKP_Silk_shell_code_table1[  52 ];                                          /*  52 */
+extern const SKP_uint16 SKP_Silk_shell_code_table2[ 102 ];                                          /* 102 */
+extern const SKP_uint16 SKP_Silk_shell_code_table3[ 207 ];                                          /* 207 */
+extern const SKP_uint16 SKP_Silk_shell_code_table_offsets[ 19 ];                                    /*  19 */
+
+extern const SKP_uint16 SKP_Silk_lsb_CDF[ 3 ];                                                      /*   3 */
+
+extern const SKP_uint16 SKP_Silk_sign_CDF[ 36 ];                                                    /*  36 */
+
+extern const SKP_uint16 SKP_Silk_LTP_per_index_CDF[ 4 ];                                            /*   4 */
+extern const SKP_int    SKP_Silk_LTP_per_index_CDF_offset;
+extern const SKP_int16  * const SKP_Silk_LTP_gain_BITS_Q6_ptrs[ NB_LTP_CBKS ];                      /*   3 */
+extern const SKP_uint16 * const SKP_Silk_LTP_gain_CDF_ptrs[ NB_LTP_CBKS ];                          /*   3 */
+extern const SKP_int    SKP_Silk_LTP_gain_CDF_offsets[ NB_LTP_CBKS ];                               /*   3 */
+extern const SKP_int32  SKP_Silk_LTP_gain_middle_avg_RD_Q14;
+extern const SKP_uint16 SKP_Silk_LTPscale_CDF[ 4 ];                                                 /*   4 */
+extern const SKP_int    SKP_Silk_LTPscale_offset;
+
+/* Tables for LTPScale */
+extern const SKP_int16  SKP_Silk_LTPScales_table_Q14[ 3 ];
+
+extern const SKP_uint16 SKP_Silk_vadflag_CDF[ 3 ];                                                  /*   3 */
+extern const SKP_int    SKP_Silk_vadflag_offset;
+
+extern const SKP_int    SKP_Silk_SamplingRates_table[ 4 ];                                          /*   4 */
+extern const SKP_uint16 SKP_Silk_SamplingRates_CDF[ 5 ];                                            /*   5 */
+extern const SKP_int    SKP_Silk_SamplingRates_offset;
+
+extern const SKP_uint16 SKP_Silk_NLSF_interpolation_factor_CDF[ 6 ];
+extern const SKP_int    SKP_Silk_NLSF_interpolation_factor_offset;
+
+/* NLSF codebooks */
+extern const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_16, SKP_Silk_NLSF_CB1_16;
+extern const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_10, SKP_Silk_NLSF_CB1_10;
+
+/* quantization tables */
+extern const SKP_int16 * const SKP_Silk_LTP_vq_ptrs_Q14[ NB_LTP_CBKS ];                             /* 168 */
+extern const SKP_int    SKP_Silk_LTP_vq_sizes[ NB_LTP_CBKS ];                                       /*   3 */
+
+/* Piece-wise linear mapping from bitrate in kbps to coding quality in dB SNR */
+extern const SKP_int32  TargetRate_table_NB[  TARGET_RATE_TAB_SZ ];
+extern const SKP_int32  TargetRate_table_MB[  TARGET_RATE_TAB_SZ ];
+extern const SKP_int32  TargetRate_table_WB[  TARGET_RATE_TAB_SZ ];
+extern const SKP_int32  TargetRate_table_SWB[ TARGET_RATE_TAB_SZ ];
+extern const SKP_int32  SNR_table_Q1[         TARGET_RATE_TAB_SZ ];
+
+extern const SKP_int32  SNR_table_one_bit_per_sample_Q7[ 4 ];
+
+/* Filter coeficicnts for HP filter: 4. Order filter implementad as two biquad filters  */
+extern const SKP_int16  SKP_Silk_SWB_detect_B_HP_Q13[ NB_SOS ][ 3 ];
+extern const SKP_int16  SKP_Silk_SWB_detect_A_HP_Q13[ NB_SOS ][ 2 ];
+
+/* Decoder high-pass filter coefficients for 24 kHz sampling */
+extern const SKP_int16  SKP_Silk_Dec_A_HP_24[ DEC_HP_ORDER ];                                       /*   2 */
+extern const SKP_int16  SKP_Silk_Dec_B_HP_24[ DEC_HP_ORDER + 1 ];                                   /*   3 */
+
+/* Decoder high-pass filter coefficients for 16 kHz sampling */
+extern const SKP_int16  SKP_Silk_Dec_A_HP_16[ DEC_HP_ORDER ];                                       /*   2 */
+extern const SKP_int16  SKP_Silk_Dec_B_HP_16[ DEC_HP_ORDER + 1 ];                                   /*   3 */
+
+/* Decoder high-pass filter coefficients for 12 kHz sampling */
+extern const SKP_int16  SKP_Silk_Dec_A_HP_12[ DEC_HP_ORDER ];                                       /*   2 */
+extern const SKP_int16  SKP_Silk_Dec_B_HP_12[ DEC_HP_ORDER + 1 ];                                   /*   3 */
+
+/* Decoder high-pass filter coefficients for 8 kHz sampling */
+extern const SKP_int16  SKP_Silk_Dec_A_HP_8[ DEC_HP_ORDER ];                                        /*   2 */
+extern const SKP_int16  SKP_Silk_Dec_B_HP_8[ DEC_HP_ORDER + 1 ];                                    /*   3 */
+
+/* Table for frame termination indication */
+extern const SKP_uint16 SKP_Silk_FrameTermination_CDF[ 5 ];
+extern const SKP_int    SKP_Silk_FrameTermination_offset;
+
+/* Table for random seed */
+extern const SKP_uint16 SKP_Silk_Seed_CDF[ 5 ];
+extern const SKP_int    SKP_Silk_Seed_offset;
+
+/* Quantization offsets */
+extern const SKP_int16  SKP_Silk_Quantization_Offsets_Q10[ 2 ][ 2 ];
+
+#if SWITCH_TRANSITION_FILTERING
+/* Interpolation points for filter coefficients used in the bandwidth transition smoother */
+extern const SKP_int32 SKP_Silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NB ];
+extern const SKP_int32 SKP_Silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NA ];
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 6de21b9308f83079175cd5d12f503f885eee1400..f4db5cf397cf4ec18d4025a9082a58ed4e1e80d3 100644 (file)
-/***********************************************************************\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_tables.h"\r
-\r
-const SKP_uint16 SKP_Silk_LTP_per_index_CDF[ 4 ] = {\r
-         0,  20992,  40788,  65535\r
-};\r
-\r
-const SKP_int SKP_Silk_LTP_per_index_CDF_offset = 1;\r
-\r
-\r
-const SKP_uint16 SKP_Silk_LTP_gain_CDF_0[ 11 ] = {\r
-         0,  49380,  54463,  56494,  58437,  60101,  61683,  62985,\r
-     64066,  64823,  65535\r
-};\r
-\r
-const SKP_uint16 SKP_Silk_LTP_gain_CDF_1[ 21 ] = {\r
-         0,  25290,  30654,  35710,  40386,  42937,  45250,  47459,\r
-     49411,  51348,  52974,  54517,  55976,  57423,  58865,  60285,\r
-     61667,  62895,  63827,  64724,  65535\r
-};\r
-\r
-const SKP_uint16 SKP_Silk_LTP_gain_CDF_2[ 41 ] = {\r
-         0,   4958,   9439,  13581,  17638,  21651,  25015,  28025,\r
-     30287,  32406,  34330,  36240,  38130,  39790,  41281,  42764,\r
-     44229,  45676,  47081,  48431,  49675,  50849,  51932,  52966,\r
-     53957,  54936,  55869,  56789,  57708,  58504,  59285,  60043,\r
-     60796,  61542,  62218,  62871,  63483,  64076,  64583,  65062,\r
-     65535\r
-};\r
-\r
-const SKP_int SKP_Silk_LTP_gain_CDF_offsets[ 3 ] = {\r
-         1,     3,     10\r
-};\r
-\r
-const SKP_int32 SKP_Silk_LTP_gain_middle_avg_RD_Q14 = 11010;\r
-\r
-const SKP_int16 SKP_Silk_LTP_gain_BITS_Q6_0[ 10 ] = {\r
-        26,    236,    321,    325,    339,    344,    362,    379,\r
-       412,    418\r
-};\r
-\r
-const SKP_int16 SKP_Silk_LTP_gain_BITS_Q6_1[ 20 ] = {\r
-        88,    231,    237,    244,    300,    309,    313,    324,\r
-       325,    341,    346,    351,    352,    352,    354,    356,\r
-       367,    393,    396,    406\r
-};\r
-\r
-const SKP_int16 SKP_Silk_LTP_gain_BITS_Q6_2[ 40 ] = {\r
-       238,    248,    255,    257,    258,    274,    284,    311,\r
-       317,    326,    326,    327,    339,    349,    350,    351,\r
-       352,    355,    358,    366,    371,    379,    383,    387,\r
-       388,    393,    394,    394,    407,    409,    412,    412,\r
-       413,    422,    426,    432,    434,    449,    454,    455\r
-};\r
-\r
-const SKP_uint16 * const SKP_Silk_LTP_gain_CDF_ptrs[ NB_LTP_CBKS ] = {\r
-    SKP_Silk_LTP_gain_CDF_0,\r
-    SKP_Silk_LTP_gain_CDF_1,\r
-    SKP_Silk_LTP_gain_CDF_2\r
-};\r
-\r
-const SKP_int16 * const SKP_Silk_LTP_gain_BITS_Q6_ptrs[ NB_LTP_CBKS ] = {\r
-    SKP_Silk_LTP_gain_BITS_Q6_0,\r
-    SKP_Silk_LTP_gain_BITS_Q6_1,\r
-    SKP_Silk_LTP_gain_BITS_Q6_2\r
-};\r
-\r
-const SKP_int16 SKP_Silk_LTP_gain_vq_0_Q14[ 10 ][ 5 ] = \r
-{\r
-{\r
-       594,    984,   2840,   1021,    669\r
-},\r
-{\r
-        10,     35,    304,     -1,     23\r
-},\r
-{\r
-      -694,   1923,   4603,   2975,   2335\r
-},\r
-{\r
-      2437,   3176,   3778,   1940,    481\r
-},\r
-{\r
-       214,    -46,   7870,   4406,   -521\r
-},\r
-{\r
-      -896,   4818,   8501,   1623,   -887\r
-},\r
-{\r
-      -696,   3178,   6480,   -302,   1081\r
-},\r
-{\r
-       517,    599,   1002,    567,    560\r
-},\r
-{\r
-     -2075,   -834,   4712,   -340,    896\r
-},\r
-{\r
-      1435,   -644,   3993,   -612,  -2063\r
-}\r
-};\r
-\r
-const SKP_int16 SKP_Silk_LTP_gain_vq_1_Q14[ 20 ][ 5 ] = \r
-{\r
-{\r
-      1655,   2918,   5001,   3010,   1775\r
-},\r
-{\r
-       113,    198,    856,    176,    178\r
-},\r
-{\r
-      -843,   2479,   7858,   5371,    574\r
-},\r
-{\r
-        59,   5356,   7648,   2850,   -315\r
-},\r
-{\r
-      3840,   4851,   6527,   1583,  -1233\r
-},\r
-{\r
-      1620,   1760,   2330,   1876,   2045\r
-},\r
-{\r
-      -545,   1854,  11792,   1547,   -307\r
-},\r
-{\r
-      -604,    689,   5369,   5074,   4265\r
-},\r
-{\r
-       521,  -1331,   9829,   6209,  -1211\r
-},\r
-{\r
-     -1315,   6747,   9929,  -1410,    546\r
-},\r
-{\r
-       117,   -144,   2810,   1649,   5240\r
-},\r
-{\r
-      5392,   3476,   2425,    -38,    633\r
-},\r
-{\r
-        14,   -449,   5274,   3547,   -171\r
-},\r
-{\r
-       -98,    395,   9114,   1676,    844\r
-},\r
-{\r
-      -908,   3843,   8861,   -957,   1474\r
-},\r
-{\r
-       396,   6747,   5379,   -329,   1269\r
-},\r
-{\r
-      -335,   2830,   4281,    270,    -54\r
-},\r
-{\r
-      1502,   5609,   8958,   6045,   2059\r
-},\r
-{\r
-      -370,    479,   5267,   5726,   1174\r
-},\r
-{\r
-      5237,  -1144,   6510,    455,    512\r
-}\r
-};\r
-\r
-const SKP_int16 SKP_Silk_LTP_gain_vq_2_Q14[ 40 ][ 5 ] = \r
-{\r
-{\r
-      -278,    415,   9345,   7106,   -431\r
-},\r
-{\r
-     -1006,   3863,   9524,   4724,   -871\r
-},\r
-{\r
-      -954,   4624,  11722,    973,   -300\r
-},\r
-{\r
-      -117,   7066,   8331,   1959,   -901\r
-},\r
-{\r
-       593,   3412,   6070,   4914,   1567\r
-},\r
-{\r
-        54,    -51,  12618,   4228,   -844\r
-},\r
-{\r
-      3157,   4822,   5229,   2313,    717\r
-},\r
-{\r
-      -244,   1161,  14198,    779,     69\r
-},\r
-{\r
-     -1218,   5603,  12894,  -2301,   1001\r
-},\r
-{\r
-      -132,   3960,   9526,    577,   1806\r
-},\r
-{\r
-     -1633,   8815,  10484,  -2452,    895\r
-},\r
-{\r
-       235,    450,   1243,    667,    437\r
-},\r
-{\r
-       959,  -2630,  10897,   8772,  -1852\r
-},\r
-{\r
-      2420,   2046,   8893,   4427,  -1569\r
-},\r
-{\r
-        23,   7091,   8356,  -1285,   1508\r
-},\r
-{\r
-     -1133,    835,   7662,   6043,   2800\r
-},\r
-{\r
-       439,    391,  11016,   2253,   1362\r
-},\r
-{\r
-     -1020,   2876,  13436,   4015,  -3020\r
-},\r
-{\r
-      1060,  -2690,  13512,   5565,  -1394\r
-},\r
-{\r
-     -1420,   8007,  11421,   -152,  -1672\r
-},\r
-{\r
-      -893,   2895,  15434,  -1490,    159\r
-},\r
-{\r
-     -1054,    428,  12208,   8538,  -3344\r
-},\r
-{\r
-      1772,  -1304,   7593,   6185,    561\r
-},\r
-{\r
-       525,  -1207,   6659,  11151,  -1170\r
-},\r
-{\r
-       439,   2667,   4743,   2359,   5515\r
-},\r
-{\r
-      2951,   7432,   7909,   -230,  -1564\r
-},\r
-{\r
-       -72,   2140,   5477,   1391,   1580\r
-},\r
-{\r
-       476,  -1312,  15912,   2174,  -1027\r
-},\r
-{\r
-      5737,    441,   2493,   2043,   2757\r
-},\r
-{\r
-       228,    -43,   1803,   6663,   7064\r
-},\r
-{\r
-      4596,   9182,   1917,   -200,    203\r
-},\r
-{\r
-      -704,  12039,   5451,  -1188,    542\r
-},\r
-{\r
-      1782,  -1040,  10078,   7513,  -2767\r
-},\r
-{\r
-     -2626,   7747,   9019,     62,   1710\r
-},\r
-{\r
-       235,   -233,   2954,  10921,   1947\r
-},\r
-{\r
-     10854,   2814,   1232,   -111,    222\r
-},\r
-{\r
-      2267,   2778,  12325,    156,  -1658\r
-},\r
-{\r
-     -2950,   8095,  16330,    268,  -3626\r
-},\r
-{\r
-        67,   2083,   7950,    -80,  -2432\r
-},\r
-{\r
-       518,    -66,   1718,    415,  11435\r
-}\r
-};\r
-\r
-const SKP_int16 * const SKP_Silk_LTP_vq_ptrs_Q14[ NB_LTP_CBKS ] = {\r
-    &SKP_Silk_LTP_gain_vq_0_Q14[ 0 ][ 0 ],\r
-    &SKP_Silk_LTP_gain_vq_1_Q14[ 0 ][ 0 ],\r
-    &SKP_Silk_LTP_gain_vq_2_Q14[ 0 ][ 0 ]\r
-};\r
\r
-const SKP_int SKP_Silk_LTP_vq_sizes[ NB_LTP_CBKS ] = {\r
-    10, 20, 40 \r
-};\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_tables.h"
+
+const SKP_uint16 SKP_Silk_LTP_per_index_CDF[ 4 ] = {
+         0,  20992,  40788,  65535
+};
+
+const SKP_int SKP_Silk_LTP_per_index_CDF_offset = 1;
+
+
+const SKP_uint16 SKP_Silk_LTP_gain_CDF_0[ 11 ] = {
+         0,  49380,  54463,  56494,  58437,  60101,  61683,  62985,
+     64066,  64823,  65535
+};
+
+const SKP_uint16 SKP_Silk_LTP_gain_CDF_1[ 21 ] = {
+         0,  25290,  30654,  35710,  40386,  42937,  45250,  47459,
+     49411,  51348,  52974,  54517,  55976,  57423,  58865,  60285,
+     61667,  62895,  63827,  64724,  65535
+};
+
+const SKP_uint16 SKP_Silk_LTP_gain_CDF_2[ 41 ] = {
+         0,   4958,   9439,  13581,  17638,  21651,  25015,  28025,
+     30287,  32406,  34330,  36240,  38130,  39790,  41281,  42764,
+     44229,  45676,  47081,  48431,  49675,  50849,  51932,  52966,
+     53957,  54936,  55869,  56789,  57708,  58504,  59285,  60043,
+     60796,  61542,  62218,  62871,  63483,  64076,  64583,  65062,
+     65535
+};
+
+const SKP_int SKP_Silk_LTP_gain_CDF_offsets[ 3 ] = {
+         1,     3,     10
+};
+
+const SKP_int32 SKP_Silk_LTP_gain_middle_avg_RD_Q14 = 11010;
+
+const SKP_int16 SKP_Silk_LTP_gain_BITS_Q6_0[ 10 ] = {
+        26,    236,    321,    325,    339,    344,    362,    379,
+       412,    418
+};
+
+const SKP_int16 SKP_Silk_LTP_gain_BITS_Q6_1[ 20 ] = {
+        88,    231,    237,    244,    300,    309,    313,    324,
+       325,    341,    346,    351,    352,    352,    354,    356,
+       367,    393,    396,    406
+};
+
+const SKP_int16 SKP_Silk_LTP_gain_BITS_Q6_2[ 40 ] = {
+       238,    248,    255,    257,    258,    274,    284,    311,
+       317,    326,    326,    327,    339,    349,    350,    351,
+       352,    355,    358,    366,    371,    379,    383,    387,
+       388,    393,    394,    394,    407,    409,    412,    412,
+       413,    422,    426,    432,    434,    449,    454,    455
+};
+
+const SKP_uint16 * const SKP_Silk_LTP_gain_CDF_ptrs[ NB_LTP_CBKS ] = {
+    SKP_Silk_LTP_gain_CDF_0,
+    SKP_Silk_LTP_gain_CDF_1,
+    SKP_Silk_LTP_gain_CDF_2
+};
+
+const SKP_int16 * const SKP_Silk_LTP_gain_BITS_Q6_ptrs[ NB_LTP_CBKS ] = {
+    SKP_Silk_LTP_gain_BITS_Q6_0,
+    SKP_Silk_LTP_gain_BITS_Q6_1,
+    SKP_Silk_LTP_gain_BITS_Q6_2
+};
+
+const SKP_int16 SKP_Silk_LTP_gain_vq_0_Q14[ 10 ][ 5 ] = 
+{
+{
+       594,    984,   2840,   1021,    669
+},
+{
+        10,     35,    304,     -1,     23
+},
+{
+      -694,   1923,   4603,   2975,   2335
+},
+{
+      2437,   3176,   3778,   1940,    481
+},
+{
+       214,    -46,   7870,   4406,   -521
+},
+{
+      -896,   4818,   8501,   1623,   -887
+},
+{
+      -696,   3178,   6480,   -302,   1081
+},
+{
+       517,    599,   1002,    567,    560
+},
+{
+     -2075,   -834,   4712,   -340,    896
+},
+{
+      1435,   -644,   3993,   -612,  -2063
+}
+};
+
+const SKP_int16 SKP_Silk_LTP_gain_vq_1_Q14[ 20 ][ 5 ] = 
+{
+{
+      1655,   2918,   5001,   3010,   1775
+},
+{
+       113,    198,    856,    176,    178
+},
+{
+      -843,   2479,   7858,   5371,    574
+},
+{
+        59,   5356,   7648,   2850,   -315
+},
+{
+      3840,   4851,   6527,   1583,  -1233
+},
+{
+      1620,   1760,   2330,   1876,   2045
+},
+{
+      -545,   1854,  11792,   1547,   -307
+},
+{
+      -604,    689,   5369,   5074,   4265
+},
+{
+       521,  -1331,   9829,   6209,  -1211
+},
+{
+     -1315,   6747,   9929,  -1410,    546
+},
+{
+       117,   -144,   2810,   1649,   5240
+},
+{
+      5392,   3476,   2425,    -38,    633
+},
+{
+        14,   -449,   5274,   3547,   -171
+},
+{
+       -98,    395,   9114,   1676,    844
+},
+{
+      -908,   3843,   8861,   -957,   1474
+},
+{
+       396,   6747,   5379,   -329,   1269
+},
+{
+      -335,   2830,   4281,    270,    -54
+},
+{
+      1502,   5609,   8958,   6045,   2059
+},
+{
+      -370,    479,   5267,   5726,   1174
+},
+{
+      5237,  -1144,   6510,    455,    512
+}
+};
+
+const SKP_int16 SKP_Silk_LTP_gain_vq_2_Q14[ 40 ][ 5 ] = 
+{
+{
+      -278,    415,   9345,   7106,   -431
+},
+{
+     -1006,   3863,   9524,   4724,   -871
+},
+{
+      -954,   4624,  11722,    973,   -300
+},
+{
+      -117,   7066,   8331,   1959,   -901
+},
+{
+       593,   3412,   6070,   4914,   1567
+},
+{
+        54,    -51,  12618,   4228,   -844
+},
+{
+      3157,   4822,   5229,   2313,    717
+},
+{
+      -244,   1161,  14198,    779,     69
+},
+{
+     -1218,   5603,  12894,  -2301,   1001
+},
+{
+      -132,   3960,   9526,    577,   1806
+},
+{
+     -1633,   8815,  10484,  -2452,    895
+},
+{
+       235,    450,   1243,    667,    437
+},
+{
+       959,  -2630,  10897,   8772,  -1852
+},
+{
+      2420,   2046,   8893,   4427,  -1569
+},
+{
+        23,   7091,   8356,  -1285,   1508
+},
+{
+     -1133,    835,   7662,   6043,   2800
+},
+{
+       439,    391,  11016,   2253,   1362
+},
+{
+     -1020,   2876,  13436,   4015,  -3020
+},
+{
+      1060,  -2690,  13512,   5565,  -1394
+},
+{
+     -1420,   8007,  11421,   -152,  -1672
+},
+{
+      -893,   2895,  15434,  -1490,    159
+},
+{
+     -1054,    428,  12208,   8538,  -3344
+},
+{
+      1772,  -1304,   7593,   6185,    561
+},
+{
+       525,  -1207,   6659,  11151,  -1170
+},
+{
+       439,   2667,   4743,   2359,   5515
+},
+{
+      2951,   7432,   7909,   -230,  -1564
+},
+{
+       -72,   2140,   5477,   1391,   1580
+},
+{
+       476,  -1312,  15912,   2174,  -1027
+},
+{
+      5737,    441,   2493,   2043,   2757
+},
+{
+       228,    -43,   1803,   6663,   7064
+},
+{
+      4596,   9182,   1917,   -200,    203
+},
+{
+      -704,  12039,   5451,  -1188,    542
+},
+{
+      1782,  -1040,  10078,   7513,  -2767
+},
+{
+     -2626,   7747,   9019,     62,   1710
+},
+{
+       235,   -233,   2954,  10921,   1947
+},
+{
+     10854,   2814,   1232,   -111,    222
+},
+{
+      2267,   2778,  12325,    156,  -1658
+},
+{
+     -2950,   8095,  16330,    268,  -3626
+},
+{
+        67,   2083,   7950,    -80,  -2432
+},
+{
+       518,    -66,   1718,    415,  11435
+}
+};
+
+const SKP_int16 * const SKP_Silk_LTP_vq_ptrs_Q14[ NB_LTP_CBKS ] = {
+    &SKP_Silk_LTP_gain_vq_0_Q14[ 0 ][ 0 ],
+    &SKP_Silk_LTP_gain_vq_1_Q14[ 0 ][ 0 ],
+    &SKP_Silk_LTP_gain_vq_2_Q14[ 0 ][ 0 ]
+};
+const SKP_int SKP_Silk_LTP_vq_sizes[ NB_LTP_CBKS ] = {
+    10, 20, 40 
+};
index 8606b133c131d8c82ed135014bc2feb3cc4aa407..79db311e495724b8b6a6ee3f5f2e50d2d2f7e251 100644 (file)
-/***********************************************************************\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
-/* This file has been automatically generated */\r
-/*                                            */\r
-/* ROM usage:  0.29 + 2.66 kB                 */\r
-/**********************************************/\r
-\r
-#include "SKP_Silk_structs.h"\r
-#include "SKP_Silk_tables_NLSF_CB0_10.h"\r
-#include "SKP_Silk_tables.h"\r
-\r
-const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB0_10_CDF[ NLSF_MSVQ_CB0_10_VECTORS + NLSF_MSVQ_CB0_10_STAGES ] =\r
-{\r
-            0,\r
-         2658,\r
-         4420,\r
-         6107,\r
-         7757,\r
-         9408,\r
-        10955,\r
-        12502,\r
-        13983,\r
-        15432,\r
-        16882,\r
-        18331,\r
-        19750,\r
-        21108,\r
-        22409,\r
-        23709,\r
-        25010,\r
-        26256,\r
-        27501,\r
-        28747,\r
-        29965,\r
-        31158,\r
-        32351,\r
-        33544,\r
-        34736,\r
-        35904,\r
-        36997,\r
-        38091,\r
-        39185,\r
-        40232,\r
-        41280,\r
-        42327,\r
-        43308,\r
-        44290,\r
-        45271,\r
-        46232,\r
-        47192,\r
-        48132,\r
-        49032,\r
-        49913,\r
-        50775,\r
-        51618,\r
-        52462,\r
-        53287,\r
-        54095,\r
-        54885,\r
-        55675,\r
-        56449,\r
-        57222,\r
-        57979,\r
-        58688,\r
-        59382,\r
-        60076,\r
-        60726,\r
-        61363,\r
-        61946,\r
-        62505,\r
-        63052,\r
-        63543,\r
-        63983,\r
-        64396,\r
-        64766,\r
-        65023,\r
-        65279,\r
-        65535,\r
-            0,\r
-         4977,\r
-         9542,\r
-        14106,\r
-        18671,\r
-        23041,\r
-        27319,\r
-        31596,\r
-        35873,\r
-        39969,\r
-        43891,\r
-        47813,\r
-        51652,\r
-        55490,\r
-        59009,\r
-        62307,\r
-        65535,\r
-            0,\r
-         8571,\r
-        17142,\r
-        25529,\r
-        33917,\r
-        42124,\r
-        49984,\r
-        57844,\r
-        65535,\r
-            0,\r
-         8732,\r
-        17463,\r
-        25825,\r
-        34007,\r
-        42189,\r
-        50196,\r
-        58032,\r
-        65535,\r
-            0,\r
-         8948,\r
-        17704,\r
-        25733,\r
-        33762,\r
-        41791,\r
-        49821,\r
-        57678,\r
-        65535,\r
-            0,\r
-         4374,\r
-         8655,\r
-        12936,\r
-        17125,\r
-        21313,\r
-        25413,\r
-        29512,\r
-        33611,\r
-        37710,\r
-        41809,\r
-        45820,\r
-        49832,\r
-        53843,\r
-        57768,\r
-        61694,\r
-        65535\r
-};\r
-\r
-const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB0_10_CDF_start_ptr[ NLSF_MSVQ_CB0_10_STAGES ] =\r
-{\r
-     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[   0 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[  65 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[  82 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[  91 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[ 100 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[ 109 ]\r
-};\r
-\r
-const SKP_int SKP_Silk_NLSF_MSVQ_CB0_10_CDF_middle_idx[ NLSF_MSVQ_CB0_10_STAGES ] =\r
-{\r
-      23,\r
-       8,\r
-       5,\r
-       5,\r
-       5,\r
-       9\r
-};\r
-\r
-const SKP_int16 SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[ NLSF_MSVQ_CB0_10_VECTORS ] =\r
-{\r
-              148,              167,\r
-              169,              170,\r
-              170,              173,\r
-              173,              175,\r
-              176,              176,\r
-              176,              177,\r
-              179,              181,\r
-              181,              181,\r
-              183,              183,\r
-              183,              184,\r
-              185,              185,\r
-              185,              185,\r
-              186,              189,\r
-              189,              189,\r
-              191,              191,\r
-              191,              194,\r
-              194,              194,\r
-              195,              195,\r
-              196,              198,\r
-              199,              200,\r
-              201,              201,\r
-              202,              203,\r
-              204,              204,\r
-              205,              205,\r
-              206,              209,\r
-              210,              210,\r
-              213,              214,\r
-              218,              220,\r
-              221,              226,\r
-              231,              234,\r
-              239,              256,\r
-              256,              256,\r
-              119,              123,\r
-              123,              123,\r
-              125,              126,\r
-              126,              126,\r
-              128,              130,\r
-              130,              131,\r
-              131,              135,\r
-              138,              139,\r
-               94,               94,\r
-               95,               95,\r
-               96,               98,\r
-               98,               99,\r
-               93,               93,\r
-               95,               96,\r
-               96,               97,\r
-               98,              100,\r
-               92,               93,\r
-               97,               97,\r
-               97,               97,\r
-               98,               98,\r
-              125,              126,\r
-              126,              127,\r
-              127,              128,\r
-              128,              128,\r
-              128,              128,\r
-              129,              129,\r
-              129,              130,\r
-              130,              131\r
-};\r
-\r
-const SKP_int SKP_Silk_NLSF_MSVQ_CB0_10_ndelta_min_Q15[ 10 + 1 ] =\r
-{\r
-              563,\r
-                3,\r
-               22,\r
-               20,\r
-                3,\r
-                3,\r
-              132,\r
-              119,\r
-              358,\r
-               86,\r
-              964\r
-};\r
-\r
-const SKP_int16 SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 * NLSF_MSVQ_CB0_10_VECTORS ] =\r
-{\r
-             2210,             4023,\r
-             6981,             9260,\r
-            12573,            15687,\r
-            19207,            22383,\r
-            25981,            29142,\r
-             3285,             4172,\r
-             6116,            10856,\r
-            15289,            16826,\r
-            19701,            22010,\r
-            24721,            29313,\r
-             1554,             2511,\r
-             6577,            10337,\r
-            13837,            16511,\r
-            20086,            23214,\r
-            26480,            29464,\r
-             3062,             4017,\r
-             5771,            10037,\r
-            13365,            14952,\r
-            20140,            22891,\r
-            25229,            29603,\r
-             2085,             3457,\r
-             5934,             8718,\r
-            11501,            13670,\r
-            17997,            21817,\r
-            24935,            28745,\r
-             2776,             4093,\r
-             6421,            10413,\r
-            15111,            16806,\r
-            20825,            23826,\r
-            26308,            29411,\r
-             2717,             4034,\r
-             5697,             8463,\r
-            14301,            16354,\r
-            19007,            23413,\r
-            25812,            28506,\r
-             2872,             3702,\r
-             5881,            11034,\r
-            17141,            18879,\r
-            21146,            23451,\r
-            25817,            29600,\r
-             2999,             4015,\r
-             7357,            11219,\r
-            12866,            17307,\r
-            20081,            22644,\r
-            26774,            29107,\r
-             2942,             3866,\r
-             5918,            11915,\r
-            13909,            16072,\r
-            20453,            22279,\r
-            27310,            29826,\r
-             2271,             3527,\r
-             6606,             9729,\r
-            12943,            17382,\r
-            20224,            22345,\r
-            24602,            28290,\r
-             2207,             3310,\r
-             5844,             9339,\r
-            11141,            15651,\r
-            18576,            21177,\r
-            25551,            28228,\r
-             3963,             4975,\r
-             6901,            11588,\r
-            13466,            15577,\r
-            19231,            21368,\r
-            25510,            27759,\r
-             2749,             3549,\r
-             6966,            13808,\r
-            15653,            17645,\r
-            20090,            22599,\r
-            26467,            28537,\r
-             2126,             3504,\r
-             5109,             9954,\r
-            12550,            14620,\r
-            19703,            21687,\r
-            26457,            29106,\r
-             3966,             5745,\r
-             7442,             9757,\r
-            14468,            16404,\r
-            19135,            23048,\r
-            25375,            28391,\r
-             3197,             4751,\r
-             6451,             9298,\r
-            13038,            14874,\r
-            17962,            20627,\r
-            23835,            28464,\r
-             3195,             4081,\r
-             6499,            12252,\r
-            14289,            16040,\r
-            18357,            20730,\r
-            26980,            29309,\r
-             1533,             2471,\r
-             4486,             7796,\r
-            12332,            15758,\r
-            19567,            22298,\r
-            25673,            29051,\r
-             2002,             2971,\r
-             4985,             8083,\r
-            13181,            15435,\r
-            18237,            21517,\r
-            24595,            28351,\r
-             3808,             4925,\r
-             6710,            10201,\r
-            12011,            14300,\r
-            18457,            20391,\r
-            26525,            28956,\r
-             2281,             3418,\r
-             4979,             8726,\r
-            15964,            18104,\r
-            20250,            22771,\r
-            25286,            28954,\r
-             3051,             5479,\r
-             7290,             9848,\r
-            12744,            14503,\r
-            18665,            23684,\r
-            26065,            28947,\r
-             2364,             3565,\r
-             5502,             9621,\r
-            14922,            16621,\r
-            19005,            20996,\r
-            26310,            29302,\r
-             4093,             5212,\r
-             6833,             9880,\r
-            16303,            18286,\r
-            20571,            23614,\r
-            26067,            29128,\r
-             2941,             3996,\r
-             6038,            10638,\r
-            12668,            14451,\r
-            16798,            19392,\r
-            26051,            28517,\r
-             3863,             5212,\r
-             7019,             9468,\r
-            11039,            13214,\r
-            19942,            22344,\r
-            25126,            29539,\r
-             4615,             6172,\r
-             7853,            10252,\r
-            12611,            14445,\r
-            19719,            22441,\r
-            24922,            29341,\r
-             3566,             4512,\r
-             6985,             8684,\r
-            10544,            16097,\r
-            18058,            22475,\r
-            26066,            28167,\r
-             4481,             5489,\r
-             7432,            11414,\r
-            13191,            15225,\r
-            20161,            22258,\r
-            26484,            29716,\r
-             3320,             4320,\r
-             6621,             9867,\r
-            11581,            14034,\r
-            21168,            23210,\r
-            26588,            29903,\r
-             3794,             4689,\r
-             6916,             8655,\r
-            10143,            16144,\r
-            19568,            21588,\r
-            27557,            29593,\r
-             2446,             3276,\r
-             5918,            12643,\r
-            16601,            18013,\r
-            21126,            23175,\r
-            27300,            29634,\r
-             2450,             3522,\r
-             5437,             8560,\r
-            15285,            19911,\r
-            21826,            24097,\r
-            26567,            29078,\r
-             2580,             3796,\r
-             5580,             8338,\r
-             9969,            12675,\r
-            18907,            22753,\r
-            25450,            29292,\r
-             3325,             4312,\r
-             6241,             7709,\r
-             9164,            14452,\r
-            21665,            23797,\r
-            27096,            29857,\r
-             3338,             4163,\r
-             7738,            11114,\r
-            12668,            14753,\r
-            16931,            22736,\r
-            25671,            28093,\r
-             3840,             4755,\r
-             7755,            13471,\r
-            15338,            17180,\r
-            20077,            22353,\r
-            27181,            29743,\r
-             2504,             4079,\r
-             8351,            12118,\r
-            15046,            18595,\r
-            21684,            24704,\r
-            27519,            29937,\r
-             5234,             6342,\r
-             8267,            11821,\r
-            15155,            16760,\r
-            20667,            23488,\r
-            25949,            29307,\r
-             2681,             3562,\r
-             6028,            10827,\r
-            18458,            20458,\r
-            22303,            24701,\r
-            26912,            29956,\r
-             3374,             4528,\r
-             6230,             8256,\r
-             9513,            12730,\r
-            18666,            20720,\r
-            26007,            28425,\r
-             2731,             3629,\r
-             8320,            12450,\r
-            14112,            16431,\r
-            18548,            22098,\r
-            25329,            27718,\r
-             3481,             4401,\r
-             7321,             9319,\r
-            11062,            13093,\r
-            15121,            22315,\r
-            26331,            28740,\r
-             3577,             4945,\r
-             6669,             8792,\r
-            10299,            12645,\r
-            19505,            24766,\r
-            26996,            29634,\r
-             4058,             5060,\r
-             7288,            10190,\r
-            11724,            13936,\r
-            15849,            18539,\r
-            26701,            29845,\r
-             4262,             5390,\r
-             7057,             8982,\r
-            10187,            15264,\r
-            20480,            22340,\r
-            25958,            28072,\r
-             3404,             4329,\r
-             6629,             7946,\r
-            10121,            17165,\r
-            19640,            22244,\r
-            25062,            27472,\r
-             3157,             4168,\r
-             6195,             9319,\r
-            10771,            13325,\r
-            15416,            19816,\r
-            24672,            27634,\r
-             2503,             3473,\r
-             5130,             6767,\r
-             8571,            14902,\r
-            19033,            21926,\r
-            26065,            28728,\r
-             4133,             5102,\r
-             7553,            10054,\r
-            11757,            14924,\r
-            17435,            20186,\r
-            23987,            26272,\r
-             4972,             6139,\r
-             7894,             9633,\r
-            11320,            14295,\r
-            21737,            24306,\r
-            26919,            29907,\r
-             2958,             3816,\r
-             6851,             9204,\r
-            10895,            18052,\r
-            20791,            23338,\r
-            27556,            29609,\r
-             5234,             6028,\r
-             8034,            10154,\r
-            11242,            14789,\r
-            18948,            20966,\r
-            26585,            29127,\r
-             5241,             6838,\r
-            10526,            12819,\r
-            14681,            17328,\r
-            19928,            22336,\r
-            26193,            28697,\r
-             3412,             4251,\r
-             5988,             7094,\r
-             9907,            18243,\r
-            21669,            23777,\r
-            26969,            29087,\r
-             2470,             3217,\r
-             7797,            15296,\r
-            17365,            19135,\r
-            21979,            24256,\r
-            27322,            29442,\r
-             4939,             5804,\r
-             8145,            11809,\r
-            13873,            15598,\r
-            17234,            19423,\r
-            26476,            29645,\r
-             5051,             6167,\r
-             8223,             9655,\r
-            12159,            17995,\r
-            20464,            22832,\r
-            26616,            28462,\r
-             4987,             5907,\r
-             9319,            11245,\r
-            13132,            15024,\r
-            17485,            22687,\r
-            26011,            28273,\r
-             5137,             6884,\r
-            11025,            14950,\r
-            17191,            19425,\r
-            21807,            24393,\r
-            26938,            29288,\r
-             7057,             7884,\r
-             9528,            10483,\r
-            10960,            14811,\r
-            19070,            21675,\r
-            25645,            28019,\r
-             6759,             7160,\r
-             8546,            11779,\r
-            12295,            13023,\r
-            16627,            21099,\r
-            24697,            28287,\r
-             3863,             9762,\r
-            11068,            11445,\r
-            12049,            13960,\r
-            18085,            21507,\r
-            25224,            28997,\r
-              397,              335,\r
-              651,             1168,\r
-              640,              765,\r
-              465,              331,\r
-              214,             -194,\r
-             -578,             -647,\r
-             -657,              750,\r
-              564,              613,\r
-              549,              630,\r
-              304,              -52,\r
-              828,              922,\r
-              443,              111,\r
-              138,              124,\r
-              169,               14,\r
-              144,               83,\r
-              132,               58,\r
-             -413,             -752,\r
-              869,              336,\r
-              385,               69,\r
-               56,              830,\r
-             -227,             -266,\r
-             -368,             -440,\r
-            -1195,              163,\r
-              126,             -228,\r
-              802,              156,\r
-              188,              120,\r
-              376,               59,\r
-             -358,             -558,\r
-            -1326,             -254,\r
-             -202,             -789,\r
-              296,               92,\r
-              -70,             -129,\r
-             -718,            -1135,\r
-              292,              -29,\r
-             -631,              487,\r
-             -157,             -153,\r
-             -279,                2,\r
-             -419,             -342,\r
-              -34,             -514,\r
-             -799,            -1571,\r
-             -687,             -609,\r
-             -546,             -130,\r
-             -215,             -252,\r
-             -446,             -574,\r
-            -1337,              207,\r
-              -72,               32,\r
-              103,             -642,\r
-              942,              733,\r
-              187,               29,\r
-             -211,             -814,\r
-              143,              225,\r
-               20,               24,\r
-             -268,             -377,\r
-             1623,             1133,\r
-              667,              164,\r
-              307,              366,\r
-              187,               34,\r
-               62,             -313,\r
-             -832,            -1482,\r
-            -1181,              483,\r
-              -42,              -39,\r
-             -450,            -1406,\r
-             -587,              -52,\r
-             -760,              334,\r
-               98,              -60,\r
-             -500,             -488,\r
-            -1058,              299,\r
-              131,             -250,\r
-             -251,             -703,\r
-             1037,              568,\r
-             -413,             -265,\r
-             1687,              573,\r
-              345,              323,\r
-               98,               61,\r
-             -102,               31,\r
-              135,              149,\r
-              617,              365,\r
-              -39,               34,\r
-             -611,             1201,\r
-             1421,              736,\r
-             -414,             -393,\r
-             -492,             -343,\r
-             -316,             -532,\r
-              528,              172,\r
-               90,              322,\r
-             -294,             -319,\r
-             -541,              503,\r
-              639,              401,\r
-                1,             -149,\r
-              -73,             -167,\r
-              150,              118,\r
-              308,              218,\r
-              121,              195,\r
-             -143,             -261,\r
-            -1013,             -802,\r
-              387,              436,\r
-              130,             -427,\r
-             -448,             -681,\r
-              123,              -87,\r
-             -251,             -113,\r
-              274,              310,\r
-              445,              501,\r
-              354,              272,\r
-              141,             -285,\r
-              569,              656,\r
-               37,              -49,\r
-              251,             -386,\r
-             -263,             1122,\r
-              604,              606,\r
-              336,               95,\r
-               34,                0,\r
-               85,              180,\r
-              207,             -367,\r
-             -622,             1070,\r
-               -6,              -79,\r
-             -160,              -92,\r
-             -137,             -276,\r
-             -323,             -371,\r
-             -696,            -1036,\r
-              407,              102,\r
-              -86,             -214,\r
-             -482,             -647,\r
-              -28,             -291,\r
-              -97,             -180,\r
-             -250,             -435,\r
-              -18,              -76,\r
-             -332,              410,\r
-              407,              168,\r
-              539,              411,\r
-              254,              111,\r
-               58,             -145,\r
-              200,               30,\r
-              187,              116,\r
-              131,             -367,\r
-             -475,              781,\r
-             -559,              561,\r
-              195,             -115,\r
-                8,             -168,\r
-               30,               55,\r
-             -122,              131,\r
-               82,               -5,\r
-             -273,              -50,\r
-             -632,              668,\r
-                4,               32,\r
-              -26,             -279,\r
-              315,              165,\r
-              197,              377,\r
-              155,              -41,\r
-             -138,             -324,\r
-             -109,             -617,\r
-              360,               98,\r
-              -53,             -319,\r
-             -114,             -245,\r
-              -82,              507,\r
-              468,              263,\r
-             -137,             -389,\r
-              652,              354,\r
-              -18,             -227,\r
-             -462,             -135,\r
-              317,               53,\r
-              -16,               66,\r
-              -72,             -126,\r
-             -356,             -347,\r
-             -328,              -72,\r
-             -337,              324,\r
-              152,              349,\r
-              169,             -196,\r
-              179,              254,\r
-              260,              325,\r
-              -74,              -80,\r
-               75,              -31,\r
-              270,              275,\r
-               87,              278,\r
-             -446,             -301,\r
-              309,               71,\r
-              -25,             -242,\r
-              516,              161,\r
-             -162,              -83,\r
-              329,              230,\r
-             -311,             -259,\r
-              177,              -26,\r
-             -462,               89,\r
-              257,                6,\r
-             -130,              -93,\r
-             -456,             -317,\r
-             -221,             -206,\r
-             -417,             -182,\r
-              -74,              234,\r
-               48,              261,\r
-              359,              231,\r
-              258,               85,\r
-             -282,              252,\r
-             -147,             -222,\r
-              251,             -207,\r
-              443,              123,\r
-             -417,              -36,\r
-              273,             -241,\r
-              240,             -112,\r
-               44,             -167,\r
-              126,             -124,\r
-              -77,               58,\r
-             -401,              333,\r
-             -118,               82,\r
-              126,              151,\r
-             -433,              359,\r
-             -130,             -102,\r
-              131,             -244,\r
-               86,               85,\r
-             -462,              414,\r
-             -240,               16,\r
-              145,               28,\r
-             -205,             -481,\r
-              373,              293,\r
-              -72,             -174,\r
-               62,              259,\r
-               -8,              -18,\r
-              362,              233,\r
-              185,               43,\r
-              278,               27,\r
-              193,              570,\r
-             -248,              189,\r
-               92,               31,\r
-             -275,               -3,\r
-              243,              176,\r
-              438,              209,\r
-              206,              -51,\r
-               79,              109,\r
-              168,             -185,\r
-             -308,              -68,\r
-             -618,              385,\r
-             -310,             -108,\r
-             -164,              165,\r
-               61,             -152,\r
-             -101,             -412,\r
-             -268,             -257,\r
-              -40,              -20,\r
-              -28,             -158,\r
-             -301,              271,\r
-              380,             -338,\r
-             -367,             -132,\r
-               64,              114,\r
-             -131,             -225,\r
-             -156,             -260,\r
-              -63,             -116,\r
-              155,             -586,\r
-             -202,              254,\r
-             -287,              178,\r
-              227,             -106,\r
-             -294,              164,\r
-              298,             -100,\r
-              185,              317,\r
-              193,              -45,\r
-               28,               80,\r
-              -87,             -433,\r
-               22,              -48,\r
-               48,             -237,\r
-             -229,             -139,\r
-              120,             -364,\r
-              268,             -136,\r
-              396,              125,\r
-              130,              -89,\r
-             -272,              118,\r
-             -256,              -68,\r
-             -451,              488,\r
-              143,             -165,\r
-              -48,             -190,\r
-              106,              219,\r
-               47,              435,\r
-              245,               97,\r
-               75,             -418,\r
-              121,             -187,\r
-              570,             -200,\r
-             -351,              225,\r
-              -21,             -217,\r
-              234,             -111,\r
-              194,               14,\r
-              242,              118,\r
-              140,             -397,\r
-              355,              361,\r
-              -45,             -195\r
-};\r
-\r
-const SKP_Silk_NLSF_CBS SKP_Silk_NLSF_CB0_10_Stage_info[ NLSF_MSVQ_CB0_10_STAGES ] =\r
-{\r
-        {  64, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 *   0 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[   0 ] },\r
-        {  16, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 *  64 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[  64 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 *  80 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[  80 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 *  88 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[  88 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 *  96 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[  96 ] },\r
-        {  16, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 * 104 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[ 104 ] }\r
-};\r
-\r
-const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_10 =\r
-{\r
-        NLSF_MSVQ_CB0_10_STAGES,\r
-        SKP_Silk_NLSF_CB0_10_Stage_info,\r
-        SKP_Silk_NLSF_MSVQ_CB0_10_ndelta_min_Q15,\r
-        SKP_Silk_NLSF_MSVQ_CB0_10_CDF,\r
-        SKP_Silk_NLSF_MSVQ_CB0_10_CDF_start_ptr,\r
-        SKP_Silk_NLSF_MSVQ_CB0_10_CDF_middle_idx\r
-};\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/**********************************************/
+/* This file has been automatically generated */
+/*                                            */
+/* ROM usage:  0.29 + 2.66 kB                 */
+/**********************************************/
+
+#include "SKP_Silk_structs.h"
+#include "SKP_Silk_tables_NLSF_CB0_10.h"
+#include "SKP_Silk_tables.h"
+
+const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB0_10_CDF[ NLSF_MSVQ_CB0_10_VECTORS + NLSF_MSVQ_CB0_10_STAGES ] =
+{
+            0,
+         2658,
+         4420,
+         6107,
+         7757,
+         9408,
+        10955,
+        12502,
+        13983,
+        15432,
+        16882,
+        18331,
+        19750,
+        21108,
+        22409,
+        23709,
+        25010,
+        26256,
+        27501,
+        28747,
+        29965,
+        31158,
+        32351,
+        33544,
+        34736,
+        35904,
+        36997,
+        38091,
+        39185,
+        40232,
+        41280,
+        42327,
+        43308,
+        44290,
+        45271,
+        46232,
+        47192,
+        48132,
+        49032,
+        49913,
+        50775,
+        51618,
+        52462,
+        53287,
+        54095,
+        54885,
+        55675,
+        56449,
+        57222,
+        57979,
+        58688,
+        59382,
+        60076,
+        60726,
+        61363,
+        61946,
+        62505,
+        63052,
+        63543,
+        63983,
+        64396,
+        64766,
+        65023,
+        65279,
+        65535,
+            0,
+         4977,
+         9542,
+        14106,
+        18671,
+        23041,
+        27319,
+        31596,
+        35873,
+        39969,
+        43891,
+        47813,
+        51652,
+        55490,
+        59009,
+        62307,
+        65535,
+            0,
+         8571,
+        17142,
+        25529,
+        33917,
+        42124,
+        49984,
+        57844,
+        65535,
+            0,
+         8732,
+        17463,
+        25825,
+        34007,
+        42189,
+        50196,
+        58032,
+        65535,
+            0,
+         8948,
+        17704,
+        25733,
+        33762,
+        41791,
+        49821,
+        57678,
+        65535,
+            0,
+         4374,
+         8655,
+        12936,
+        17125,
+        21313,
+        25413,
+        29512,
+        33611,
+        37710,
+        41809,
+        45820,
+        49832,
+        53843,
+        57768,
+        61694,
+        65535
+};
+
+const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB0_10_CDF_start_ptr[ NLSF_MSVQ_CB0_10_STAGES ] =
+{
+     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[   0 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[  65 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[  82 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[  91 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[ 100 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_10_CDF[ 109 ]
+};
+
+const SKP_int SKP_Silk_NLSF_MSVQ_CB0_10_CDF_middle_idx[ NLSF_MSVQ_CB0_10_STAGES ] =
+{
+      23,
+       8,
+       5,
+       5,
+       5,
+       9
+};
+
+const SKP_int16 SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[ NLSF_MSVQ_CB0_10_VECTORS ] =
+{
+              148,              167,
+              169,              170,
+              170,              173,
+              173,              175,
+              176,              176,
+              176,              177,
+              179,              181,
+              181,              181,
+              183,              183,
+              183,              184,
+              185,              185,
+              185,              185,
+              186,              189,
+              189,              189,
+              191,              191,
+              191,              194,
+              194,              194,
+              195,              195,
+              196,              198,
+              199,              200,
+              201,              201,
+              202,              203,
+              204,              204,
+              205,              205,
+              206,              209,
+              210,              210,
+              213,              214,
+              218,              220,
+              221,              226,
+              231,              234,
+              239,              256,
+              256,              256,
+              119,              123,
+              123,              123,
+              125,              126,
+              126,              126,
+              128,              130,
+              130,              131,
+              131,              135,
+              138,              139,
+               94,               94,
+               95,               95,
+               96,               98,
+               98,               99,
+               93,               93,
+               95,               96,
+               96,               97,
+               98,              100,
+               92,               93,
+               97,               97,
+               97,               97,
+               98,               98,
+              125,              126,
+              126,              127,
+              127,              128,
+              128,              128,
+              128,              128,
+              129,              129,
+              129,              130,
+              130,              131
+};
+
+const SKP_int SKP_Silk_NLSF_MSVQ_CB0_10_ndelta_min_Q15[ 10 + 1 ] =
+{
+              563,
+                3,
+               22,
+               20,
+                3,
+                3,
+              132,
+              119,
+              358,
+               86,
+              964
+};
+
+const SKP_int16 SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 * NLSF_MSVQ_CB0_10_VECTORS ] =
+{
+             2210,             4023,
+             6981,             9260,
+            12573,            15687,
+            19207,            22383,
+            25981,            29142,
+             3285,             4172,
+             6116,            10856,
+            15289,            16826,
+            19701,            22010,
+            24721,            29313,
+             1554,             2511,
+             6577,            10337,
+            13837,            16511,
+            20086,            23214,
+            26480,            29464,
+             3062,             4017,
+             5771,            10037,
+            13365,            14952,
+            20140,            22891,
+            25229,            29603,
+             2085,             3457,
+             5934,             8718,
+            11501,            13670,
+            17997,            21817,
+            24935,            28745,
+             2776,             4093,
+             6421,            10413,
+            15111,            16806,
+            20825,            23826,
+            26308,            29411,
+             2717,             4034,
+             5697,             8463,
+            14301,            16354,
+            19007,            23413,
+            25812,            28506,
+             2872,             3702,
+             5881,            11034,
+            17141,            18879,
+            21146,            23451,
+            25817,            29600,
+             2999,             4015,
+             7357,            11219,
+            12866,            17307,
+            20081,            22644,
+            26774,            29107,
+             2942,             3866,
+             5918,            11915,
+            13909,            16072,
+            20453,            22279,
+            27310,            29826,
+             2271,             3527,
+             6606,             9729,
+            12943,            17382,
+            20224,            22345,
+            24602,            28290,
+             2207,             3310,
+             5844,             9339,
+            11141,            15651,
+            18576,            21177,
+            25551,            28228,
+             3963,             4975,
+             6901,            11588,
+            13466,            15577,
+            19231,            21368,
+            25510,            27759,
+             2749,             3549,
+             6966,            13808,
+            15653,            17645,
+            20090,            22599,
+            26467,            28537,
+             2126,             3504,
+             5109,             9954,
+            12550,            14620,
+            19703,            21687,
+            26457,            29106,
+             3966,             5745,
+             7442,             9757,
+            14468,            16404,
+            19135,            23048,
+            25375,            28391,
+             3197,             4751,
+             6451,             9298,
+            13038,            14874,
+            17962,            20627,
+            23835,            28464,
+             3195,             4081,
+             6499,            12252,
+            14289,            16040,
+            18357,            20730,
+            26980,            29309,
+             1533,             2471,
+             4486,             7796,
+            12332,            15758,
+            19567,            22298,
+            25673,            29051,
+             2002,             2971,
+             4985,             8083,
+            13181,            15435,
+            18237,            21517,
+            24595,            28351,
+             3808,             4925,
+             6710,            10201,
+            12011,            14300,
+            18457,            20391,
+            26525,            28956,
+             2281,             3418,
+             4979,             8726,
+            15964,            18104,
+            20250,            22771,
+            25286,            28954,
+             3051,             5479,
+             7290,             9848,
+            12744,            14503,
+            18665,            23684,
+            26065,            28947,
+             2364,             3565,
+             5502,             9621,
+            14922,            16621,
+            19005,            20996,
+            26310,            29302,
+             4093,             5212,
+             6833,             9880,
+            16303,            18286,
+            20571,            23614,
+            26067,            29128,
+             2941,             3996,
+             6038,            10638,
+            12668,            14451,
+            16798,            19392,
+            26051,            28517,
+             3863,             5212,
+             7019,             9468,
+            11039,            13214,
+            19942,            22344,
+            25126,            29539,
+             4615,             6172,
+             7853,            10252,
+            12611,            14445,
+            19719,            22441,
+            24922,            29341,
+             3566,             4512,
+             6985,             8684,
+            10544,            16097,
+            18058,            22475,
+            26066,            28167,
+             4481,             5489,
+             7432,            11414,
+            13191,            15225,
+            20161,            22258,
+            26484,            29716,
+             3320,             4320,
+             6621,             9867,
+            11581,            14034,
+            21168,            23210,
+            26588,            29903,
+             3794,             4689,
+             6916,             8655,
+            10143,            16144,
+            19568,            21588,
+            27557,            29593,
+             2446,             3276,
+             5918,            12643,
+            16601,            18013,
+            21126,            23175,
+            27300,            29634,
+             2450,             3522,
+             5437,             8560,
+            15285,            19911,
+            21826,            24097,
+            26567,            29078,
+             2580,             3796,
+             5580,             8338,
+             9969,            12675,
+            18907,            22753,
+            25450,            29292,
+             3325,             4312,
+             6241,             7709,
+             9164,            14452,
+            21665,            23797,
+            27096,            29857,
+             3338,             4163,
+             7738,            11114,
+            12668,            14753,
+            16931,            22736,
+            25671,            28093,
+             3840,             4755,
+             7755,            13471,
+            15338,            17180,
+            20077,            22353,
+            27181,            29743,
+             2504,             4079,
+             8351,            12118,
+            15046,            18595,
+            21684,            24704,
+            27519,            29937,
+             5234,             6342,
+             8267,            11821,
+            15155,            16760,
+            20667,            23488,
+            25949,            29307,
+             2681,             3562,
+             6028,            10827,
+            18458,            20458,
+            22303,            24701,
+            26912,            29956,
+             3374,             4528,
+             6230,             8256,
+             9513,            12730,
+            18666,            20720,
+            26007,            28425,
+             2731,             3629,
+             8320,            12450,
+            14112,            16431,
+            18548,            22098,
+            25329,            27718,
+             3481,             4401,
+             7321,             9319,
+            11062,            13093,
+            15121,            22315,
+            26331,            28740,
+             3577,             4945,
+             6669,             8792,
+            10299,            12645,
+            19505,            24766,
+            26996,            29634,
+             4058,             5060,
+             7288,            10190,
+            11724,            13936,
+            15849,            18539,
+            26701,            29845,
+             4262,             5390,
+             7057,             8982,
+            10187,            15264,
+            20480,            22340,
+            25958,            28072,
+             3404,             4329,
+             6629,             7946,
+            10121,            17165,
+            19640,            22244,
+            25062,            27472,
+             3157,             4168,
+             6195,             9319,
+            10771,            13325,
+            15416,            19816,
+            24672,            27634,
+             2503,             3473,
+             5130,             6767,
+             8571,            14902,
+            19033,            21926,
+            26065,            28728,
+             4133,             5102,
+             7553,            10054,
+            11757,            14924,
+            17435,            20186,
+            23987,            26272,
+             4972,             6139,
+             7894,             9633,
+            11320,            14295,
+            21737,            24306,
+            26919,            29907,
+             2958,             3816,
+             6851,             9204,
+            10895,            18052,
+            20791,            23338,
+            27556,            29609,
+             5234,             6028,
+             8034,            10154,
+            11242,            14789,
+            18948,            20966,
+            26585,            29127,
+             5241,             6838,
+            10526,            12819,
+            14681,            17328,
+            19928,            22336,
+            26193,            28697,
+             3412,             4251,
+             5988,             7094,
+             9907,            18243,
+            21669,            23777,
+            26969,            29087,
+             2470,             3217,
+             7797,            15296,
+            17365,            19135,
+            21979,            24256,
+            27322,            29442,
+             4939,             5804,
+             8145,            11809,
+            13873,            15598,
+            17234,            19423,
+            26476,            29645,
+             5051,             6167,
+             8223,             9655,
+            12159,            17995,
+            20464,            22832,
+            26616,            28462,
+             4987,             5907,
+             9319,            11245,
+            13132,            15024,
+            17485,            22687,
+            26011,            28273,
+             5137,             6884,
+            11025,            14950,
+            17191,            19425,
+            21807,            24393,
+            26938,            29288,
+             7057,             7884,
+             9528,            10483,
+            10960,            14811,
+            19070,            21675,
+            25645,            28019,
+             6759,             7160,
+             8546,            11779,
+            12295,            13023,
+            16627,            21099,
+            24697,            28287,
+             3863,             9762,
+            11068,            11445,
+            12049,            13960,
+            18085,            21507,
+            25224,            28997,
+              397,              335,
+              651,             1168,
+              640,              765,
+              465,              331,
+              214,             -194,
+             -578,             -647,
+             -657,              750,
+              564,              613,
+              549,              630,
+              304,              -52,
+              828,              922,
+              443,              111,
+              138,              124,
+              169,               14,
+              144,               83,
+              132,               58,
+             -413,             -752,
+              869,              336,
+              385,               69,
+               56,              830,
+             -227,             -266,
+             -368,             -440,
+            -1195,              163,
+              126,             -228,
+              802,              156,
+              188,              120,
+              376,               59,
+             -358,             -558,
+            -1326,             -254,
+             -202,             -789,
+              296,               92,
+              -70,             -129,
+             -718,            -1135,
+              292,              -29,
+             -631,              487,
+             -157,             -153,
+             -279,                2,
+             -419,             -342,
+              -34,             -514,
+             -799,            -1571,
+             -687,             -609,
+             -546,             -130,
+             -215,             -252,
+             -446,             -574,
+            -1337,              207,
+              -72,               32,
+              103,             -642,
+              942,              733,
+              187,               29,
+             -211,             -814,
+              143,              225,
+               20,               24,
+             -268,             -377,
+             1623,             1133,
+              667,              164,
+              307,              366,
+              187,               34,
+               62,             -313,
+             -832,            -1482,
+            -1181,              483,
+              -42,              -39,
+             -450,            -1406,
+             -587,              -52,
+             -760,              334,
+               98,              -60,
+             -500,             -488,
+            -1058,              299,
+              131,             -250,
+             -251,             -703,
+             1037,              568,
+             -413,             -265,
+             1687,              573,
+              345,              323,
+               98,               61,
+             -102,               31,
+              135,              149,
+              617,              365,
+              -39,               34,
+             -611,             1201,
+             1421,              736,
+             -414,             -393,
+             -492,             -343,
+             -316,             -532,
+              528,              172,
+               90,              322,
+             -294,             -319,
+             -541,              503,
+              639,              401,
+                1,             -149,
+              -73,             -167,
+              150,              118,
+              308,              218,
+              121,              195,
+             -143,             -261,
+            -1013,             -802,
+              387,              436,
+              130,             -427,
+             -448,             -681,
+              123,              -87,
+             -251,             -113,
+              274,              310,
+              445,              501,
+              354,              272,
+              141,             -285,
+              569,              656,
+               37,              -49,
+              251,             -386,
+             -263,             1122,
+              604,              606,
+              336,               95,
+               34,                0,
+               85,              180,
+              207,             -367,
+             -622,             1070,
+               -6,              -79,
+             -160,              -92,
+             -137,             -276,
+             -323,             -371,
+             -696,            -1036,
+              407,              102,
+              -86,             -214,
+             -482,             -647,
+              -28,             -291,
+              -97,             -180,
+             -250,             -435,
+              -18,              -76,
+             -332,              410,
+              407,              168,
+              539,              411,
+              254,              111,
+               58,             -145,
+              200,               30,
+              187,              116,
+              131,             -367,
+             -475,              781,
+             -559,              561,
+              195,             -115,
+                8,             -168,
+               30,               55,
+             -122,              131,
+               82,               -5,
+             -273,              -50,
+             -632,              668,
+                4,               32,
+              -26,             -279,
+              315,              165,
+              197,              377,
+              155,              -41,
+             -138,             -324,
+             -109,             -617,
+              360,               98,
+              -53,             -319,
+             -114,             -245,
+              -82,              507,
+              468,              263,
+             -137,             -389,
+              652,              354,
+              -18,             -227,
+             -462,             -135,
+              317,               53,
+              -16,               66,
+              -72,             -126,
+             -356,             -347,
+             -328,              -72,
+             -337,              324,
+              152,              349,
+              169,             -196,
+              179,              254,
+              260,              325,
+              -74,              -80,
+               75,              -31,
+              270,              275,
+               87,              278,
+             -446,             -301,
+              309,               71,
+              -25,             -242,
+              516,              161,
+             -162,              -83,
+              329,              230,
+             -311,             -259,
+              177,              -26,
+             -462,               89,
+              257,                6,
+             -130,              -93,
+             -456,             -317,
+             -221,             -206,
+             -417,             -182,
+              -74,              234,
+               48,              261,
+              359,              231,
+              258,               85,
+             -282,              252,
+             -147,             -222,
+              251,             -207,
+              443,              123,
+             -417,              -36,
+              273,             -241,
+              240,             -112,
+               44,             -167,
+              126,             -124,
+              -77,               58,
+             -401,              333,
+             -118,               82,
+              126,              151,
+             -433,              359,
+             -130,             -102,
+              131,             -244,
+               86,               85,
+             -462,              414,
+             -240,               16,
+              145,               28,
+             -205,             -481,
+              373,              293,
+              -72,             -174,
+               62,              259,
+               -8,              -18,
+              362,              233,
+              185,               43,
+              278,               27,
+              193,              570,
+             -248,              189,
+               92,               31,
+             -275,               -3,
+              243,              176,
+              438,              209,
+              206,              -51,
+               79,              109,
+              168,             -185,
+             -308,              -68,
+             -618,              385,
+             -310,             -108,
+             -164,              165,
+               61,             -152,
+             -101,             -412,
+             -268,             -257,
+              -40,              -20,
+              -28,             -158,
+             -301,              271,
+              380,             -338,
+             -367,             -132,
+               64,              114,
+             -131,             -225,
+             -156,             -260,
+              -63,             -116,
+              155,             -586,
+             -202,              254,
+             -287,              178,
+              227,             -106,
+             -294,              164,
+              298,             -100,
+              185,              317,
+              193,              -45,
+               28,               80,
+              -87,             -433,
+               22,              -48,
+               48,             -237,
+             -229,             -139,
+              120,             -364,
+              268,             -136,
+              396,              125,
+              130,              -89,
+             -272,              118,
+             -256,              -68,
+             -451,              488,
+              143,             -165,
+              -48,             -190,
+              106,              219,
+               47,              435,
+              245,               97,
+               75,             -418,
+              121,             -187,
+              570,             -200,
+             -351,              225,
+              -21,             -217,
+              234,             -111,
+              194,               14,
+              242,              118,
+              140,             -397,
+              355,              361,
+              -45,             -195
+};
+
+const SKP_Silk_NLSF_CBS SKP_Silk_NLSF_CB0_10_Stage_info[ NLSF_MSVQ_CB0_10_STAGES ] =
+{
+        {  64, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 *   0 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[   0 ] },
+        {  16, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 *  64 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[  64 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 *  80 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[  80 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 *  88 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[  88 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 *  96 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[  96 ] },
+        {  16, &SKP_Silk_NLSF_MSVQ_CB0_10_Q15[ 10 * 104 ], &SKP_Silk_NLSF_MSVQ_CB0_10_rates_Q5[ 104 ] }
+};
+
+const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_10 =
+{
+        NLSF_MSVQ_CB0_10_STAGES,
+        SKP_Silk_NLSF_CB0_10_Stage_info,
+        SKP_Silk_NLSF_MSVQ_CB0_10_ndelta_min_Q15,
+        SKP_Silk_NLSF_MSVQ_CB0_10_CDF,
+        SKP_Silk_NLSF_MSVQ_CB0_10_CDF_start_ptr,
+        SKP_Silk_NLSF_MSVQ_CB0_10_CDF_middle_idx
+};
+
index 6a72cba3e94b9a1b67f0b13ded59588780ae03c0..f2b51b2e2e17e725df12ee96b377ba5fed8d3baa 100644 (file)
@@ -1,51 +1,51 @@
-/***********************************************************************\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
-#ifndef SKP_SILK_TABLES_NLSF_CB0_10_H\r
-#define SKP_SILK_TABLES_NLSF_CB0_10_H\r
-\r
-#include "SKP_Silk_define.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-#define NLSF_MSVQ_CB0_10_STAGES       6\r
-#define NLSF_MSVQ_CB0_10_VECTORS      120\r
-\r
-/* NLSF codebook entropy coding tables */\r
-extern const SKP_uint16         SKP_Silk_NLSF_MSVQ_CB0_10_CDF[ NLSF_MSVQ_CB0_10_VECTORS + NLSF_MSVQ_CB0_10_STAGES ];\r
-extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB0_10_CDF_start_ptr[                  NLSF_MSVQ_CB0_10_STAGES ];\r
-extern const SKP_int            SKP_Silk_NLSF_MSVQ_CB0_10_CDF_middle_idx[                 NLSF_MSVQ_CB0_10_STAGES ];\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_TABLES_NLSF_CB0_10_H
+#define SKP_SILK_TABLES_NLSF_CB0_10_H
+
+#include "SKP_Silk_define.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define NLSF_MSVQ_CB0_10_STAGES       6
+#define NLSF_MSVQ_CB0_10_VECTORS      120
+
+/* NLSF codebook entropy coding tables */
+extern const SKP_uint16         SKP_Silk_NLSF_MSVQ_CB0_10_CDF[ NLSF_MSVQ_CB0_10_VECTORS + NLSF_MSVQ_CB0_10_STAGES ];
+extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB0_10_CDF_start_ptr[                  NLSF_MSVQ_CB0_10_STAGES ];
+extern const SKP_int            SKP_Silk_NLSF_MSVQ_CB0_10_CDF_middle_idx[                 NLSF_MSVQ_CB0_10_STAGES ];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
index 2491ec9d83390c49b4645d5cf5acc147b0bdff48..1825d71563a0c9af8efeb4fcadf91cd1df0c24c5 100644 (file)
-/***********************************************************************\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
-/* This file has been automatically generated */\r
-/*                                            */\r
-/* ROM usage:  0.51 + 7.38 kB                 */\r
-/**********************************************/\r
-\r
-#include "SKP_Silk_structs.h"\r
-#include "SKP_Silk_tables_NLSF_CB0_16.h"\r
-#include "SKP_Silk_tables.h"\r
-\r
-const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ NLSF_MSVQ_CB0_16_VECTORS + NLSF_MSVQ_CB0_16_STAGES ] =\r
-{\r
-            0,\r
-         1449,\r
-         2749,\r
-         4022,\r
-         5267,\r
-         6434,\r
-         7600,\r
-         8647,\r
-         9695,\r
-        10742,\r
-        11681,\r
-        12601,\r
-        13444,\r
-        14251,\r
-        15008,\r
-        15764,\r
-        16521,\r
-        17261,\r
-        18002,\r
-        18710,\r
-        19419,\r
-        20128,\r
-        20837,\r
-        21531,\r
-        22225,\r
-        22919,\r
-        23598,\r
-        24277,\r
-        24956,\r
-        25620,\r
-        26256,\r
-        26865,\r
-        27475,\r
-        28071,\r
-        28667,\r
-        29263,\r
-        29859,\r
-        30443,\r
-        31026,\r
-        31597,\r
-        32168,\r
-        32727,\r
-        33273,\r
-        33808,\r
-        34332,\r
-        34855,\r
-        35379,\r
-        35902,\r
-        36415,\r
-        36927,\r
-        37439,\r
-        37941,\r
-        38442,\r
-        38932,\r
-        39423,\r
-        39914,\r
-        40404,\r
-        40884,\r
-        41364,\r
-        41844,\r
-        42324,\r
-        42805,\r
-        43285,\r
-        43754,\r
-        44224,\r
-        44694,\r
-        45164,\r
-        45623,\r
-        46083,\r
-        46543,\r
-        46993,\r
-        47443,\r
-        47892,\r
-        48333,\r
-        48773,\r
-        49213,\r
-        49653,\r
-        50084,\r
-        50515,\r
-        50946,\r
-        51377,\r
-        51798,\r
-        52211,\r
-        52614,\r
-        53018,\r
-        53422,\r
-        53817,\r
-        54212,\r
-        54607,\r
-        55002,\r
-        55388,\r
-        55775,\r
-        56162,\r
-        56548,\r
-        56910,\r
-        57273,\r
-        57635,\r
-        57997,\r
-        58352,\r
-        58698,\r
-        59038,\r
-        59370,\r
-        59702,\r
-        60014,\r
-        60325,\r
-        60630,\r
-        60934,\r
-        61239,\r
-        61537,\r
-        61822,\r
-        62084,\r
-        62346,\r
-        62602,\r
-        62837,\r
-        63072,\r
-        63302,\r
-        63517,\r
-        63732,\r
-        63939,\r
-        64145,\r
-        64342,\r
-        64528,\r
-        64701,\r
-        64867,\r
-        65023,\r
-        65151,\r
-        65279,\r
-        65407,\r
-        65535,\r
-            0,\r
-         5099,\r
-         9982,\r
-        14760,\r
-        19538,\r
-        24213,\r
-        28595,\r
-        32976,\r
-        36994,\r
-        41012,\r
-        44944,\r
-        48791,\r
-        52557,\r
-        56009,\r
-        59388,\r
-        62694,\r
-        65535,\r
-            0,\r
-         9955,\r
-        19697,\r
-        28825,\r
-        36842,\r
-        44686,\r
-        52198,\r
-        58939,\r
-        65535,\r
-            0,\r
-         8949,\r
-        17335,\r
-        25720,\r
-        33926,\r
-        41957,\r
-        49987,\r
-        57845,\r
-        65535,\r
-            0,\r
-         9724,\r
-        18642,\r
-        26998,\r
-        35355,\r
-        43532,\r
-        51534,\r
-        59365,\r
-        65535,\r
-            0,\r
-         8750,\r
-        17499,\r
-        26249,\r
-        34448,\r
-        42471,\r
-        50494,\r
-        58178,\r
-        65535,\r
-            0,\r
-         8730,\r
-        17273,\r
-        25816,\r
-        34176,\r
-        42536,\r
-        50203,\r
-        57869,\r
-        65535,\r
-            0,\r
-         8769,\r
-        17538,\r
-        26307,\r
-        34525,\r
-        42742,\r
-        50784,\r
-        58319,\r
-        65535,\r
-            0,\r
-         8736,\r
-        17101,\r
-        25466,\r
-        33653,\r
-        41839,\r
-        50025,\r
-        57864,\r
-        65535,\r
-            0,\r
-         4368,\r
-         8735,\r
-        12918,\r
-        17100,\r
-        21283,\r
-        25465,\r
-        29558,\r
-        33651,\r
-        37744,\r
-        41836,\r
-        45929,\r
-        50022,\r
-        54027,\r
-        57947,\r
-        61782,\r
-        65535\r
-};\r
-\r
-const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB0_16_CDF_start_ptr[ NLSF_MSVQ_CB0_16_STAGES ] =\r
-{\r
-     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[   0 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 129 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 146 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 155 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 164 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 173 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 182 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 191 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 200 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 209 ]\r
-};\r
-\r
-const SKP_int SKP_Silk_NLSF_MSVQ_CB0_16_CDF_middle_idx[ NLSF_MSVQ_CB0_16_STAGES ] =\r
-{\r
-      42,\r
-       8,\r
-       4,\r
-       5,\r
-       5,\r
-       5,\r
-       5,\r
-       5,\r
-       5,\r
-       9\r
-};\r
-\r
-const SKP_int16 SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ NLSF_MSVQ_CB0_16_VECTORS ] =\r
-{\r
-              176,              181,\r
-              182,              183,\r
-              186,              186,\r
-              191,              191,\r
-              191,              196,\r
-              197,              201,\r
-              203,              206,\r
-              206,              206,\r
-              207,              207,\r
-              209,              209,\r
-              209,              209,\r
-              210,              210,\r
-              210,              211,\r
-              211,              211,\r
-              212,              214,\r
-              216,              216,\r
-              217,              217,\r
-              217,              217,\r
-              218,              218,\r
-              219,              219,\r
-              220,              221,\r
-              222,              223,\r
-              223,              223,\r
-              223,              224,\r
-              224,              224,\r
-              225,              225,\r
-              226,              226,\r
-              226,              226,\r
-              227,              227,\r
-              227,              227,\r
-              227,              227,\r
-              228,              228,\r
-              228,              228,\r
-              229,              229,\r
-              229,              230,\r
-              230,              230,\r
-              231,              231,\r
-              231,              231,\r
-              232,              232,\r
-              232,              232,\r
-              233,              234,\r
-              235,              235,\r
-              235,              236,\r
-              236,              236,\r
-              236,              237,\r
-              237,              237,\r
-              237,              240,\r
-              240,              240,\r
-              240,              241,\r
-              242,              243,\r
-              244,              244,\r
-              247,              247,\r
-              248,              248,\r
-              248,              249,\r
-              251,              255,\r
-              255,              256,\r
-              260,              260,\r
-              261,              264,\r
-              264,              266,\r
-              266,              268,\r
-              271,              274,\r
-              276,              279,\r
-              288,              288,\r
-              288,              288,\r
-              118,              120,\r
-              121,              121,\r
-              122,              125,\r
-              125,              129,\r
-              129,              130,\r
-              131,              132,\r
-              136,              137,\r
-              138,              145,\r
-               87,               88,\r
-               91,               97,\r
-               98,              100,\r
-              105,              106,\r
-               92,               95,\r
-               95,               96,\r
-               97,               97,\r
-               98,               99,\r
-               88,               92,\r
-               95,               95,\r
-               96,               97,\r
-               98,              109,\r
-               93,               93,\r
-               93,               96,\r
-               97,               97,\r
-               99,              101,\r
-               93,               94,\r
-               94,               95,\r
-               95,               99,\r
-               99,               99,\r
-               93,               93,\r
-               93,               96,\r
-               96,               97,\r
-              100,              102,\r
-               93,               95,\r
-               95,               96,\r
-               96,               96,\r
-               98,               99,\r
-              125,              125,\r
-              127,              127,\r
-              127,              127,\r
-              128,              128,\r
-              128,              128,\r
-              128,              128,\r
-              129,              130,\r
-              131,              132\r
-};\r
-\r
-const SKP_int SKP_Silk_NLSF_MSVQ_CB0_16_ndelta_min_Q15[ 16 + 1 ] =\r
-{\r
-              266,\r
-                3,\r
-               40,\r
-                3,\r
-                3,\r
-               16,\r
-               78,\r
-               89,\r
-              107,\r
-              141,\r
-              188,\r
-              146,\r
-              272,\r
-              240,\r
-              235,\r
-              215,\r
-              632\r
-};\r
-\r
-const SKP_int16 SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * NLSF_MSVQ_CB0_16_VECTORS ] =\r
-{\r
-             1170,             2278,             3658,             5374,\r
-             7666,             9113,            11298,            13304,\r
-            15371,            17549,            19587,            21487,\r
-            23798,            26038,            28318,            30201,\r
-             1628,             2334,             4115,             6036,\r
-             7818,             9544,            11777,            14021,\r
-            15787,            17408,            19466,            21261,\r
-            22886,            24565,            26714,            28059,\r
-             1724,             2670,             4056,             6532,\r
-             8357,            10119,            12093,            14061,\r
-            16491,            18795,            20417,            22402,\r
-            24251,            26224,            28410,            29956,\r
-             1493,             3427,             4789,             6399,\r
-             8435,            10168,            12000,            14066,\r
-            16229,            18210,            20040,            22098,\r
-            24153,            26095,            28183,            30121,\r
-             1119,             2089,             4295,             6245,\r
-             8691,            10741,            12688,            15057,\r
-            17028,            18792,            20717,            22514,\r
-            24497,            26548,            28619,            30630,\r
-             1363,             2417,             3927,             5556,\r
-             7422,             9315,            11879,            13767,\r
-            16143,            18520,            20458,            22578,\r
-            24539,            26436,            28318,            30318,\r
-             1122,             2503,             5216,             7148,\r
-             9310,            11078,            13175,            14800,\r
-            16864,            18700,            20436,            22488,\r
-            24572,            26602,            28555,            30426,\r
-              600,             1317,             2970,             5609,\r
-             7694,             9784,            12169,            14087,\r
-            16379,            18378,            20551,            22686,\r
-            24739,            26697,            28646,            30355,\r
-              941,             1882,             4274,             5540,\r
-             8482,             9858,            11940,            14287,\r
-            16091,            18501,            20326,            22612,\r
-            24711,            26638,            28814,            30430,\r
-              635,             1699,             4376,             5948,\r
-             8097,            10115,            12274,            14178,\r
-            16111,            17813,            19695,            21773,\r
-            23927,            25866,            28022,            30134,\r
-             1408,             2222,             3524,             5615,\r
-             7345,             8849,            10989,            12772,\r
-            15352,            17026,            18919,            21062,\r
-            23329,            25215,            27209,            29023,\r
-              701,             1307,             3548,             6301,\r
-             7744,             9574,            11227,            12978,\r
-            15170,            17565,            19775,            22097,\r
-            24230,            26335,            28377,            30231,\r
-             1752,             2364,             4879,             6569,\r
-             7813,             9796,            11199,            14290,\r
-            15795,            18000,            20396,            22417,\r
-            24308,            26124,            28360,            30633,\r
-              901,             1629,             3356,             4635,\r
-             7256,             8767,             9971,            11558,\r
-            15215,            17544,            19523,            21852,\r
-            23900,            25978,            28133,            30184,\r
-              981,             1669,             3323,             4693,\r
-             6213,             8692,            10614,            12956,\r
-            15211,            17711,            19856,            22122,\r
-            24344,            26592,            28723,            30481,\r
-             1607,             2577,             4220,             5512,\r
-             8532,            10388,            11627,            13671,\r
-            15752,            17199,            19840,            21859,\r
-            23494,            25786,            28091,            30131,\r
-              811,             1471,             3144,             5041,\r
-             7430,             9389,            11174,            13255,\r
-            15157,            16741,            19583,            22167,\r
-            24115,            26142,            28383,            30395,\r
-             1543,             2144,             3629,             6347,\r
-             7333,             9339,            10710,            13596,\r
-            15099,            17340,            20102,            21886,\r
-            23732,            25637,            27818,            29917,\r
-              492,             1185,             2940,             5488,\r
-             7095,             8751,            11596,            13579,\r
-            16045,            18015,            20178,            22127,\r
-            24265,            26406,            28484,            30357,\r
-             1547,             2282,             3693,             6341,\r
-             7758,             9607,            11848,            13236,\r
-            16564,            18069,            19759,            21404,\r
-            24110,            26606,            28786,            30655,\r
-              685,             1338,             3409,             5262,\r
-             6950,             9222,            11414,            14523,\r
-            16337,            17893,            19436,            21298,\r
-            23293,            25181,            27973,            30520,\r
-              887,             1581,             3057,             4318,\r
-             7192,             8617,            10047,            13106,\r
-            16265,            17893,            20233,            22350,\r
-            24379,            26384,            28314,            30189,\r
-             2285,             3745,             5662,             7576,\r
-             9323,            11320,            13239,            15191,\r
-            17175,            19225,            21108,            22972,\r
-            24821,            26655,            28561,            30460,\r
-             1496,             2108,             3448,             6898,\r
-             8328,             9656,            11252,            12823,\r
-            14979,            16482,            18180,            20085,\r
-            22962,            25160,            27705,            29629,\r
-              575,             1261,             3861,             6627,\r
-             8294,            10809,            12705,            14768,\r
-            17076,            19047,            20978,            23055,\r
-            24972,            26703,            28720,            30345,\r
-             1682,             2213,             3882,             6238,\r
-             7208,             9646,            10877,            13431,\r
-            14805,            16213,            17941,            20873,\r
-            23550,            25765,            27756,            29461,\r
-              888,             1616,             3924,             5195,\r
-             7206,             8647,             9842,            11473,\r
-            16067,            18221,            20343,            22774,\r
-            24503,            26412,            28054,            29731,\r
-              805,             1454,             2683,             4472,\r
-             7936,             9360,            11398,            14345,\r
-            16205,            17832,            19453,            21646,\r
-            23899,            25928,            28387,            30463,\r
-             1640,             2383,             3484,             5082,\r
-             6032,             8606,            11640,            12966,\r
-            15842,            17368,            19346,            21182,\r
-            23638,            25889,            28368,            30299,\r
-             1632,             2204,             4510,             7580,\r
-             8718,            10512,            11962,            14096,\r
-            15640,            17194,            19143,            22247,\r
-            24563,            26561,            28604,            30509,\r
-             2043,             2612,             3985,             6851,\r
-             8038,             9514,            10979,            12789,\r
-            15426,            16728,            18899,            20277,\r
-            22902,            26209,            28711,            30618,\r
-             2224,             2798,             4465,             5320,\r
-             7108,             9436,            10986,            13222,\r
-            14599,            18317,            20141,            21843,\r
-            23601,            25700,            28184,            30582,\r
-              835,             1541,             4083,             5769,\r
-             7386,             9399,            10971,            12456,\r
-            15021,            18642,            20843,            23100,\r
-            25292,            26966,            28952,            30422,\r
-             1795,             2343,             4809,             5896,\r
-             7178,             8545,            10223,            13370,\r
-            14606,            16469,            18273,            20736,\r
-            23645,            26257,            28224,            30390,\r
-             1734,             2254,             4031,             5188,\r
-             6506,             7872,             9651,            13025,\r
-            14419,            17305,            19495,            22190,\r
-            24403,            26302,            28195,            30177,\r
-             1841,             2349,             3968,             4764,\r
-             6376,             9825,            11048,            13345,\r
-            14682,            16252,            18183,            21363,\r
-            23918,            26156,            28031,            29935,\r
-             1432,             2047,             5631,             6927,\r
-             8198,             9675,            11358,            13506,\r
-            14802,            16419,            18339,            22019,\r
-            24124,            26177,            28130,            30586,\r
-             1730,             2320,             3744,             4808,\r
-             6007,             9666,            10997,            13622,\r
-            15234,            17495,            20088,            22002,\r
-            23603,            25400,            27379,            29254,\r
-             1267,             1915,             5483,             6812,\r
-             8229,             9919,            11589,            13337,\r
-            14747,            17965,            20552,            22167,\r
-            24519,            26819,            28883,            30642,\r
-             1526,             2229,             4240,             7388,\r
-             8953,            10450,            11899,            13718,\r
-            16861,            18323,            20379,            22672,\r
-            24797,            26906,            28906,            30622,\r
-             2175,             2791,             4104,             6875,\r
-             8612,             9798,            12152,            13536,\r
-            15623,            17682,            19213,            21060,\r
-            24382,            26760,            28633,            30248,\r
-              454,             1231,             4339,             5738,\r
-             7550,             9006,            10320,            13525,\r
-            16005,            17849,            20071,            21992,\r
-            23949,            26043,            28245,            30175,\r
-             2250,             2791,             4230,             5283,\r
-             6762,            10607,            11879,            13821,\r
-            15797,            17264,            20029,            22266,\r
-            24588,            26437,            28244,            30419,\r
-             1696,             2216,             4308,             8385,\r
-             9766,            11030,            12556,            14099,\r
-            16322,            17640,            19166,            20590,\r
-            23967,            26858,            28798,            30562,\r
-             2452,             3236,             4369,             6118,\r
-             7156,             9003,            11509,            12796,\r
-            15749,            17291,            19491,            22241,\r
-            24530,            26474,            28273,            30073,\r
-             1811,             2541,             3555,             5480,\r
-             9123,            10527,            11894,            13659,\r
-            15262,            16899,            19366,            21069,\r
-            22694,            24314,            27256,            29983,\r
-             1553,             2246,             4559,             5500,\r
-             6754,             7874,            11739,            13571,\r
-            15188,            17879,            20281,            22510,\r
-            24614,            26649,            28786,            30755,\r
-             1982,             2768,             3834,             5964,\r
-             8732,             9908,            11797,            14813,\r
-            16311,            17946,            21097,            22851,\r
-            24456,            26304,            28166,            29755,\r
-             1824,             2529,             3817,             5449,\r
-             6854,             8714,            10381,            12286,\r
-            14194,            15774,            19524,            21374,\r
-            23695,            26069,            28096,            30212,\r
-             2212,             2854,             3947,             5898,\r
-             9930,            11556,            12854,            14788,\r
-            16328,            17700,            20321,            22098,\r
-            23672,            25291,            26976,            28586,\r
-             2023,             2599,             4024,             4916,\r
-             6613,            11149,            12457,            14626,\r
-            16320,            17822,            19673,            21172,\r
-            23115,            26051,            28825,            30758,\r
-             1628,             2206,             3467,             4364,\r
-             8679,            10173,            11864,            13679,\r
-            14998,            16938,            19207,            21364,\r
-            23850,            26115,            28124,            30273,\r
-             2014,             2603,             4114,             7254,\r
-             8516,            10043,            11822,            13503,\r
-            16329,            17826,            19697,            21280,\r
-            23151,            24661,            26807,            30161,\r
-             2376,             2980,             4422,             5770,\r
-             7016,             9723,            11125,            13516,\r
-            15485,            16985,            19160,            20587,\r
-            24401,            27180,            29046,            30647,\r
-             2454,             3502,             4624,             6019,\r
-             7632,             8849,            10792,            13964,\r
-            15523,            17085,            19611,            21238,\r
-            22856,            25108,            28106,            29890,\r
-             1573,             2274,             3308,             5999,\r
-             8977,            10104,            12457,            14258,\r
-            15749,            18180,            19974,            21253,\r
-            23045,            25058,            27741,            30315,\r
-             1943,             2730,             4140,             6160,\r
-             7491,             8986,            11309,            12775,\r
-            14820,            16558,            17909,            19757,\r
-            21512,            23605,            27274,            29527,\r
-             2021,             2582,             4494,             5835,\r
-             6993,             8245,             9827,            14733,\r
-            16462,            17894,            19647,            21083,\r
-            23764,            26667,            29072,            30990,\r
-             1052,             1775,             3218,             4378,\r
-             7666,             9403,            11248,            13327,\r
-            14972,            17962,            20758,            22354,\r
-            25071,            27209,            29001,            30609,\r
-             2218,             2866,             4223,             5352,\r
-             6581,             9980,            11587,            13121,\r
-            15193,            16583,            18386,            20080,\r
-            22013,            25317,            28127,            29880,\r
-             2146,             2840,             4397,             5840,\r
-             7449,             8721,            10512,            11936,\r
-            13595,            17253,            19310,            20891,\r
-            23417,            25627,            27749,            30231,\r
-             1972,             2619,             3756,             6367,\r
-             7641,             8814,            12286,            13768,\r
-            15309,            18036,            19557,            20904,\r
-            22582,            24876,            27800,            30440,\r
-             2005,             2577,             4272,             7373,\r
-             8558,            10223,            11770,            13402,\r
-            16502,            18000,            19645,            21104,\r
-            22990,            26806,            29505,            30942,\r
-             1153,             1822,             3724,             5443,\r
-             6990,             8702,            10289,            11899,\r
-            13856,            15315,            17601,            21064,\r
-            23692,            26083,            28586,            30639,\r
-             1304,             1869,             3318,             7195,\r
-             9613,            10733,            12393,            13728,\r
-            15822,            17474,            18882,            20692,\r
-            23114,            25540,            27684,            29244,\r
-             2093,             2691,             4018,             6658,\r
-             7947,             9147,            10497,            11881,\r
-            15888,            17821,            19333,            21233,\r
-            23371,            25234,            27553,            29998,\r
-              575,             1331,             5304,             6910,\r
-             8425,            10086,            11577,            13498,\r
-            16444,            18527,            20565,            22847,\r
-            24914,            26692,            28759,            30157,\r
-             1435,             2024,             3283,             4156,\r
-             7611,            10592,            12049,            13927,\r
-            15459,            18413,            20495,            22270,\r
-            24222,            26093,            28065,            30099,\r
-             1632,             2168,             5540,             7478,\r
-             8630,            10391,            11644,            14321,\r
-            15741,            17357,            18756,            20434,\r
-            22799,            26060,            28542,            30696,\r
-             1407,             2245,             3405,             5639,\r
-             9419,            10685,            12104,            13495,\r
-            15535,            18357,            19996,            21689,\r
-            24351,            26550,            28853,            30564,\r
-             1675,             2226,             4005,             8223,\r
-             9975,            11155,            12822,            14316,\r
-            16504,            18137,            19574,            21050,\r
-            22759,            24912,            28296,            30634,\r
-             1080,             1614,             3622,             7565,\r
-             8748,            10303,            11713,            13848,\r
-            15633,            17434,            19761,            21825,\r
-            23571,            25393,            27406,            29063,\r
-             1693,             2229,             3456,             4354,\r
-             5670,            10890,            12563,            14167,\r
-            15879,            17377,            19817,            21971,\r
-            24094,            26131,            28298,            30099,\r
-             2042,             2959,             4195,             5740,\r
-             7106,             8267,            11126,            14973,\r
-            16914,            18295,            20532,            21982,\r
-            23711,            25769,            27609,            29351,\r
-              984,             1612,             3808,             5265,\r
-             6885,             8411,             9547,            10889,\r
-            12522,            16520,            19549,            21639,\r
-            23746,            26058,            28310,            30374,\r
-             2036,             2538,             4166,             7761,\r
-             9146,            10412,            12144,            13609,\r
-            15588,            17169,            18559,            20113,\r
-            21820,            24313,            28029,            30612,\r
-             1871,             2355,             4061,             5143,\r
-             7464,            10129,            11941,            15001,\r
-            16680,            18354,            19957,            22279,\r
-            24861,            26872,            28988,            30615,\r
-             2566,             3161,             4643,             6227,\r
-             7406,             9970,            11618,            13416,\r
-            15889,            17364,            19121,            20817,\r
-            22592,            24720,            28733,            31082,\r
-             1700,             2327,             4828,             5939,\r
-             7567,             9154,            11087,            12771,\r
-            14209,            16121,            20222,            22671,\r
-            24648,            26656,            28696,            30745,\r
-             3169,             3873,             5046,             6868,\r
-             8184,             9480,            12335,            14068,\r
-            15774,            17971,            20231,            21711,\r
-            23520,            25245,            27026,            28730,\r
-             1564,             2391,             4229,             6730,\r
-             8905,            10459,            13026,            15033,\r
-            17265,            19809,            21849,            23741,\r
-            25490,            27312,            29061,            30527,\r
-             2864,             3559,             4719,             6441,\r
-             9592,            11055,            12763,            14784,\r
-            16428,            18164,            20486,            22262,\r
-            24183,            26263,            28383,            30224,\r
-             2673,             3449,             4581,             5983,\r
-             6863,             8311,            12464,            13911,\r
-            15738,            17791,            19416,            21182,\r
-            24025,            26561,            28723,            30440,\r
-             2419,             3049,             4274,             6384,\r
-             8564,             9661,            11288,            12676,\r
-            14447,            17578,            19816,            21231,\r
-            23099,            25270,            26899,            28926,\r
-             1278,             2001,             3000,             5353,\r
-             9995,            11777,            13018,            14570,\r
-            16050,            17762,            19982,            21617,\r
-            23371,            25083,            27656,            30172,\r
-              932,             1624,             2798,             4570,\r
-             8592,             9988,            11552,            13050,\r
-            16921,            18677,            20415,            22810,\r
-            24817,            26819,            28804,            30385,\r
-             2324,             2973,             4156,             5702,\r
-             6919,             8806,            10259,            12503,\r
-            15015,            16567,            19418,            21375,\r
-            22943,            24550,            27024,            29849,\r
-             1564,             2373,             3455,             4907,\r
-             5975,             7436,            11786,            14505,\r
-            16107,            18148,            20019,            21653,\r
-            23740,            25814,            28578,            30372,\r
-             3025,             3729,             4866,             6520,\r
-             9487,            10943,            12358,            14258,\r
-            16174,            17501,            19476,            21408,\r
-            23227,            24906,            27347,            29407,\r
-             1270,             1965,             6802,             7995,\r
-             9204,            10828,            12507,            14230,\r
-            15759,            17860,            20369,            22502,\r
-            24633,            26514,            28535,            30525,\r
-             2210,             2749,             4266,             7487,\r
-             9878,            11018,            12823,            14431,\r
-            16247,            18626,            20450,            22054,\r
-            23739,            25291,            27074,            29169,\r
-             1275,             1926,             4330,             6573,\r
-             8441,            10920,            13260,            15008,\r
-            16927,            18573,            20644,            22217,\r
-            23983,            25474,            27372,            28645,\r
-             3015,             3670,             5086,             6372,\r
-             7888,             9309,            10966,            12642,\r
-            14495,            16172,            18080,            19972,\r
-            22454,            24899,            27362,            29975,\r
-             2882,             3733,             5113,             6482,\r
-             8125,             9685,            11598,            13288,\r
-            15405,            17192,            20178,            22426,\r
-            24801,            27014,            29212,            30811,\r
-             2300,             2968,             4101,             5442,\r
-             6327,             7910,            12455,            13862,\r
-            15747,            17505,            19053,            20679,\r
-            22615,            24658,            27499,            30065,\r
-             2257,             2940,             4430,             5991,\r
-             7042,             8364,             9414,            11224,\r
-            15723,            17420,            19253,            21469,\r
-            23915,            26053,            28430,            30384,\r
-             1227,             2045,             3818,             5011,\r
-             6990,             9231,            11024,            13011,\r
-            17341,            19017,            20583,            22799,\r
-            25195,            26876,            29351,            30805,\r
-             1354,             1924,             3789,             8077,\r
-            10453,            11639,            13352,            14817,\r
-            16743,            18189,            20095,            22014,\r
-            24593,            26677,            28647,            30256,\r
-             3142,             4049,             6197,             7417,\r
-             8753,            10156,            11533,            13181,\r
-            15947,            17655,            19606,            21402,\r
-            23487,            25659,            28123,            30304,\r
-             1317,             2263,             4725,             7611,\r
-             9667,            11634,            14143,            16258,\r
-            18724,            20698,            22379,            24007,\r
-            25775,            27251,            28930,            30593,\r
-             1570,             2323,             3818,             6215,\r
-             9893,            11556,            13070,            14631,\r
-            16152,            18290,            21386,            23346,\r
-            25114,            26923,            28712,            30168,\r
-             2297,             3905,             6287,             8558,\r
-            10668,            12766,            15019,            17102,\r
-            19036,            20677,            22341,            23871,\r
-            25478,            27085,            28851,            30520,\r
-             1915,             2507,             4033,             5749,\r
-             7059,             8871,            10659,            12198,\r
-            13937,            15383,            16869,            18707,\r
-            23175,            25818,            28514,            30501,\r
-             2404,             2918,             5190,             6252,\r
-             7426,             9887,            12387,            14795,\r
-            16754,            18368,            20338,            22003,\r
-            24236,            26456,            28490,            30397,\r
-             1621,             2227,             3479,             5085,\r
-             9425,            12892,            14246,            15652,\r
-            17205,            18674,            20446,            22209,\r
-            23778,            25867,            27931,            30093,\r
-             1869,             2390,             4105,             7021,\r
-            11221,            12775,            14059,            15590,\r
-            17024,            18608,            20595,            22075,\r
-            23649,            25154,            26914,            28671,\r
-             2551,             3252,             4688,             6562,\r
-             7869,             9125,            10475,            11800,\r
-            15402,            18780,            20992,            22555,\r
-            24289,            25968,            27465,            29232,\r
-             2705,             3493,             4735,             6360,\r
-             7905,             9352,            11538,            13430,\r
-            15239,            16919,            18619,            20094,\r
-            21800,            23342,            25200,            29257,\r
-             2166,             2791,             4011,             5081,\r
-             5896,             9038,            13407,            14703,\r
-            16543,            18189,            19896,            21857,\r
-            24872,            26971,            28955,            30514,\r
-             1865,             3021,             4696,             6534,\r
-             8343,             9914,            12789,            14103,\r
-            16533,            17729,            21340,            22439,\r
-            24873,            26330,            28428,            30154,\r
-             3369,             4345,             6573,             8763,\r
-            10309,            11713,            13367,            14784,\r
-            16483,            18145,            19839,            21247,\r
-            23292,            25477,            27555,            29447,\r
-             1265,             2184,             5443,             7893,\r
-            10591,            13139,            15105,            16639,\r
-            18402,            19826,            21419,            22995,\r
-            24719,            26437,            28363,            30125,\r
-             1584,             2004,             3535,             4450,\r
-             8662,            10764,            12832,            14978,\r
-            16972,            18794,            20932,            22547,\r
-            24636,            26521,            28701,            30567,\r
-             3419,             4528,             6602,             7890,\r
-             9508,            10875,            12771,            14357,\r
-            16051,            18330,            20630,            22490,\r
-            25070,            26936,            28946,            30542,\r
-             1726,             2252,             4597,             6950,\r
-             8379,             9823,            11363,            12794,\r
-            14306,            15476,            16798,            18018,\r
-            21671,            25550,            28148,            30367,\r
-             3385,             3870,             5307,             6388,\r
-             7141,             8684,            12695,            14939,\r
-            16480,            18277,            20537,            22048,\r
-            23947,            25965,            28214,            29956,\r
-             2771,             3306,             4450,             5560,\r
-             6453,             9493,            13548,            14754,\r
-            16743,            18447,            20028,            21736,\r
-            23746,            25353,            27141,            29066,\r
-             3028,             3900,             6617,             7893,\r
-             9211,            10480,            12047,            13583,\r
-            15182,            16662,            18502,            20092,\r
-            22190,            24358,            26302,            28957,\r
-             2000,             2550,             4067,             6837,\r
-             9628,            11002,            12594,            14098,\r
-            15589,            17195,            18679,            20099,\r
-            21530,            23085,            24641,            29022,\r
-             2844,             3302,             5103,             6107,\r
-             6911,             8598,            12416,            14054,\r
-            16026,            18567,            20672,            22270,\r
-            23952,            25771,            27658,            30026,\r
-             4043,             5150,             7268,             9056,\r
-            10916,            12638,            14543,            16184,\r
-            17948,            19691,            21357,            22981,\r
-            24825,            26591,            28479,            30233,\r
-             2109,             2625,             4320,             5525,\r
-             7454,            10220,            12980,            14698,\r
-            17627,            19263,            20485,            22381,\r
-            24279,            25777,            27847,            30458,\r
-             1550,             2667,             6473,             9496,\r
-            10985,            12352,            13795,            15233,\r
-            17099,            18642,            20461,            22116,\r
-            24197,            26291,            28403,            30132,\r
-             2411,             3084,             4145,             5394,\r
-             6367,             8154,            13125,            16049,\r
-            17561,            19125,            21258,            22762,\r
-            24459,            26317,            28255,            29702,\r
-             4159,             4516,             5956,             7635,\r
-             8254,             8980,            11208,            14133,\r
-            16210,            17875,            20196,            21864,\r
-            23840,            25747,            28058,            30012,\r
-             2026,             2431,             2845,             3618,\r
-             7950,             9802,            12721,            14460,\r
-            16576,            18984,            21376,            23319,\r
-            24961,            26718,            28971,            30640,\r
-             3429,             3833,             4472,             4912,\r
-             7723,            10386,            12981,            15322,\r
-            16699,            18807,            20778,            22551,\r
-            24627,            26494,            28334,            30482,\r
-             4740,             5169,             5796,             6485,\r
-             6998,             8830,            11777,            14414,\r
-            16831,            18413,            20789,            22369,\r
-            24236,            25835,            27807,            30021,\r
-              150,              168,              -17,             -107,\r
-             -142,             -229,             -320,             -406,\r
-             -503,             -620,             -867,             -935,\r
-             -902,             -680,             -398,             -114,\r
-             -398,             -355,               49,              255,\r
-              114,              260,              399,              264,\r
-              317,              431,              514,              531,\r
-              435,              356,              238,              106,\r
-              -43,              -36,             -169,             -224,\r
-             -391,             -633,             -776,             -970,\r
-             -844,             -455,             -181,              -12,\r
-               85,               85,              164,              195,\r
-              122,               85,             -158,             -640,\r
-             -903,                9,                7,             -124,\r
-              149,               32,              220,              369,\r
-              242,              115,               79,               84,\r
-             -146,             -216,              -70,             1024,\r
-              751,              574,              440,              377,\r
-              352,              203,               30,               16,\r
-               -3,               81,              161,              100,\r
-             -148,             -176,              933,              750,\r
-              404,              171,               -2,             -146,\r
-             -411,             -442,             -541,             -552,\r
-             -442,             -269,             -240,              -52,\r
-              603,              635,              405,              178,\r
-              215,               19,             -153,             -167,\r
-             -290,             -219,              151,              271,\r
-              151,              119,              303,              266,\r
-              100,               69,             -293,             -657,\r
-              939,              659,              442,              351,\r
-              132,               98,              -16,               -1,\r
-             -135,             -200,             -223,              -89,\r
-              167,              154,              172,              237,\r
-              -45,             -183,             -228,             -486,\r
-              263,              608,              158,             -125,\r
-             -390,             -227,             -118,               43,\r
-             -457,             -392,             -769,             -840,\r
-               20,             -117,             -194,             -189,\r
-             -173,             -173,              -33,               32,\r
-              174,              144,              115,              167,\r
-               57,               44,               14,              147,\r
-               96,              -54,             -142,             -129,\r
-             -254,             -331,              304,              310,\r
-              -52,             -419,             -846,            -1060,\r
-              -88,             -123,             -202,             -343,\r
-             -554,             -961,             -951,              327,\r
-              159,               81,              255,              227,\r
-              120,              203,              256,              192,\r
-              164,              224,              290,              195,\r
-              216,              209,              128,              832,\r
-             1028,              889,              698,              504,\r
-              408,              355,              218,               32,\r
-             -115,              -84,             -276,             -100,\r
-             -312,             -484,              899,              682,\r
-              465,              456,              241,              -12,\r
-             -275,             -425,             -461,             -367,\r
-              -33,              -28,             -102,             -194,\r
-             -527,              863,              906,              463,\r
-              245,               13,             -212,             -305,\r
-             -105,              163,              279,              176,\r
-               93,               67,              115,              192,\r
-               61,              -50,             -132,             -175,\r
-             -224,             -271,             -629,             -252,\r
-             1158,              972,              638,              280,\r
-              300,              326,              143,             -152,\r
-             -214,             -287,               53,              -42,\r
-             -236,             -352,             -423,             -248,\r
-             -129,             -163,             -178,             -119,\r
-               85,               57,              514,              382,\r
-              374,              402,              424,              423,\r
-              271,              197,               97,               40,\r
-               39,              -97,             -191,             -164,\r
-             -230,             -256,             -410,              396,\r
-              327,              127,               10,             -119,\r
-             -167,             -291,             -274,             -141,\r
-              -99,             -226,             -218,             -139,\r
-             -224,             -209,             -268,             -442,\r
-             -413,              222,               58,              521,\r
-              344,              258,               76,              -42,\r
-             -142,             -165,             -123,              -92,\r
-               47,                8,               -3,             -191,\r
-              -11,             -164,             -167,             -351,\r
-             -740,              311,              538,              291,\r
-              184,               29,             -105,                9,\r
-              -30,              -54,              -17,              -77,\r
-             -271,             -412,             -622,             -648,\r
-              476,              186,              -66,             -197,\r
-              -73,              -94,              -15,               47,\r
-               28,              112,              -58,              -33,\r
-               65,               19,               84,               86,\r
-              276,              114,              472,              786,\r
-              799,              625,              415,              178,\r
-              -35,              -26,                5,                9,\r
-               83,               39,               37,               39,\r
-             -184,             -374,             -265,             -362,\r
-             -501,              337,              716,              478,\r
-              -60,             -125,             -163,              362,\r
-               17,             -122,             -233,              279,\r
-              138,              157,              318,              193,\r
-              189,              209,              266,              252,\r
-              -46,              -56,             -277,             -429,\r
-              464,              386,              142,               44,\r
-              -43,               66,              264,              182,\r
-               47,               14,              -26,              -79,\r
-               49,               15,             -128,             -203,\r
-             -400,             -478,              325,               27,\r
-              234,              411,              205,              129,\r
-               12,               58,              123,               57,\r
-              171,              137,               96,              128,\r
-              -32,              134,              -12,               57,\r
-              119,               26,              -22,             -165,\r
-             -500,             -701,             -528,             -116,\r
-               64,               -8,               97,               -9,\r
-             -162,              -66,             -156,             -194,\r
-             -303,             -546,             -341,              546,\r
-              358,               95,               45,               76,\r
-              270,              403,              205,              100,\r
-              123,               50,              -53,             -144,\r
-             -110,              -13,               32,             -228,\r
-             -130,              353,              296,               56,\r
-             -372,             -253,              365,               73,\r
-               10,              -34,             -139,             -191,\r
-              -96,                5,               44,              -85,\r
-             -179,             -129,             -192,             -246,\r
-              -85,             -110,             -155,              -44,\r
-              -27,              145,              138,               79,\r
-               32,             -148,             -577,             -634,\r
-              191,               94,               -9,              -35,\r
-              -77,              -84,              -56,             -171,\r
-             -298,             -271,             -243,             -156,\r
-             -328,             -235,              -76,             -128,\r
-             -121,              129,               13,              -22,\r
-               32,               45,             -248,              -65,\r
-              193,              -81,              299,               57,\r
-             -147,              192,             -165,             -354,\r
-             -334,             -106,             -156,              -40,\r
-               -3,              -68,              124,             -257,\r
-               78,              124,              170,              412,\r
-              227,              105,             -104,               12,\r
-              154,              250,              274,              258,\r
-                4,              -27,              235,              152,\r
-               51,              338,              300,                7,\r
-             -314,             -411,              215,              170,\r
-               -9,              -93,              -77,               76,\r
-               67,               54,              200,              315,\r
-              163,               72,              -91,             -402,\r
-              158,              187,             -156,              -91,\r
-              290,              267,              167,               91,\r
-              140,              171,              112,                9,\r
-              -42,             -177,             -440,              385,\r
-               80,               15,              172,              129,\r
-               41,             -129,             -372,              -24,\r
-              -75,              -30,             -170,               10,\r
-             -118,               57,               78,             -101,\r
-              232,              161,              123,              256,\r
-              277,              101,             -192,             -629,\r
-             -100,              -60,             -232,               66,\r
-               13,              -13,              -80,             -239,\r
-              239,               37,               32,               89,\r
-             -319,             -579,              450,              360,\r
-                3,              -29,             -299,              -89,\r
-              -54,             -110,             -246,             -164,\r
-                6,             -188,              338,              176,\r
-              -92,              197,              137,              134,\r
-               12,               -2,               56,             -183,\r
-              114,              -36,             -131,             -204,\r
-               75,              -25,             -174,              191,\r
-              -15,             -290,             -429,             -267,\r
-               79,               37,              106,               23,\r
-             -384,              425,               70,              -14,\r
-              212,              105,               15,               -2,\r
-              -42,              -37,             -123,              108,\r
-               28,              -48,              193,              197,\r
-              173,              -33,               37,               73,\r
-              -57,              256,              137,              -58,\r
-             -430,             -228,              217,              -51,\r
-              -10,              -58,               -6,               22,\r
-              104,               61,             -119,              169,\r
-              144,               16,              -46,             -394,\r
-               60,              454,              -80,             -298,\r
-              -65,               25,                0,              -24,\r
-              -65,             -417,              465,              276,\r
-               -3,             -194,              -13,              130,\r
-               19,               -6,              -21,              -24,\r
-             -180,              -53,              -85,               20,\r
-              118,              147,              113,              -75,\r
-             -289,              226,             -122,              227,\r
-              270,              125,              109,              197,\r
-              125,              138,               44,               60,\r
-               25,              -55,             -167,              -32,\r
-             -139,             -193,             -173,             -316,\r
-              287,             -208,              253,              239,\r
-               27,              -80,             -188,              -28,\r
-             -182,             -235,              156,             -117,\r
-              128,              -48,              -58,             -226,\r
-              172,              181,              167,               19,\r
-               62,               10,                2,              181,\r
-              151,              108,              -16,              -11,\r
-              -78,             -331,              411,              133,\r
-               17,              104,               64,             -184,\r
-               24,              -30,               -3,             -283,\r
-              121,              204,               -8,             -199,\r
-              -21,              -80,             -169,             -157,\r
-             -191,             -136,               81,              155,\r
-               14,             -131,              244,               74,\r
-              -57,              -47,             -280,              347,\r
-              111,              -77,             -128,             -142,\r
-             -194,             -125,               -6,              -68,\r
-               91,                1,               23,               14,\r
-             -154,              -34,               23,              -38,\r
-             -343,              503,              146,              -38,\r
-              -46,              -41,               58,               31,\r
-               63,              -48,             -117,               45,\r
-               28,                1,              -89,               -5,\r
-              -44,              -29,             -448,              487,\r
-              204,               81,               46,             -106,\r
-             -302,              380,              120,              -38,\r
-              -12,              -39,               70,               -3,\r
-               25,              -65,               30,              -11,\r
-               34,              -15,               22,             -115,\r
-                0,              -79,              -83,               45,\r
-              114,               43,              150,               36,\r
-              233,              149,              195,                5,\r
-               25,              -52,             -475,              274,\r
-               28,              -39,               -8,              -66,\r
-             -255,              258,               56,              143,\r
-              -45,             -190,              165,              -60,\r
-               20,                2,              125,             -129,\r
-               51,               -8,             -335,              288,\r
-               38,               59,               25,              -42,\r
-               23,             -118,             -112,               11,\r
-              -55,             -133,             -109,               24,\r
-             -105,               78,              -64,             -245,\r
-              202,              -65,             -127,              162,\r
-               40,              -94,               89,              -85,\r
-             -119,             -103,               97,                9,\r
-              -70,              -28,              194,               86,\r
-             -112,              -92,             -114,               74,\r
-              -49,               46,              -84,             -178,\r
-              113,               52,             -205,              333,\r
-               88,              222,               56,              -55,\r
-               13,               86,                4,              -77,\r
-              224,              114,             -105,              112,\r
-              125,              -29,              -18,             -144,\r
-               22,              -58,              -99,               28,\r
-              114,              -66,              -32,             -169,\r
-             -314,              285,               72,              -74,\r
-              179,               28,              -79,             -182,\r
-               13,              -55,              147,               13,\r
-               12,              -54,               31,              -84,\r
-              -17,              -75,             -228,               83,\r
-             -375,              436,              110,              -63,\r
-              -27,             -136,              169,              -56,\r
-               -8,             -171,              184,              -42,\r
-              148,               68,              204,              235,\r
-              110,             -229,               91,              171,\r
-              -43,               -3,              -26,              -99,\r
-             -111,               71,             -170,              202,\r
-              -67,              181,              -37,              109,\r
-             -120,                3,              -55,             -260,\r
-              -16,              152,               91,              142,\r
-               42,               44,              134,               47,\r
-               17,              -35,               22,               79,\r
-             -169,               41,               46,              277,\r
-              -93,              -49,             -126,               37,\r
-             -103,              -34,              -22,              -90,\r
-             -134,             -205,               92,               -9,\r
-                1,             -195,             -239,               45,\r
-               54,               18,              -23,               -1,\r
-              -80,              -98,              -20,             -261,\r
-              306,               72,               20,              -89,\r
-             -217,               11,                6,              -82,\r
-               89,               13,             -129,              -89,\r
-               83,              -71,              -55,              130,\r
-              -98,             -146,              -27,              -57,\r
-               53,              275,               17,              170,\r
-               -5,              -54,              132,              -64,\r
-               72,              160,             -125,             -168,\r
-               72,               40,              170,               78,\r
-              248,              116,               20,               84,\r
-               31,              -34,              190,               38,\r
-               13,             -106,              225,               27,\r
-             -168,               24,             -157,             -122,\r
-              165,               11,             -161,             -213,\r
-              -12,              -51,             -101,               42,\r
-              101,               27,               55,              111,\r
-               75,               71,              -96,               -1,\r
-               65,             -277,              393,              -26,\r
-              -44,              -68,              -84,              -66,\r
-              -95,              235,              179,              -25,\r
-              -41,               27,              -91,             -128,\r
-             -222,              146,              -72,              -30,\r
-              -24,               55,             -126,              -68,\r
-              -58,             -127,               13,              -97,\r
-             -106,              174,             -100,              155,\r
-              101,             -146,              -21,              261,\r
-               22,               38,              -66,               65,\r
-                4,               70,               64,              144,\r
-               59,              213,               71,             -337,\r
-              303,              -52,               51,              -56,\r
-                1,               10,              -15,               -5,\r
-               34,               52,              228,              131,\r
-              161,             -127,             -214,              238,\r
-              123,               64,             -147,              -50,\r
-              -34,             -127,              204,              162,\r
-               85,               41,                5,             -140,\r
-               73,             -150,               56,              -96,\r
-              -66,              -20,                2,             -235,\r
-               59,              -22,             -107,              150,\r
-              -16,              -47,               -4,               81,\r
-              -67,              167,              149,              149,\r
-             -157,              288,             -156,              -27,\r
-               -8,               18,               83,              -24,\r
-              -41,             -167,              158,             -100,\r
-               93,               53,              201,               15,\r
-               42,              266,              278,              -12,\r
-               -6,              -37,               85,                6,\r
-               20,             -188,             -271,              107,\r
-              -13,              -80,               51,              202,\r
-              173,              -69,               78,             -188,\r
-               46,                4,              153,               12,\r
-             -138,              169,                5,              -58,\r
-             -123,             -108,             -243,              150,\r
-               10,             -191,              246,              -15,\r
-               38,               25,              -10,               14,\r
-               61,               50,             -206,             -215,\r
-             -220,               90,                5,             -149,\r
-             -219,               56,              142,               24,\r
-             -376,               77,              -80,               75,\r
-                6,               42,             -101,               16,\r
-               56,               14,              -57,                3,\r
-              -17,               80,               57,              -36,\r
-               88,              -59,              -97,              -19,\r
-             -148,               46,             -219,              226,\r
-              114,               -4,              -72,              -15,\r
-               37,              -49,              -28,              247,\r
-               44,              123,               47,             -122,\r
-              -38,               17,                4,             -113,\r
-              -32,             -224,              154,             -134,\r
-              196,               71,             -267,              -85,\r
-               28,              -70,               89,             -120,\r
-               99,               -2,               64,               76,\r
-             -166,              -48,              189,              -35,\r
-              -92,             -169,             -123,              339,\r
-               38,              -25,               38,              -35,\r
-              225,             -139,              -50,              -63,\r
-              246,               60,             -185,             -109,\r
-              -49,              -53,             -167,               51,\r
-              149,               60,             -101,              -33,\r
-               25,              -76,              120,               32,\r
-              -30,              -83,              102,               91,\r
-             -186,             -261,              131,             -197\r
-};\r
-\r
-const SKP_Silk_NLSF_CBS SKP_Silk_NLSF_CB0_16_Stage_info[ NLSF_MSVQ_CB0_16_STAGES ] =\r
-{\r
-        { 128, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 *   0 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[   0 ] },\r
-        {  16, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 128 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 128 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 144 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 144 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 152 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 152 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 160 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 160 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 168 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 168 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 176 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 176 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 184 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 184 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 192 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 192 ] },\r
-        {  16, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 200 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 200 ] }\r
-};\r
-\r
-const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_16 =\r
-{\r
-        NLSF_MSVQ_CB0_16_STAGES,\r
-        SKP_Silk_NLSF_CB0_16_Stage_info,\r
-        SKP_Silk_NLSF_MSVQ_CB0_16_ndelta_min_Q15,\r
-        SKP_Silk_NLSF_MSVQ_CB0_16_CDF,\r
-        SKP_Silk_NLSF_MSVQ_CB0_16_CDF_start_ptr,\r
-        SKP_Silk_NLSF_MSVQ_CB0_16_CDF_middle_idx\r
-};\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/**********************************************/
+/* This file has been automatically generated */
+/*                                            */
+/* ROM usage:  0.51 + 7.38 kB                 */
+/**********************************************/
+
+#include "SKP_Silk_structs.h"
+#include "SKP_Silk_tables_NLSF_CB0_16.h"
+#include "SKP_Silk_tables.h"
+
+const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ NLSF_MSVQ_CB0_16_VECTORS + NLSF_MSVQ_CB0_16_STAGES ] =
+{
+            0,
+         1449,
+         2749,
+         4022,
+         5267,
+         6434,
+         7600,
+         8647,
+         9695,
+        10742,
+        11681,
+        12601,
+        13444,
+        14251,
+        15008,
+        15764,
+        16521,
+        17261,
+        18002,
+        18710,
+        19419,
+        20128,
+        20837,
+        21531,
+        22225,
+        22919,
+        23598,
+        24277,
+        24956,
+        25620,
+        26256,
+        26865,
+        27475,
+        28071,
+        28667,
+        29263,
+        29859,
+        30443,
+        31026,
+        31597,
+        32168,
+        32727,
+        33273,
+        33808,
+        34332,
+        34855,
+        35379,
+        35902,
+        36415,
+        36927,
+        37439,
+        37941,
+        38442,
+        38932,
+        39423,
+        39914,
+        40404,
+        40884,
+        41364,
+        41844,
+        42324,
+        42805,
+        43285,
+        43754,
+        44224,
+        44694,
+        45164,
+        45623,
+        46083,
+        46543,
+        46993,
+        47443,
+        47892,
+        48333,
+        48773,
+        49213,
+        49653,
+        50084,
+        50515,
+        50946,
+        51377,
+        51798,
+        52211,
+        52614,
+        53018,
+        53422,
+        53817,
+        54212,
+        54607,
+        55002,
+        55388,
+        55775,
+        56162,
+        56548,
+        56910,
+        57273,
+        57635,
+        57997,
+        58352,
+        58698,
+        59038,
+        59370,
+        59702,
+        60014,
+        60325,
+        60630,
+        60934,
+        61239,
+        61537,
+        61822,
+        62084,
+        62346,
+        62602,
+        62837,
+        63072,
+        63302,
+        63517,
+        63732,
+        63939,
+        64145,
+        64342,
+        64528,
+        64701,
+        64867,
+        65023,
+        65151,
+        65279,
+        65407,
+        65535,
+            0,
+         5099,
+         9982,
+        14760,
+        19538,
+        24213,
+        28595,
+        32976,
+        36994,
+        41012,
+        44944,
+        48791,
+        52557,
+        56009,
+        59388,
+        62694,
+        65535,
+            0,
+         9955,
+        19697,
+        28825,
+        36842,
+        44686,
+        52198,
+        58939,
+        65535,
+            0,
+         8949,
+        17335,
+        25720,
+        33926,
+        41957,
+        49987,
+        57845,
+        65535,
+            0,
+         9724,
+        18642,
+        26998,
+        35355,
+        43532,
+        51534,
+        59365,
+        65535,
+            0,
+         8750,
+        17499,
+        26249,
+        34448,
+        42471,
+        50494,
+        58178,
+        65535,
+            0,
+         8730,
+        17273,
+        25816,
+        34176,
+        42536,
+        50203,
+        57869,
+        65535,
+            0,
+         8769,
+        17538,
+        26307,
+        34525,
+        42742,
+        50784,
+        58319,
+        65535,
+            0,
+         8736,
+        17101,
+        25466,
+        33653,
+        41839,
+        50025,
+        57864,
+        65535,
+            0,
+         4368,
+         8735,
+        12918,
+        17100,
+        21283,
+        25465,
+        29558,
+        33651,
+        37744,
+        41836,
+        45929,
+        50022,
+        54027,
+        57947,
+        61782,
+        65535
+};
+
+const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB0_16_CDF_start_ptr[ NLSF_MSVQ_CB0_16_STAGES ] =
+{
+     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[   0 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 129 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 146 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 155 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 164 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 173 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 182 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 191 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 200 ],
+     &SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ 209 ]
+};
+
+const SKP_int SKP_Silk_NLSF_MSVQ_CB0_16_CDF_middle_idx[ NLSF_MSVQ_CB0_16_STAGES ] =
+{
+      42,
+       8,
+       4,
+       5,
+       5,
+       5,
+       5,
+       5,
+       5,
+       9
+};
+
+const SKP_int16 SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ NLSF_MSVQ_CB0_16_VECTORS ] =
+{
+              176,              181,
+              182,              183,
+              186,              186,
+              191,              191,
+              191,              196,
+              197,              201,
+              203,              206,
+              206,              206,
+              207,              207,
+              209,              209,
+              209,              209,
+              210,              210,
+              210,              211,
+              211,              211,
+              212,              214,
+              216,              216,
+              217,              217,
+              217,              217,
+              218,              218,
+              219,              219,
+              220,              221,
+              222,              223,
+              223,              223,
+              223,              224,
+              224,              224,
+              225,              225,
+              226,              226,
+              226,              226,
+              227,              227,
+              227,              227,
+              227,              227,
+              228,              228,
+              228,              228,
+              229,              229,
+              229,              230,
+              230,              230,
+              231,              231,
+              231,              231,
+              232,              232,
+              232,              232,
+              233,              234,
+              235,              235,
+              235,              236,
+              236,              236,
+              236,              237,
+              237,              237,
+              237,              240,
+              240,              240,
+              240,              241,
+              242,              243,
+              244,              244,
+              247,              247,
+              248,              248,
+              248,              249,
+              251,              255,
+              255,              256,
+              260,              260,
+              261,              264,
+              264,              266,
+              266,              268,
+              271,              274,
+              276,              279,
+              288,              288,
+              288,              288,
+              118,              120,
+              121,              121,
+              122,              125,
+              125,              129,
+              129,              130,
+              131,              132,
+              136,              137,
+              138,              145,
+               87,               88,
+               91,               97,
+               98,              100,
+              105,              106,
+               92,               95,
+               95,               96,
+               97,               97,
+               98,               99,
+               88,               92,
+               95,               95,
+               96,               97,
+               98,              109,
+               93,               93,
+               93,               96,
+               97,               97,
+               99,              101,
+               93,               94,
+               94,               95,
+               95,               99,
+               99,               99,
+               93,               93,
+               93,               96,
+               96,               97,
+              100,              102,
+               93,               95,
+               95,               96,
+               96,               96,
+               98,               99,
+              125,              125,
+              127,              127,
+              127,              127,
+              128,              128,
+              128,              128,
+              128,              128,
+              129,              130,
+              131,              132
+};
+
+const SKP_int SKP_Silk_NLSF_MSVQ_CB0_16_ndelta_min_Q15[ 16 + 1 ] =
+{
+              266,
+                3,
+               40,
+                3,
+                3,
+               16,
+               78,
+               89,
+              107,
+              141,
+              188,
+              146,
+              272,
+              240,
+              235,
+              215,
+              632
+};
+
+const SKP_int16 SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * NLSF_MSVQ_CB0_16_VECTORS ] =
+{
+             1170,             2278,             3658,             5374,
+             7666,             9113,            11298,            13304,
+            15371,            17549,            19587,            21487,
+            23798,            26038,            28318,            30201,
+             1628,             2334,             4115,             6036,
+             7818,             9544,            11777,            14021,
+            15787,            17408,            19466,            21261,
+            22886,            24565,            26714,            28059,
+             1724,             2670,             4056,             6532,
+             8357,            10119,            12093,            14061,
+            16491,            18795,            20417,            22402,
+            24251,            26224,            28410,            29956,
+             1493,             3427,             4789,             6399,
+             8435,            10168,            12000,            14066,
+            16229,            18210,            20040,            22098,
+            24153,            26095,            28183,            30121,
+             1119,             2089,             4295,             6245,
+             8691,            10741,            12688,            15057,
+            17028,            18792,            20717,            22514,
+            24497,            26548,            28619,            30630,
+             1363,             2417,             3927,             5556,
+             7422,             9315,            11879,            13767,
+            16143,            18520,            20458,            22578,
+            24539,            26436,            28318,            30318,
+             1122,             2503,             5216,             7148,
+             9310,            11078,            13175,            14800,
+            16864,            18700,            20436,            22488,
+            24572,            26602,            28555,            30426,
+              600,             1317,             2970,             5609,
+             7694,             9784,            12169,            14087,
+            16379,            18378,            20551,            22686,
+            24739,            26697,            28646,            30355,
+              941,             1882,             4274,             5540,
+             8482,             9858,            11940,            14287,
+            16091,            18501,            20326,            22612,
+            24711,            26638,            28814,            30430,
+              635,             1699,             4376,             5948,
+             8097,            10115,            12274,            14178,
+            16111,            17813,            19695,            21773,
+            23927,            25866,            28022,            30134,
+             1408,             2222,             3524,             5615,
+             7345,             8849,            10989,            12772,
+            15352,            17026,            18919,            21062,
+            23329,            25215,            27209,            29023,
+              701,             1307,             3548,             6301,
+             7744,             9574,            11227,            12978,
+            15170,            17565,            19775,            22097,
+            24230,            26335,            28377,            30231,
+             1752,             2364,             4879,             6569,
+             7813,             9796,            11199,            14290,
+            15795,            18000,            20396,            22417,
+            24308,            26124,            28360,            30633,
+              901,             1629,             3356,             4635,
+             7256,             8767,             9971,            11558,
+            15215,            17544,            19523,            21852,
+            23900,            25978,            28133,            30184,
+              981,             1669,             3323,             4693,
+             6213,             8692,            10614,            12956,
+            15211,            17711,            19856,            22122,
+            24344,            26592,            28723,            30481,
+             1607,             2577,             4220,             5512,
+             8532,            10388,            11627,            13671,
+            15752,            17199,            19840,            21859,
+            23494,            25786,            28091,            30131,
+              811,             1471,             3144,             5041,
+             7430,             9389,            11174,            13255,
+            15157,            16741,            19583,            22167,
+            24115,            26142,            28383,            30395,
+             1543,             2144,             3629,             6347,
+             7333,             9339,            10710,            13596,
+            15099,            17340,            20102,            21886,
+            23732,            25637,            27818,            29917,
+              492,             1185,             2940,             5488,
+             7095,             8751,            11596,            13579,
+            16045,            18015,            20178,            22127,
+            24265,            26406,            28484,            30357,
+             1547,             2282,             3693,             6341,
+             7758,             9607,            11848,            13236,
+            16564,            18069,            19759,            21404,
+            24110,            26606,            28786,            30655,
+              685,             1338,             3409,             5262,
+             6950,             9222,            11414,            14523,
+            16337,            17893,            19436,            21298,
+            23293,            25181,            27973,            30520,
+              887,             1581,             3057,             4318,
+             7192,             8617,            10047,            13106,
+            16265,            17893,            20233,            22350,
+            24379,            26384,            28314,            30189,
+             2285,             3745,             5662,             7576,
+             9323,            11320,            13239,            15191,
+            17175,            19225,            21108,            22972,
+            24821,            26655,            28561,            30460,
+             1496,             2108,             3448,             6898,
+             8328,             9656,            11252,            12823,
+            14979,            16482,            18180,            20085,
+            22962,            25160,            27705,            29629,
+              575,             1261,             3861,             6627,
+             8294,            10809,            12705,            14768,
+            17076,            19047,            20978,            23055,
+            24972,            26703,            28720,            30345,
+             1682,             2213,             3882,             6238,
+             7208,             9646,            10877,            13431,
+            14805,            16213,            17941,            20873,
+            23550,            25765,            27756,            29461,
+              888,             1616,             3924,             5195,
+             7206,             8647,             9842,            11473,
+            16067,            18221,            20343,            22774,
+            24503,            26412,            28054,            29731,
+              805,             1454,             2683,             4472,
+             7936,             9360,            11398,            14345,
+            16205,            17832,            19453,            21646,
+            23899,            25928,            28387,            30463,
+             1640,             2383,             3484,             5082,
+             6032,             8606,            11640,            12966,
+            15842,            17368,            19346,            21182,
+            23638,            25889,            28368,            30299,
+             1632,             2204,             4510,             7580,
+             8718,            10512,            11962,            14096,
+            15640,            17194,            19143,            22247,
+            24563,            26561,            28604,            30509,
+             2043,             2612,             3985,             6851,
+             8038,             9514,            10979,            12789,
+            15426,            16728,            18899,            20277,
+            22902,            26209,            28711,            30618,
+             2224,             2798,             4465,             5320,
+             7108,             9436,            10986,            13222,
+            14599,            18317,            20141,            21843,
+            23601,            25700,            28184,            30582,
+              835,             1541,             4083,             5769,
+             7386,             9399,            10971,            12456,
+            15021,            18642,            20843,            23100,
+            25292,            26966,            28952,            30422,
+             1795,             2343,             4809,             5896,
+             7178,             8545,            10223,            13370,
+            14606,            16469,            18273,            20736,
+            23645,            26257,            28224,            30390,
+             1734,             2254,             4031,             5188,
+             6506,             7872,             9651,            13025,
+            14419,            17305,            19495,            22190,
+            24403,            26302,            28195,            30177,
+             1841,             2349,             3968,             4764,
+             6376,             9825,            11048,            13345,
+            14682,            16252,            18183,            21363,
+            23918,            26156,            28031,            29935,
+             1432,             2047,             5631,             6927,
+             8198,             9675,            11358,            13506,
+            14802,            16419,            18339,            22019,
+            24124,            26177,            28130,            30586,
+             1730,             2320,             3744,             4808,
+             6007,             9666,            10997,            13622,
+            15234,            17495,            20088,            22002,
+            23603,            25400,            27379,            29254,
+             1267,             1915,             5483,             6812,
+             8229,             9919,            11589,            13337,
+            14747,            17965,            20552,            22167,
+            24519,            26819,            28883,            30642,
+             1526,             2229,             4240,             7388,
+             8953,            10450,            11899,            13718,
+            16861,            18323,            20379,            22672,
+            24797,            26906,            28906,            30622,
+             2175,             2791,             4104,             6875,
+             8612,             9798,            12152,            13536,
+            15623,            17682,            19213,            21060,
+            24382,            26760,            28633,            30248,
+              454,             1231,             4339,             5738,
+             7550,             9006,            10320,            13525,
+            16005,            17849,            20071,            21992,
+            23949,            26043,            28245,            30175,
+             2250,             2791,             4230,             5283,
+             6762,            10607,            11879,            13821,
+            15797,            17264,            20029,            22266,
+            24588,            26437,            28244,            30419,
+             1696,             2216,             4308,             8385,
+             9766,            11030,            12556,            14099,
+            16322,            17640,            19166,            20590,
+            23967,            26858,            28798,            30562,
+             2452,             3236,             4369,             6118,
+             7156,             9003,            11509,            12796,
+            15749,            17291,            19491,            22241,
+            24530,            26474,            28273,            30073,
+             1811,             2541,             3555,             5480,
+             9123,            10527,            11894,            13659,
+            15262,            16899,            19366,            21069,
+            22694,            24314,            27256,            29983,
+             1553,             2246,             4559,             5500,
+             6754,             7874,            11739,            13571,
+            15188,            17879,            20281,            22510,
+            24614,            26649,            28786,            30755,
+             1982,             2768,             3834,             5964,
+             8732,             9908,            11797,            14813,
+            16311,            17946,            21097,            22851,
+            24456,            26304,            28166,            29755,
+             1824,             2529,             3817,             5449,
+             6854,             8714,            10381,            12286,
+            14194,            15774,            19524,            21374,
+            23695,            26069,            28096,            30212,
+             2212,             2854,             3947,             5898,
+             9930,            11556,            12854,            14788,
+            16328,            17700,            20321,            22098,
+            23672,            25291,            26976,            28586,
+             2023,             2599,             4024,             4916,
+             6613,            11149,            12457,            14626,
+            16320,            17822,            19673,            21172,
+            23115,            26051,            28825,            30758,
+             1628,             2206,             3467,             4364,
+             8679,            10173,            11864,            13679,
+            14998,            16938,            19207,            21364,
+            23850,            26115,            28124,            30273,
+             2014,             2603,             4114,             7254,
+             8516,            10043,            11822,            13503,
+            16329,            17826,            19697,            21280,
+            23151,            24661,            26807,            30161,
+             2376,             2980,             4422,             5770,
+             7016,             9723,            11125,            13516,
+            15485,            16985,            19160,            20587,
+            24401,            27180,            29046,            30647,
+             2454,             3502,             4624,             6019,
+             7632,             8849,            10792,            13964,
+            15523,            17085,            19611,            21238,
+            22856,            25108,            28106,            29890,
+             1573,             2274,             3308,             5999,
+             8977,            10104,            12457,            14258,
+            15749,            18180,            19974,            21253,
+            23045,            25058,            27741,            30315,
+             1943,             2730,             4140,             6160,
+             7491,             8986,            11309,            12775,
+            14820,            16558,            17909,            19757,
+            21512,            23605,            27274,            29527,
+             2021,             2582,             4494,             5835,
+             6993,             8245,             9827,            14733,
+            16462,            17894,            19647,            21083,
+            23764,            26667,            29072,            30990,
+             1052,             1775,             3218,             4378,
+             7666,             9403,            11248,            13327,
+            14972,            17962,            20758,            22354,
+            25071,            27209,            29001,            30609,
+             2218,             2866,             4223,             5352,
+             6581,             9980,            11587,            13121,
+            15193,            16583,            18386,            20080,
+            22013,            25317,            28127,            29880,
+             2146,             2840,             4397,             5840,
+             7449,             8721,            10512,            11936,
+            13595,            17253,            19310,            20891,
+            23417,            25627,            27749,            30231,
+             1972,             2619,             3756,             6367,
+             7641,             8814,            12286,            13768,
+            15309,            18036,            19557,            20904,
+            22582,            24876,            27800,            30440,
+             2005,             2577,             4272,             7373,
+             8558,            10223,            11770,            13402,
+            16502,            18000,            19645,            21104,
+            22990,            26806,            29505,            30942,
+             1153,             1822,             3724,             5443,
+             6990,             8702,            10289,            11899,
+            13856,            15315,            17601,            21064,
+            23692,            26083,            28586,            30639,
+             1304,             1869,             3318,             7195,
+             9613,            10733,            12393,            13728,
+            15822,            17474,            18882,            20692,
+            23114,            25540,            27684,            29244,
+             2093,             2691,             4018,             6658,
+             7947,             9147,            10497,            11881,
+            15888,            17821,            19333,            21233,
+            23371,            25234,            27553,            29998,
+              575,             1331,             5304,             6910,
+             8425,            10086,            11577,            13498,
+            16444,            18527,            20565,            22847,
+            24914,            26692,            28759,            30157,
+             1435,             2024,             3283,             4156,
+             7611,            10592,            12049,            13927,
+            15459,            18413,            20495,            22270,
+            24222,            26093,            28065,            30099,
+             1632,             2168,             5540,             7478,
+             8630,            10391,            11644,            14321,
+            15741,            17357,            18756,            20434,
+            22799,            26060,            28542,            30696,
+             1407,             2245,             3405,             5639,
+             9419,            10685,            12104,            13495,
+            15535,            18357,            19996,            21689,
+            24351,            26550,            28853,            30564,
+             1675,             2226,             4005,             8223,
+             9975,            11155,            12822,            14316,
+            16504,            18137,            19574,            21050,
+            22759,            24912,            28296,            30634,
+             1080,             1614,             3622,             7565,
+             8748,            10303,            11713,            13848,
+            15633,            17434,            19761,            21825,
+            23571,            25393,            27406,            29063,
+             1693,             2229,             3456,             4354,
+             5670,            10890,            12563,            14167,
+            15879,            17377,            19817,            21971,
+            24094,            26131,            28298,            30099,
+             2042,             2959,             4195,             5740,
+             7106,             8267,            11126,            14973,
+            16914,            18295,            20532,            21982,
+            23711,            25769,            27609,            29351,
+              984,             1612,             3808,             5265,
+             6885,             8411,             9547,            10889,
+            12522,            16520,            19549,            21639,
+            23746,            26058,            28310,            30374,
+             2036,             2538,             4166,             7761,
+             9146,            10412,            12144,            13609,
+            15588,            17169,            18559,            20113,
+            21820,            24313,            28029,            30612,
+             1871,             2355,             4061,             5143,
+             7464,            10129,            11941,            15001,
+            16680,            18354,            19957,            22279,
+            24861,            26872,            28988,            30615,
+             2566,             3161,             4643,             6227,
+             7406,             9970,            11618,            13416,
+            15889,            17364,            19121,            20817,
+            22592,            24720,            28733,            31082,
+             1700,             2327,             4828,             5939,
+             7567,             9154,            11087,            12771,
+            14209,            16121,            20222,            22671,
+            24648,            26656,            28696,            30745,
+             3169,             3873,             5046,             6868,
+             8184,             9480,            12335,            14068,
+            15774,            17971,            20231,            21711,
+            23520,            25245,            27026,            28730,
+             1564,             2391,             4229,             6730,
+             8905,            10459,            13026,            15033,
+            17265,            19809,            21849,            23741,
+            25490,            27312,            29061,            30527,
+             2864,             3559,             4719,             6441,
+             9592,            11055,            12763,            14784,
+            16428,            18164,            20486,            22262,
+            24183,            26263,            28383,            30224,
+             2673,             3449,             4581,             5983,
+             6863,             8311,            12464,            13911,
+            15738,            17791,            19416,            21182,
+            24025,            26561,            28723,            30440,
+             2419,             3049,             4274,             6384,
+             8564,             9661,            11288,            12676,
+            14447,            17578,            19816,            21231,
+            23099,            25270,            26899,            28926,
+             1278,             2001,             3000,             5353,
+             9995,            11777,            13018,            14570,
+            16050,            17762,            19982,            21617,
+            23371,            25083,            27656,            30172,
+              932,             1624,             2798,             4570,
+             8592,             9988,            11552,            13050,
+            16921,            18677,            20415,            22810,
+            24817,            26819,            28804,            30385,
+             2324,             2973,             4156,             5702,
+             6919,             8806,            10259,            12503,
+            15015,            16567,            19418,            21375,
+            22943,            24550,            27024,            29849,
+             1564,             2373,             3455,             4907,
+             5975,             7436,            11786,            14505,
+            16107,            18148,            20019,            21653,
+            23740,            25814,            28578,            30372,
+             3025,             3729,             4866,             6520,
+             9487,            10943,            12358,            14258,
+            16174,            17501,            19476,            21408,
+            23227,            24906,            27347,            29407,
+             1270,             1965,             6802,             7995,
+             9204,            10828,            12507,            14230,
+            15759,            17860,            20369,            22502,
+            24633,            26514,            28535,            30525,
+             2210,             2749,             4266,             7487,
+             9878,            11018,            12823,            14431,
+            16247,            18626,            20450,            22054,
+            23739,            25291,            27074,            29169,
+             1275,             1926,             4330,             6573,
+             8441,            10920,            13260,            15008,
+            16927,            18573,            20644,            22217,
+            23983,            25474,            27372,            28645,
+             3015,             3670,             5086,             6372,
+             7888,             9309,            10966,            12642,
+            14495,            16172,            18080,            19972,
+            22454,            24899,            27362,            29975,
+             2882,             3733,             5113,             6482,
+             8125,             9685,            11598,            13288,
+            15405,            17192,            20178,            22426,
+            24801,            27014,            29212,            30811,
+             2300,             2968,             4101,             5442,
+             6327,             7910,            12455,            13862,
+            15747,            17505,            19053,            20679,
+            22615,            24658,            27499,            30065,
+             2257,             2940,             4430,             5991,
+             7042,             8364,             9414,            11224,
+            15723,            17420,            19253,            21469,
+            23915,            26053,            28430,            30384,
+             1227,             2045,             3818,             5011,
+             6990,             9231,            11024,            13011,
+            17341,            19017,            20583,            22799,
+            25195,            26876,            29351,            30805,
+             1354,             1924,             3789,             8077,
+            10453,            11639,            13352,            14817,
+            16743,            18189,            20095,            22014,
+            24593,            26677,            28647,            30256,
+             3142,             4049,             6197,             7417,
+             8753,            10156,            11533,            13181,
+            15947,            17655,            19606,            21402,
+            23487,            25659,            28123,            30304,
+             1317,             2263,             4725,             7611,
+             9667,            11634,            14143,            16258,
+            18724,            20698,            22379,            24007,
+            25775,            27251,            28930,            30593,
+             1570,             2323,             3818,             6215,
+             9893,            11556,            13070,            14631,
+            16152,            18290,            21386,            23346,
+            25114,            26923,            28712,            30168,
+             2297,             3905,             6287,             8558,
+            10668,            12766,            15019,            17102,
+            19036,            20677,            22341,            23871,
+            25478,            27085,            28851,            30520,
+             1915,             2507,             4033,             5749,
+             7059,             8871,            10659,            12198,
+            13937,            15383,            16869,            18707,
+            23175,            25818,            28514,            30501,
+             2404,             2918,             5190,             6252,
+             7426,             9887,            12387,            14795,
+            16754,            18368,            20338,            22003,
+            24236,            26456,            28490,            30397,
+             1621,             2227,             3479,             5085,
+             9425,            12892,            14246,            15652,
+            17205,            18674,            20446,            22209,
+            23778,            25867,            27931,            30093,
+             1869,             2390,             4105,             7021,
+            11221,            12775,            14059,            15590,
+            17024,            18608,            20595,            22075,
+            23649,            25154,            26914,            28671,
+             2551,             3252,             4688,             6562,
+             7869,             9125,            10475,            11800,
+            15402,            18780,            20992,            22555,
+            24289,            25968,            27465,            29232,
+             2705,             3493,             4735,             6360,
+             7905,             9352,            11538,            13430,
+            15239,            16919,            18619,            20094,
+            21800,            23342,            25200,            29257,
+             2166,             2791,             4011,             5081,
+             5896,             9038,            13407,            14703,
+            16543,            18189,            19896,            21857,
+            24872,            26971,            28955,            30514,
+             1865,             3021,             4696,             6534,
+             8343,             9914,            12789,            14103,
+            16533,            17729,            21340,            22439,
+            24873,            26330,            28428,            30154,
+             3369,             4345,             6573,             8763,
+            10309,            11713,            13367,            14784,
+            16483,            18145,            19839,            21247,
+            23292,            25477,            27555,            29447,
+             1265,             2184,             5443,             7893,
+            10591,            13139,            15105,            16639,
+            18402,            19826,            21419,            22995,
+            24719,            26437,            28363,            30125,
+             1584,             2004,             3535,             4450,
+             8662,            10764,            12832,            14978,
+            16972,            18794,            20932,            22547,
+            24636,            26521,            28701,            30567,
+             3419,             4528,             6602,             7890,
+             9508,            10875,            12771,            14357,
+            16051,            18330,            20630,            22490,
+            25070,            26936,            28946,            30542,
+             1726,             2252,             4597,             6950,
+             8379,             9823,            11363,            12794,
+            14306,            15476,            16798,            18018,
+            21671,            25550,            28148,            30367,
+             3385,             3870,             5307,             6388,
+             7141,             8684,            12695,            14939,
+            16480,            18277,            20537,            22048,
+            23947,            25965,            28214,            29956,
+             2771,             3306,             4450,             5560,
+             6453,             9493,            13548,            14754,
+            16743,            18447,            20028,            21736,
+            23746,            25353,            27141,            29066,
+             3028,             3900,             6617,             7893,
+             9211,            10480,            12047,            13583,
+            15182,            16662,            18502,            20092,
+            22190,            24358,            26302,            28957,
+             2000,             2550,             4067,             6837,
+             9628,            11002,            12594,            14098,
+            15589,            17195,            18679,            20099,
+            21530,            23085,            24641,            29022,
+             2844,             3302,             5103,             6107,
+             6911,             8598,            12416,            14054,
+            16026,            18567,            20672,            22270,
+            23952,            25771,            27658,            30026,
+             4043,             5150,             7268,             9056,
+            10916,            12638,            14543,            16184,
+            17948,            19691,            21357,            22981,
+            24825,            26591,            28479,            30233,
+             2109,             2625,             4320,             5525,
+             7454,            10220,            12980,            14698,
+            17627,            19263,            20485,            22381,
+            24279,            25777,            27847,            30458,
+             1550,             2667,             6473,             9496,
+            10985,            12352,            13795,            15233,
+            17099,            18642,            20461,            22116,
+            24197,            26291,            28403,            30132,
+             2411,             3084,             4145,             5394,
+             6367,             8154,            13125,            16049,
+            17561,            19125,            21258,            22762,
+            24459,            26317,            28255,            29702,
+             4159,             4516,             5956,             7635,
+             8254,             8980,            11208,            14133,
+            16210,            17875,            20196,            21864,
+            23840,            25747,            28058,            30012,
+             2026,             2431,             2845,             3618,
+             7950,             9802,            12721,            14460,
+            16576,            18984,            21376,            23319,
+            24961,            26718,            28971,            30640,
+             3429,             3833,             4472,             4912,
+             7723,            10386,            12981,            15322,
+            16699,            18807,            20778,            22551,
+            24627,            26494,            28334,            30482,
+             4740,             5169,             5796,             6485,
+             6998,             8830,            11777,            14414,
+            16831,            18413,            20789,            22369,
+            24236,            25835,            27807,            30021,
+              150,              168,              -17,             -107,
+             -142,             -229,             -320,             -406,
+             -503,             -620,             -867,             -935,
+             -902,             -680,             -398,             -114,
+             -398,             -355,               49,              255,
+              114,              260,              399,              264,
+              317,              431,              514,              531,
+              435,              356,              238,              106,
+              -43,              -36,             -169,             -224,
+             -391,             -633,             -776,             -970,
+             -844,             -455,             -181,              -12,
+               85,               85,              164,              195,
+              122,               85,             -158,             -640,
+             -903,                9,                7,             -124,
+              149,               32,              220,              369,
+              242,              115,               79,               84,
+             -146,             -216,              -70,             1024,
+              751,              574,              440,              377,
+              352,              203,               30,               16,
+               -3,               81,              161,              100,
+             -148,             -176,              933,              750,
+              404,              171,               -2,             -146,
+             -411,             -442,             -541,             -552,
+             -442,             -269,             -240,              -52,
+              603,              635,              405,              178,
+              215,               19,             -153,             -167,
+             -290,             -219,              151,              271,
+              151,              119,              303,              266,
+              100,               69,             -293,             -657,
+              939,              659,              442,              351,
+              132,               98,              -16,               -1,
+             -135,             -200,             -223,              -89,
+              167,              154,              172,              237,
+              -45,             -183,             -228,             -486,
+              263,              608,              158,             -125,
+             -390,             -227,             -118,               43,
+             -457,             -392,             -769,             -840,
+               20,             -117,             -194,             -189,
+             -173,             -173,              -33,               32,
+              174,              144,              115,              167,
+               57,               44,               14,              147,
+               96,              -54,             -142,             -129,
+             -254,             -331,              304,              310,
+              -52,             -419,             -846,            -1060,
+              -88,             -123,             -202,             -343,
+             -554,             -961,             -951,              327,
+              159,               81,              255,              227,
+              120,              203,              256,              192,
+              164,              224,              290,              195,
+              216,              209,              128,              832,
+             1028,              889,              698,              504,
+              408,              355,              218,               32,
+             -115,              -84,             -276,             -100,
+             -312,             -484,              899,              682,
+              465,              456,              241,              -12,
+             -275,             -425,             -461,             -367,
+              -33,              -28,             -102,             -194,
+             -527,              863,              906,              463,
+              245,               13,             -212,             -305,
+             -105,              163,              279,              176,
+               93,               67,              115,              192,
+               61,              -50,             -132,             -175,
+             -224,             -271,             -629,             -252,
+             1158,              972,              638,              280,
+              300,              326,              143,             -152,
+             -214,             -287,               53,              -42,
+             -236,             -352,             -423,             -248,
+             -129,             -163,             -178,             -119,
+               85,               57,              514,              382,
+              374,              402,              424,              423,
+              271,              197,               97,               40,
+               39,              -97,             -191,             -164,
+             -230,             -256,             -410,              396,
+              327,              127,               10,             -119,
+             -167,             -291,             -274,             -141,
+              -99,             -226,             -218,             -139,
+             -224,             -209,             -268,             -442,
+             -413,              222,               58,              521,
+              344,              258,               76,              -42,
+             -142,             -165,             -123,              -92,
+               47,                8,               -3,             -191,
+              -11,             -164,             -167,             -351,
+             -740,              311,              538,              291,
+              184,               29,             -105,                9,
+              -30,              -54,              -17,              -77,
+             -271,             -412,             -622,             -648,
+              476,              186,              -66,             -197,
+              -73,              -94,              -15,               47,
+               28,              112,              -58,              -33,
+               65,               19,               84,               86,
+              276,              114,              472,              786,
+              799,              625,              415,              178,
+              -35,              -26,                5,                9,
+               83,               39,               37,               39,
+             -184,             -374,             -265,             -362,
+             -501,              337,              716,              478,
+              -60,             -125,             -163,              362,
+               17,             -122,             -233,              279,
+              138,              157,              318,              193,
+              189,              209,              266,              252,
+              -46,              -56,             -277,             -429,
+              464,              386,              142,               44,
+              -43,               66,              264,              182,
+               47,               14,              -26,              -79,
+               49,               15,             -128,             -203,
+             -400,             -478,              325,               27,
+              234,              411,              205,              129,
+               12,               58,              123,               57,
+              171,              137,               96,              128,
+              -32,              134,              -12,               57,
+              119,               26,              -22,             -165,
+             -500,             -701,             -528,             -116,
+               64,               -8,               97,               -9,
+             -162,              -66,             -156,             -194,
+             -303,             -546,             -341,              546,
+              358,               95,               45,               76,
+              270,              403,              205,              100,
+              123,               50,              -53,             -144,
+             -110,              -13,               32,             -228,
+             -130,              353,              296,               56,
+             -372,             -253,              365,               73,
+               10,              -34,             -139,             -191,
+              -96,                5,               44,              -85,
+             -179,             -129,             -192,             -246,
+              -85,             -110,             -155,              -44,
+              -27,              145,              138,               79,
+               32,             -148,             -577,             -634,
+              191,               94,               -9,              -35,
+              -77,              -84,              -56,             -171,
+             -298,             -271,             -243,             -156,
+             -328,             -235,              -76,             -128,
+             -121,              129,               13,              -22,
+               32,               45,             -248,              -65,
+              193,              -81,              299,               57,
+             -147,              192,             -165,             -354,
+             -334,             -106,             -156,              -40,
+               -3,              -68,              124,             -257,
+               78,              124,              170,              412,
+              227,              105,             -104,               12,
+              154,              250,              274,              258,
+                4,              -27,              235,              152,
+               51,              338,              300,                7,
+             -314,             -411,              215,              170,
+               -9,              -93,              -77,               76,
+               67,               54,              200,              315,
+              163,               72,              -91,             -402,
+              158,              187,             -156,              -91,
+              290,              267,              167,               91,
+              140,              171,              112,                9,
+              -42,             -177,             -440,              385,
+               80,               15,              172,              129,
+               41,             -129,             -372,              -24,
+              -75,              -30,             -170,               10,
+             -118,               57,               78,             -101,
+              232,              161,              123,              256,
+              277,              101,             -192,             -629,
+             -100,              -60,             -232,               66,
+               13,              -13,              -80,             -239,
+              239,               37,               32,               89,
+             -319,             -579,              450,              360,
+                3,              -29,             -299,              -89,
+              -54,             -110,             -246,             -164,
+                6,             -188,              338,              176,
+              -92,              197,              137,              134,
+               12,               -2,               56,             -183,
+              114,              -36,             -131,             -204,
+               75,              -25,             -174,              191,
+              -15,             -290,             -429,             -267,
+               79,               37,              106,               23,
+             -384,              425,               70,              -14,
+              212,              105,               15,               -2,
+              -42,              -37,             -123,              108,
+               28,              -48,              193,              197,
+              173,              -33,               37,               73,
+              -57,              256,              137,              -58,
+             -430,             -228,              217,              -51,
+              -10,              -58,               -6,               22,
+              104,               61,             -119,              169,
+              144,               16,              -46,             -394,
+               60,              454,              -80,             -298,
+              -65,               25,                0,              -24,
+              -65,             -417,              465,              276,
+               -3,             -194,              -13,              130,
+               19,               -6,              -21,              -24,
+             -180,              -53,              -85,               20,
+              118,              147,              113,              -75,
+             -289,              226,             -122,              227,
+              270,              125,              109,              197,
+              125,              138,               44,               60,
+               25,              -55,             -167,              -32,
+             -139,             -193,             -173,             -316,
+              287,             -208,              253,              239,
+               27,              -80,             -188,              -28,
+             -182,             -235,              156,             -117,
+              128,              -48,              -58,             -226,
+              172,              181,              167,               19,
+               62,               10,                2,              181,
+              151,              108,              -16,              -11,
+              -78,             -331,              411,              133,
+               17,              104,               64,             -184,
+               24,              -30,               -3,             -283,
+              121,              204,               -8,             -199,
+              -21,              -80,             -169,             -157,
+             -191,             -136,               81,              155,
+               14,             -131,              244,               74,
+              -57,              -47,             -280,              347,
+              111,              -77,             -128,             -142,
+             -194,             -125,               -6,              -68,
+               91,                1,               23,               14,
+             -154,              -34,               23,              -38,
+             -343,              503,              146,              -38,
+              -46,              -41,               58,               31,
+               63,              -48,             -117,               45,
+               28,                1,              -89,               -5,
+              -44,              -29,             -448,              487,
+              204,               81,               46,             -106,
+             -302,              380,              120,              -38,
+              -12,              -39,               70,               -3,
+               25,              -65,               30,              -11,
+               34,              -15,               22,             -115,
+                0,              -79,              -83,               45,
+              114,               43,              150,               36,
+              233,              149,              195,                5,
+               25,              -52,             -475,              274,
+               28,              -39,               -8,              -66,
+             -255,              258,               56,              143,
+              -45,             -190,              165,              -60,
+               20,                2,              125,             -129,
+               51,               -8,             -335,              288,
+               38,               59,               25,              -42,
+               23,             -118,             -112,               11,
+              -55,             -133,             -109,               24,
+             -105,               78,              -64,             -245,
+              202,              -65,             -127,              162,
+               40,              -94,               89,              -85,
+             -119,             -103,               97,                9,
+              -70,              -28,              194,               86,
+             -112,              -92,             -114,               74,
+              -49,               46,              -84,             -178,
+              113,               52,             -205,              333,
+               88,              222,               56,              -55,
+               13,               86,                4,              -77,
+              224,              114,             -105,              112,
+              125,              -29,              -18,             -144,
+               22,              -58,              -99,               28,
+              114,              -66,              -32,             -169,
+             -314,              285,               72,              -74,
+              179,               28,              -79,             -182,
+               13,              -55,              147,               13,
+               12,              -54,               31,              -84,
+              -17,              -75,             -228,               83,
+             -375,              436,              110,              -63,
+              -27,             -136,              169,              -56,
+               -8,             -171,              184,              -42,
+              148,               68,              204,              235,
+              110,             -229,               91,              171,
+              -43,               -3,              -26,              -99,
+             -111,               71,             -170,              202,
+              -67,              181,              -37,              109,
+             -120,                3,              -55,             -260,
+              -16,              152,               91,              142,
+               42,               44,              134,               47,
+               17,              -35,               22,               79,
+             -169,               41,               46,              277,
+              -93,              -49,             -126,               37,
+             -103,              -34,              -22,              -90,
+             -134,             -205,               92,               -9,
+                1,             -195,             -239,               45,
+               54,               18,              -23,               -1,
+              -80,              -98,              -20,             -261,
+              306,               72,               20,              -89,
+             -217,               11,                6,              -82,
+               89,               13,             -129,              -89,
+               83,              -71,              -55,              130,
+              -98,             -146,              -27,              -57,
+               53,              275,               17,              170,
+               -5,              -54,              132,              -64,
+               72,              160,             -125,             -168,
+               72,               40,              170,               78,
+              248,              116,               20,               84,
+               31,              -34,              190,               38,
+               13,             -106,              225,               27,
+             -168,               24,             -157,             -122,
+              165,               11,             -161,             -213,
+              -12,              -51,             -101,               42,
+              101,               27,               55,              111,
+               75,               71,              -96,               -1,
+               65,             -277,              393,              -26,
+              -44,              -68,              -84,              -66,
+              -95,              235,              179,              -25,
+              -41,               27,              -91,             -128,
+             -222,              146,              -72,              -30,
+              -24,               55,             -126,              -68,
+              -58,             -127,               13,              -97,
+             -106,              174,             -100,              155,
+              101,             -146,              -21,              261,
+               22,               38,              -66,               65,
+                4,               70,               64,              144,
+               59,              213,               71,             -337,
+              303,              -52,               51,              -56,
+                1,               10,              -15,               -5,
+               34,               52,              228,              131,
+              161,             -127,             -214,              238,
+              123,               64,             -147,              -50,
+              -34,             -127,              204,              162,
+               85,               41,                5,             -140,
+               73,             -150,               56,              -96,
+              -66,              -20,                2,             -235,
+               59,              -22,             -107,              150,
+              -16,              -47,               -4,               81,
+              -67,              167,              149,              149,
+             -157,              288,             -156,              -27,
+               -8,               18,               83,              -24,
+              -41,             -167,              158,             -100,
+               93,               53,              201,               15,
+               42,              266,              278,              -12,
+               -6,              -37,               85,                6,
+               20,             -188,             -271,              107,
+              -13,              -80,               51,              202,
+              173,              -69,               78,             -188,
+               46,                4,              153,               12,
+             -138,              169,                5,              -58,
+             -123,             -108,             -243,              150,
+               10,             -191,              246,              -15,
+               38,               25,              -10,               14,
+               61,               50,             -206,             -215,
+             -220,               90,                5,             -149,
+             -219,               56,              142,               24,
+             -376,               77,              -80,               75,
+                6,               42,             -101,               16,
+               56,               14,              -57,                3,
+              -17,               80,               57,              -36,
+               88,              -59,              -97,              -19,
+             -148,               46,             -219,              226,
+              114,               -4,              -72,              -15,
+               37,              -49,              -28,              247,
+               44,              123,               47,             -122,
+              -38,               17,                4,             -113,
+              -32,             -224,              154,             -134,
+              196,               71,             -267,              -85,
+               28,              -70,               89,             -120,
+               99,               -2,               64,               76,
+             -166,              -48,              189,              -35,
+              -92,             -169,             -123,              339,
+               38,              -25,               38,              -35,
+              225,             -139,              -50,              -63,
+              246,               60,             -185,             -109,
+              -49,              -53,             -167,               51,
+              149,               60,             -101,              -33,
+               25,              -76,              120,               32,
+              -30,              -83,              102,               91,
+             -186,             -261,              131,             -197
+};
+
+const SKP_Silk_NLSF_CBS SKP_Silk_NLSF_CB0_16_Stage_info[ NLSF_MSVQ_CB0_16_STAGES ] =
+{
+        { 128, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 *   0 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[   0 ] },
+        {  16, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 128 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 128 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 144 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 144 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 152 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 152 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 160 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 160 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 168 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 168 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 176 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 176 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 184 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 184 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 192 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 192 ] },
+        {  16, &SKP_Silk_NLSF_MSVQ_CB0_16_Q15[ 16 * 200 ], &SKP_Silk_NLSF_MSVQ_CB0_16_rates_Q5[ 200 ] }
+};
+
+const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_16 =
+{
+        NLSF_MSVQ_CB0_16_STAGES,
+        SKP_Silk_NLSF_CB0_16_Stage_info,
+        SKP_Silk_NLSF_MSVQ_CB0_16_ndelta_min_Q15,
+        SKP_Silk_NLSF_MSVQ_CB0_16_CDF,
+        SKP_Silk_NLSF_MSVQ_CB0_16_CDF_start_ptr,
+        SKP_Silk_NLSF_MSVQ_CB0_16_CDF_middle_idx
+};
+
index 1581e5a372e0387e66fbb6bd77ab84c9331e044c..180c4614904533d9c7e5c7569ee9d7d6611e1ea3 100644 (file)
@@ -1,51 +1,51 @@
-/***********************************************************************\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
-#ifndef SKP_SILK_TABLES_NLSF_CB0_16_H\r
-#define SKP_SILK_TABLES_NLSF_CB0_16_H\r
-\r
-#include "SKP_Silk_define.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-#define NLSF_MSVQ_CB0_16_STAGES       10\r
-#define NLSF_MSVQ_CB0_16_VECTORS      216\r
-\r
-/* NLSF codebook entropy coding tables */\r
-extern const SKP_uint16         SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ NLSF_MSVQ_CB0_16_VECTORS + NLSF_MSVQ_CB0_16_STAGES ];\r
-extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB0_16_CDF_start_ptr[                  NLSF_MSVQ_CB0_16_STAGES ];\r
-extern const SKP_int            SKP_Silk_NLSF_MSVQ_CB0_16_CDF_middle_idx[                 NLSF_MSVQ_CB0_16_STAGES ];\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_TABLES_NLSF_CB0_16_H
+#define SKP_SILK_TABLES_NLSF_CB0_16_H
+
+#include "SKP_Silk_define.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define NLSF_MSVQ_CB0_16_STAGES       10
+#define NLSF_MSVQ_CB0_16_VECTORS      216
+
+/* NLSF codebook entropy coding tables */
+extern const SKP_uint16         SKP_Silk_NLSF_MSVQ_CB0_16_CDF[ NLSF_MSVQ_CB0_16_VECTORS + NLSF_MSVQ_CB0_16_STAGES ];
+extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB0_16_CDF_start_ptr[                  NLSF_MSVQ_CB0_16_STAGES ];
+extern const SKP_int            SKP_Silk_NLSF_MSVQ_CB0_16_CDF_middle_idx[                 NLSF_MSVQ_CB0_16_STAGES ];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
index 73e043028e55164bebcd6078df5781281643616f..5d897e0b0572c60b1fddd5903b8ed969c24a1c73 100644 (file)
-/***********************************************************************\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
-/* This file has been automatically generated */\r
-/*                                            */\r
-/* ROM usage:  0.19 + 1.61 kB                 */\r
-/**********************************************/\r
-\r
-#include "SKP_Silk_structs.h"\r
-#include "SKP_Silk_tables_NLSF_CB1_10.h"\r
-#include "SKP_Silk_tables.h"\r
-\r
-const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB1_10_CDF[ NLSF_MSVQ_CB1_10_VECTORS + NLSF_MSVQ_CB1_10_STAGES ] =\r
-{\r
-            0,\r
-        17096,\r
-        24130,\r
-        28997,\r
-        33179,\r
-        36696,\r
-        40213,\r
-        42493,\r
-        44252,\r
-        45973,\r
-        47551,\r
-        49095,\r
-        50542,\r
-        51898,\r
-        53196,\r
-        54495,\r
-        55685,\r
-        56851,\r
-        57749,\r
-        58628,\r
-        59435,\r
-        60207,\r
-        60741,\r
-        61220,\r
-        61700,\r
-        62179,\r
-        62659,\r
-        63138,\r
-        63617,\r
-        64097,\r
-        64576,\r
-        65056,\r
-        65535,\r
-            0,\r
-        20378,\r
-        33032,\r
-        40395,\r
-        46721,\r
-        51707,\r
-        56585,\r
-        61157,\r
-        65535,\r
-            0,\r
-        15055,\r
-        25472,\r
-        35447,\r
-        42501,\r
-        48969,\r
-        54773,\r
-        60212,\r
-        65535,\r
-            0,\r
-        12069,\r
-        22440,\r
-        32812,\r
-        40145,\r
-        46870,\r
-        53595,\r
-        59630,\r
-        65535,\r
-            0,\r
-        10839,\r
-        19954,\r
-        27957,\r
-        35961,\r
-        43965,\r
-        51465,\r
-        58805,\r
-        65535,\r
-            0,\r
-         8933,\r
-        17674,\r
-        26415,\r
-        34785,\r
-        42977,\r
-        50820,\r
-        58496,\r
-        65535\r
-};\r
-\r
-const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB1_10_CDF_start_ptr[ NLSF_MSVQ_CB1_10_STAGES ] =\r
-{\r
-     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[   0 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[  33 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[  42 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[  51 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[  60 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[  69 ]\r
-};\r
-\r
-const SKP_int SKP_Silk_NLSF_MSVQ_CB1_10_CDF_middle_idx[ NLSF_MSVQ_CB1_10_STAGES ] =\r
-{\r
-       5,\r
-       3,\r
-       4,\r
-       4,\r
-       5,\r
-       5\r
-};\r
-\r
-const SKP_int16 SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[ NLSF_MSVQ_CB1_10_VECTORS ] =\r
-{\r
-               62,              103,\r
-              120,              127,\r
-              135,              135,\r
-              155,              167,\r
-              168,              172,\r
-              173,              176,\r
-              179,              181,\r
-              181,              185,\r
-              186,              198,\r
-              199,              203,\r
-              205,              222,\r
-              227,              227,\r
-              227,              227,\r
-              227,              227,\r
-              227,              227,\r
-              227,              227,\r
-               54,               76,\r
-              101,              108,\r
-              119,              120,\r
-              123,              125,\r
-               68,               85,\r
-               87,              103,\r
-              107,              112,\r
-              115,              116,\r
-               78,               85,\r
-               85,              101,\r
-              105,              105,\r
-              110,              111,\r
-               83,               91,\r
-               97,               97,\r
-               97,              100,\r
-              101,              105,\r
-               92,               93,\r
-               93,               95,\r
-               96,               98,\r
-               99,              103\r
-};\r
-\r
-const SKP_int SKP_Silk_NLSF_MSVQ_CB1_10_ndelta_min_Q15[ 10 + 1 ] =\r
-{\r
-              462,\r
-                3,\r
-               64,\r
-               74,\r
-               98,\r
-               50,\r
-               97,\r
-               68,\r
-              120,\r
-               53,\r
-              639\r
-};\r
-\r
-const SKP_int16 SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 * NLSF_MSVQ_CB1_10_VECTORS ] =\r
-{\r
-             1877,             4646,\r
-             7712,            10745,\r
-            13964,            17028,\r
-            20239,            23182,\r
-            26471,            29287,\r
-             1612,             3278,\r
-             7086,             9975,\r
-            13228,            16264,\r
-            19596,            22690,\r
-            26037,            28965,\r
-             2169,             3830,\r
-             6460,             8958,\r
-            11960,            14750,\r
-            18408,            21659,\r
-            25018,            28043,\r
-             3680,             6024,\r
-             8986,            12256,\r
-            15201,            18188,\r
-            21741,            24460,\r
-            27484,            30059,\r
-             2584,             5187,\r
-             7799,            10902,\r
-            13179,            15765,\r
-            19017,            22431,\r
-            25891,            28698,\r
-             3731,             5751,\r
-             8650,            11742,\r
-            15090,            17407,\r
-            20391,            23421,\r
-            26228,            29247,\r
-             2107,             6323,\r
-             8915,            12226,\r
-            14775,            17791,\r
-            20664,            23679,\r
-            26829,            29353,\r
-             1677,             2870,\r
-             5386,             8077,\r
-            11817,            15176,\r
-            18657,            22006,\r
-            25513,            28689,\r
-             2111,             3625,\r
-             7027,            10588,\r
-            14059,            17193,\r
-            21137,            24260,\r
-            27577,            30036,\r
-             2428,             4010,\r
-             5765,             9376,\r
-            13805,            15821,\r
-            19444,            22389,\r
-            25295,            29310,\r
-             2256,             4628,\r
-             8377,            12441,\r
-            15283,            19462,\r
-            22257,            25551,\r
-            28432,            30304,\r
-             2352,             3675,\r
-             6129,            11868,\r
-            14551,            16655,\r
-            19624,            21883,\r
-            26526,            28849,\r
-             5243,             7248,\r
-            10558,            13269,\r
-            15651,            17919,\r
-            21141,            23827,\r
-            27102,            29519,\r
-             4422,             6725,\r
-            10449,            13273,\r
-            16124,            19921,\r
-            22826,            26061,\r
-            28763,            30583,\r
-             4508,             6291,\r
-             9504,            11809,\r
-            13827,            15950,\r
-            19077,            22084,\r
-            25740,            28658,\r
-             2540,             4297,\r
-             8579,            13578,\r
-            16634,            19101,\r
-            21547,            23887,\r
-            26777,            29146,\r
-             3377,             6358,\r
-            10224,            14518,\r
-            17905,            21056,\r
-            23637,            25784,\r
-            28161,            30109,\r
-             4177,             5942,\r
-             8159,            10108,\r
-            12130,            15470,\r
-            20191,            23326,\r
-            26782,            29359,\r
-             2492,             3801,\r
-             6144,             9825,\r
-            16000,            18671,\r
-            20893,            23663,\r
-            25899,            28974,\r
-             3011,             4727,\r
-             6834,            10505,\r
-            12465,            14496,\r
-            17065,            20052,\r
-            25265,            28057,\r
-             4149,             7197,\r
-            12338,            15076,\r
-            18002,            20190,\r
-            22187,            24723,\r
-            27083,            29125,\r
-             2975,             4578,\r
-             6448,             8378,\r
-             9671,            13225,\r
-            19502,            22277,\r
-            26058,            28850,\r
-             4102,             5760,\r
-             7744,             9484,\r
-            10744,            12308,\r
-            14677,            19607,\r
-            24841,            28381,\r
-             4931,             9287,\r
-            12477,            13395,\r
-            13712,            14351,\r
-            16048,            19867,\r
-            24188,            28994,\r
-             4141,             7867,\r
-            13140,            17720,\r
-            20064,            21108,\r
-            21692,            22722,\r
-            23736,            27449,\r
-             4011,             8720,\r
-            13234,            16206,\r
-            17601,            18289,\r
-            18524,            19689,\r
-            23234,            27882,\r
-             3420,             5995,\r
-            11230,            15117,\r
-            15907,            16783,\r
-            17762,            23347,\r
-            26898,            29946,\r
-             3080,             6786,\r
-            10465,            13676,\r
-            18059,            23615,\r
-            27058,            29082,\r
-            29563,            29905,\r
-             3038,             5620,\r
-             9266,            12870,\r
-            18803,            19610,\r
-            20010,            20802,\r
-            23882,            29306,\r
-             3314,             6420,\r
-             9046,            13262,\r
-            15869,            23117,\r
-            23667,            24215,\r
-            24487,            25915,\r
-             3469,             6963,\r
-            10103,            15282,\r
-            20531,            23240,\r
-            25024,            26021,\r
-            26736,            27255,\r
-             3041,             6459,\r
-             9777,            12896,\r
-            16315,            19410,\r
-            24070,            29353,\r
-            31795,            32075,\r
-             -200,             -134,\r
-             -113,             -204,\r
-             -347,             -440,\r
-             -352,             -211,\r
-             -418,             -172,\r
-             -313,               59,\r
-              495,              772,\r
-              721,              614,\r
-              334,              444,\r
-              225,              242,\r
-              161,               16,\r
-              274,              564,\r
-              -73,             -188,\r
-             -395,             -171,\r
-              777,              508,\r
-             1340,             1145,\r
-              699,              196,\r
-              223,              173,\r
-               90,               25,\r
-              -26,               18,\r
-              133,             -105,\r
-             -360,             -277,\r
-              859,              634,\r
-               41,             -557,\r
-             -768,             -926,\r
-             -601,            -1021,\r
-            -1189,             -365,\r
-              225,              107,\r
-              374,              -50,\r
-              433,              417,\r
-              156,               39,\r
-             -597,            -1397,\r
-            -1594,             -592,\r
-             -485,             -292,\r
-              253,               87,\r
-               -0,               -6,\r
-              -25,             -345,\r
-             -240,              120,\r
-             1261,              946,\r
-              166,             -277,\r
-              241,              167,\r
-              170,              429,\r
-              518,              714,\r
-              602,              254,\r
-              134,               92,\r
-             -152,             -324,\r
-             -394,               49,\r
-             -151,             -304,\r
-             -724,             -657,\r
-             -162,             -369,\r
-              -35,                3,\r
-               -2,             -312,\r
-             -200,              -92,\r
-             -227,              242,\r
-              628,              565,\r
-             -124,             1056,\r
-              770,              101,\r
-              -84,              -33,\r
-                4,             -192,\r
-             -272,                5,\r
-             -627,             -977,\r
-              419,              472,\r
-               53,             -103,\r
-              145,              322,\r
-              -95,              -31,\r
-             -100,             -303,\r
-             -560,            -1067,\r
-             -413,              714,\r
-              283,                2,\r
-             -223,             -367,\r
-              523,              360,\r
-              -38,             -115,\r
-              378,             -591,\r
-             -718,              448,\r
-             -481,             -274,\r
-              180,              -88,\r
-             -581,             -157,\r
-             -696,            -1265,\r
-              394,             -479,\r
-              -23,              124,\r
-              -43,               19,\r
-             -113,             -236,\r
-             -412,             -659,\r
-             -200,                2,\r
-              -69,             -342,\r
-              199,               55,\r
-               58,              -36,\r
-              -51,              -62,\r
-              507,              507,\r
-              427,              442,\r
-               36,              601,\r
-             -141,               68,\r
-              274,              274,\r
-               68,              -12,\r
-               -4,               71,\r
-             -193,             -464,\r
-             -425,             -383,\r
-              408,              203,\r
-             -337,              236,\r
-              410,              -59,\r
-              -25,             -341,\r
-             -449,               28,\r
-               -9,               90,\r
-              332,              -14,\r
-             -905,               96,\r
-             -540,             -242,\r
-              679,              -59,\r
-              192,              -24,\r
-               60,             -217,\r
-                5,              -37,\r
-              179,              -20,\r
-              311,              519,\r
-              274,               72,\r
-             -326,            -1030,\r
-             -262,              213,\r
-              380,               82,\r
-              328,              411,\r
-             -540,              574,\r
-             -283,              151,\r
-              181,             -402,\r
-             -278,             -240,\r
-             -110,             -227,\r
-             -264,              -89,\r
-             -250,             -259,\r
-              -27,              106,\r
-             -239,              -98,\r
-             -390,              118,\r
-               61,              104,\r
-              294,              532,\r
-               92,              -13,\r
-               60,             -233,\r
-              335,              541,\r
-              307,              -26,\r
-             -110,              -91,\r
-             -231,             -460,\r
-              170,              201,\r
-               96,             -372,\r
-              132,              435,\r
-             -302,              216,\r
-             -279,              -41,\r
-               74,              190,\r
-              368,              273,\r
-             -186,             -608,\r
-             -157,              159,\r
-               12,              278,\r
-              245,              307,\r
-               25,             -187,\r
-              -16,               55,\r
-               30,             -163,\r
-              548,             -307,\r
-              106,               -5,\r
-               27,              330,\r
-             -416,              475,\r
-              438,             -235,\r
-              104,              137,\r
-               21,               -5,\r
-             -300,             -468,\r
-              521,             -347,\r
-              170,             -200,\r
-             -219,              308,\r
-             -122,             -133,\r
-              219,              -16,\r
-              359,              412,\r
-              -89,             -111,\r
-               48,              322,\r
-              142,              177,\r
-             -286,             -127,\r
-              -39,              -63,\r
-              -42,             -451,\r
-              160,              308,\r
-              -57,              193,\r
-              -48,               74,\r
-             -346,               59,\r
-              -27,               27,\r
-             -469,             -277,\r
-             -344,              282,\r
-              262,              122,\r
-              171,             -249,\r
-               27,              258,\r
-              188,               -3,\r
-               67,             -206,\r
-             -284,              291,\r
-             -117,              -88,\r
-             -477,              375,\r
-               50,              106,\r
-               99,             -182,\r
-              438,             -376,\r
-             -401,              -49,\r
-              119,              -23,\r
-              -10,              -48,\r
-             -116,             -200,\r
-             -310,              121,\r
-               73,                7,\r
-              237,             -226,\r
-              139,             -456,\r
-              397,               35,\r
-                3,             -108,\r
-              323,              -75,\r
-              332,              198,\r
-              -99,              -21\r
-};\r
-\r
-const SKP_Silk_NLSF_CBS SKP_Silk_NLSF_CB1_10_Stage_info[ NLSF_MSVQ_CB1_10_STAGES ] =\r
-{\r
-        {  32, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *   0 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[   0 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *  32 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[  32 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *  40 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[  40 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *  48 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[  48 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *  56 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[  56 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *  64 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[  64 ] }\r
-};\r
-\r
-const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB1_10 =\r
-{\r
-        NLSF_MSVQ_CB1_10_STAGES,\r
-        SKP_Silk_NLSF_CB1_10_Stage_info,\r
-        SKP_Silk_NLSF_MSVQ_CB1_10_ndelta_min_Q15,\r
-        SKP_Silk_NLSF_MSVQ_CB1_10_CDF,\r
-        SKP_Silk_NLSF_MSVQ_CB1_10_CDF_start_ptr,\r
-        SKP_Silk_NLSF_MSVQ_CB1_10_CDF_middle_idx\r
-};\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/**********************************************/
+/* This file has been automatically generated */
+/*                                            */
+/* ROM usage:  0.19 + 1.61 kB                 */
+/**********************************************/
+
+#include "SKP_Silk_structs.h"
+#include "SKP_Silk_tables_NLSF_CB1_10.h"
+#include "SKP_Silk_tables.h"
+
+const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB1_10_CDF[ NLSF_MSVQ_CB1_10_VECTORS + NLSF_MSVQ_CB1_10_STAGES ] =
+{
+            0,
+        17096,
+        24130,
+        28997,
+        33179,
+        36696,
+        40213,
+        42493,
+        44252,
+        45973,
+        47551,
+        49095,
+        50542,
+        51898,
+        53196,
+        54495,
+        55685,
+        56851,
+        57749,
+        58628,
+        59435,
+        60207,
+        60741,
+        61220,
+        61700,
+        62179,
+        62659,
+        63138,
+        63617,
+        64097,
+        64576,
+        65056,
+        65535,
+            0,
+        20378,
+        33032,
+        40395,
+        46721,
+        51707,
+        56585,
+        61157,
+        65535,
+            0,
+        15055,
+        25472,
+        35447,
+        42501,
+        48969,
+        54773,
+        60212,
+        65535,
+            0,
+        12069,
+        22440,
+        32812,
+        40145,
+        46870,
+        53595,
+        59630,
+        65535,
+            0,
+        10839,
+        19954,
+        27957,
+        35961,
+        43965,
+        51465,
+        58805,
+        65535,
+            0,
+         8933,
+        17674,
+        26415,
+        34785,
+        42977,
+        50820,
+        58496,
+        65535
+};
+
+const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB1_10_CDF_start_ptr[ NLSF_MSVQ_CB1_10_STAGES ] =
+{
+     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[   0 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[  33 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[  42 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[  51 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[  60 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_10_CDF[  69 ]
+};
+
+const SKP_int SKP_Silk_NLSF_MSVQ_CB1_10_CDF_middle_idx[ NLSF_MSVQ_CB1_10_STAGES ] =
+{
+       5,
+       3,
+       4,
+       4,
+       5,
+       5
+};
+
+const SKP_int16 SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[ NLSF_MSVQ_CB1_10_VECTORS ] =
+{
+               62,              103,
+              120,              127,
+              135,              135,
+              155,              167,
+              168,              172,
+              173,              176,
+              179,              181,
+              181,              185,
+              186,              198,
+              199,              203,
+              205,              222,
+              227,              227,
+              227,              227,
+              227,              227,
+              227,              227,
+              227,              227,
+               54,               76,
+              101,              108,
+              119,              120,
+              123,              125,
+               68,               85,
+               87,              103,
+              107,              112,
+              115,              116,
+               78,               85,
+               85,              101,
+              105,              105,
+              110,              111,
+               83,               91,
+               97,               97,
+               97,              100,
+              101,              105,
+               92,               93,
+               93,               95,
+               96,               98,
+               99,              103
+};
+
+const SKP_int SKP_Silk_NLSF_MSVQ_CB1_10_ndelta_min_Q15[ 10 + 1 ] =
+{
+              462,
+                3,
+               64,
+               74,
+               98,
+               50,
+               97,
+               68,
+              120,
+               53,
+              639
+};
+
+const SKP_int16 SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 * NLSF_MSVQ_CB1_10_VECTORS ] =
+{
+             1877,             4646,
+             7712,            10745,
+            13964,            17028,
+            20239,            23182,
+            26471,            29287,
+             1612,             3278,
+             7086,             9975,
+            13228,            16264,
+            19596,            22690,
+            26037,            28965,
+             2169,             3830,
+             6460,             8958,
+            11960,            14750,
+            18408,            21659,
+            25018,            28043,
+             3680,             6024,
+             8986,            12256,
+            15201,            18188,
+            21741,            24460,
+            27484,            30059,
+             2584,             5187,
+             7799,            10902,
+            13179,            15765,
+            19017,            22431,
+            25891,            28698,
+             3731,             5751,
+             8650,            11742,
+            15090,            17407,
+            20391,            23421,
+            26228,            29247,
+             2107,             6323,
+             8915,            12226,
+            14775,            17791,
+            20664,            23679,
+            26829,            29353,
+             1677,             2870,
+             5386,             8077,
+            11817,            15176,
+            18657,            22006,
+            25513,            28689,
+             2111,             3625,
+             7027,            10588,
+            14059,            17193,
+            21137,            24260,
+            27577,            30036,
+             2428,             4010,
+             5765,             9376,
+            13805,            15821,
+            19444,            22389,
+            25295,            29310,
+             2256,             4628,
+             8377,            12441,
+            15283,            19462,
+            22257,            25551,
+            28432,            30304,
+             2352,             3675,
+             6129,            11868,
+            14551,            16655,
+            19624,            21883,
+            26526,            28849,
+             5243,             7248,
+            10558,            13269,
+            15651,            17919,
+            21141,            23827,
+            27102,            29519,
+             4422,             6725,
+            10449,            13273,
+            16124,            19921,
+            22826,            26061,
+            28763,            30583,
+             4508,             6291,
+             9504,            11809,
+            13827,            15950,
+            19077,            22084,
+            25740,            28658,
+             2540,             4297,
+             8579,            13578,
+            16634,            19101,
+            21547,            23887,
+            26777,            29146,
+             3377,             6358,
+            10224,            14518,
+            17905,            21056,
+            23637,            25784,
+            28161,            30109,
+             4177,             5942,
+             8159,            10108,
+            12130,            15470,
+            20191,            23326,
+            26782,            29359,
+             2492,             3801,
+             6144,             9825,
+            16000,            18671,
+            20893,            23663,
+            25899,            28974,
+             3011,             4727,
+             6834,            10505,
+            12465,            14496,
+            17065,            20052,
+            25265,            28057,
+             4149,             7197,
+            12338,            15076,
+            18002,            20190,
+            22187,            24723,
+            27083,            29125,
+             2975,             4578,
+             6448,             8378,
+             9671,            13225,
+            19502,            22277,
+            26058,            28850,
+             4102,             5760,
+             7744,             9484,
+            10744,            12308,
+            14677,            19607,
+            24841,            28381,
+             4931,             9287,
+            12477,            13395,
+            13712,            14351,
+            16048,            19867,
+            24188,            28994,
+             4141,             7867,
+            13140,            17720,
+            20064,            21108,
+            21692,            22722,
+            23736,            27449,
+             4011,             8720,
+            13234,            16206,
+            17601,            18289,
+            18524,            19689,
+            23234,            27882,
+             3420,             5995,
+            11230,            15117,
+            15907,            16783,
+            17762,            23347,
+            26898,            29946,
+             3080,             6786,
+            10465,            13676,
+            18059,            23615,
+            27058,            29082,
+            29563,            29905,
+             3038,             5620,
+             9266,            12870,
+            18803,            19610,
+            20010,            20802,
+            23882,            29306,
+             3314,             6420,
+             9046,            13262,
+            15869,            23117,
+            23667,            24215,
+            24487,            25915,
+             3469,             6963,
+            10103,            15282,
+            20531,            23240,
+            25024,            26021,
+            26736,            27255,
+             3041,             6459,
+             9777,            12896,
+            16315,            19410,
+            24070,            29353,
+            31795,            32075,
+             -200,             -134,
+             -113,             -204,
+             -347,             -440,
+             -352,             -211,
+             -418,             -172,
+             -313,               59,
+              495,              772,
+              721,              614,
+              334,              444,
+              225,              242,
+              161,               16,
+              274,              564,
+              -73,             -188,
+             -395,             -171,
+              777,              508,
+             1340,             1145,
+              699,              196,
+              223,              173,
+               90,               25,
+              -26,               18,
+              133,             -105,
+             -360,             -277,
+              859,              634,
+               41,             -557,
+             -768,             -926,
+             -601,            -1021,
+            -1189,             -365,
+              225,              107,
+              374,              -50,
+              433,              417,
+              156,               39,
+             -597,            -1397,
+            -1594,             -592,
+             -485,             -292,
+              253,               87,
+               -0,               -6,
+              -25,             -345,
+             -240,              120,
+             1261,              946,
+              166,             -277,
+              241,              167,
+              170,              429,
+              518,              714,
+              602,              254,
+              134,               92,
+             -152,             -324,
+             -394,               49,
+             -151,             -304,
+             -724,             -657,
+             -162,             -369,
+              -35,                3,
+               -2,             -312,
+             -200,              -92,
+             -227,              242,
+              628,              565,
+             -124,             1056,
+              770,              101,
+              -84,              -33,
+                4,             -192,
+             -272,                5,
+             -627,             -977,
+              419,              472,
+               53,             -103,
+              145,              322,
+              -95,              -31,
+             -100,             -303,
+             -560,            -1067,
+             -413,              714,
+              283,                2,
+             -223,             -367,
+              523,              360,
+              -38,             -115,
+              378,             -591,
+             -718,              448,
+             -481,             -274,
+              180,              -88,
+             -581,             -157,
+             -696,            -1265,
+              394,             -479,
+              -23,              124,
+              -43,               19,
+             -113,             -236,
+             -412,             -659,
+             -200,                2,
+              -69,             -342,
+              199,               55,
+               58,              -36,
+              -51,              -62,
+              507,              507,
+              427,              442,
+               36,              601,
+             -141,               68,
+              274,              274,
+               68,              -12,
+               -4,               71,
+             -193,             -464,
+             -425,             -383,
+              408,              203,
+             -337,              236,
+              410,              -59,
+              -25,             -341,
+             -449,               28,
+               -9,               90,
+              332,              -14,
+             -905,               96,
+             -540,             -242,
+              679,              -59,
+              192,              -24,
+               60,             -217,
+                5,              -37,
+              179,              -20,
+              311,              519,
+              274,               72,
+             -326,            -1030,
+             -262,              213,
+              380,               82,
+              328,              411,
+             -540,              574,
+             -283,              151,
+              181,             -402,
+             -278,             -240,
+             -110,             -227,
+             -264,              -89,
+             -250,             -259,
+              -27,              106,
+             -239,              -98,
+             -390,              118,
+               61,              104,
+              294,              532,
+               92,              -13,
+               60,             -233,
+              335,              541,
+              307,              -26,
+             -110,              -91,
+             -231,             -460,
+              170,              201,
+               96,             -372,
+              132,              435,
+             -302,              216,
+             -279,              -41,
+               74,              190,
+              368,              273,
+             -186,             -608,
+             -157,              159,
+               12,              278,
+              245,              307,
+               25,             -187,
+              -16,               55,
+               30,             -163,
+              548,             -307,
+              106,               -5,
+               27,              330,
+             -416,              475,
+              438,             -235,
+              104,              137,
+               21,               -5,
+             -300,             -468,
+              521,             -347,
+              170,             -200,
+             -219,              308,
+             -122,             -133,
+              219,              -16,
+              359,              412,
+              -89,             -111,
+               48,              322,
+              142,              177,
+             -286,             -127,
+              -39,              -63,
+              -42,             -451,
+              160,              308,
+              -57,              193,
+              -48,               74,
+             -346,               59,
+              -27,               27,
+             -469,             -277,
+             -344,              282,
+              262,              122,
+              171,             -249,
+               27,              258,
+              188,               -3,
+               67,             -206,
+             -284,              291,
+             -117,              -88,
+             -477,              375,
+               50,              106,
+               99,             -182,
+              438,             -376,
+             -401,              -49,
+              119,              -23,
+              -10,              -48,
+             -116,             -200,
+             -310,              121,
+               73,                7,
+              237,             -226,
+              139,             -456,
+              397,               35,
+                3,             -108,
+              323,              -75,
+              332,              198,
+              -99,              -21
+};
+
+const SKP_Silk_NLSF_CBS SKP_Silk_NLSF_CB1_10_Stage_info[ NLSF_MSVQ_CB1_10_STAGES ] =
+{
+        {  32, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *   0 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[   0 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *  32 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[  32 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *  40 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[  40 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *  48 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[  48 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *  56 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[  56 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_10_Q15[ 10 *  64 ], &SKP_Silk_NLSF_MSVQ_CB1_10_rates_Q5[  64 ] }
+};
+
+const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB1_10 =
+{
+        NLSF_MSVQ_CB1_10_STAGES,
+        SKP_Silk_NLSF_CB1_10_Stage_info,
+        SKP_Silk_NLSF_MSVQ_CB1_10_ndelta_min_Q15,
+        SKP_Silk_NLSF_MSVQ_CB1_10_CDF,
+        SKP_Silk_NLSF_MSVQ_CB1_10_CDF_start_ptr,
+        SKP_Silk_NLSF_MSVQ_CB1_10_CDF_middle_idx
+};
+
index 7d110ff1f60a6dd3a458f9e3b56e78e68a0385c4..b70e3e3c64ba09e8fcfdc614f9f226caab9a6163 100644 (file)
@@ -1,51 +1,51 @@
-/***********************************************************************\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
-#ifndef SKP_SILK_TABLES_NLSF_CB1_10_H\r
-#define SKP_SILK_TABLES_NLSF_CB1_10_H\r
-\r
-#include "SKP_Silk_define.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-#define NLSF_MSVQ_CB1_10_STAGES       6\r
-#define NLSF_MSVQ_CB1_10_VECTORS      72\r
-\r
-/* NLSF codebook entropy coding tables */\r
-extern const SKP_uint16         SKP_Silk_NLSF_MSVQ_CB1_10_CDF[ NLSF_MSVQ_CB1_10_VECTORS + NLSF_MSVQ_CB1_10_STAGES ];\r
-extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB1_10_CDF_start_ptr[                  NLSF_MSVQ_CB1_10_STAGES ];\r
-extern const SKP_int            SKP_Silk_NLSF_MSVQ_CB1_10_CDF_middle_idx[                 NLSF_MSVQ_CB1_10_STAGES ];\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_TABLES_NLSF_CB1_10_H
+#define SKP_SILK_TABLES_NLSF_CB1_10_H
+
+#include "SKP_Silk_define.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define NLSF_MSVQ_CB1_10_STAGES       6
+#define NLSF_MSVQ_CB1_10_VECTORS      72
+
+/* NLSF codebook entropy coding tables */
+extern const SKP_uint16         SKP_Silk_NLSF_MSVQ_CB1_10_CDF[ NLSF_MSVQ_CB1_10_VECTORS + NLSF_MSVQ_CB1_10_STAGES ];
+extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB1_10_CDF_start_ptr[                  NLSF_MSVQ_CB1_10_STAGES ];
+extern const SKP_int            SKP_Silk_NLSF_MSVQ_CB1_10_CDF_middle_idx[                 NLSF_MSVQ_CB1_10_STAGES ];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
index 4d727ff7461685db710edf9cd34af64772a42d23..5db144f4b68a4db06418e76cd066267d80abcefe 100644 (file)
-/***********************************************************************\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
-/* This file has been automatically generated */\r
-/*                                            */\r
-/* ROM usage:  0.29 + 3.57 kB                 */\r
-/**********************************************/\r
-\r
-#include "SKP_Silk_structs.h"\r
-#include "SKP_Silk_tables_NLSF_CB1_16.h"\r
-#include "SKP_Silk_tables.h"\r
-\r
-const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB1_16_CDF[ NLSF_MSVQ_CB1_16_VECTORS + NLSF_MSVQ_CB1_16_STAGES ] =\r
-{\r
-            0,\r
-        19099,\r
-        26957,\r
-        30639,\r
-        34242,\r
-        37546,\r
-        40447,\r
-        43287,\r
-        46005,\r
-        48445,\r
-        49865,\r
-        51284,\r
-        52673,\r
-        53975,\r
-        55221,\r
-        56441,\r
-        57267,\r
-        58025,\r
-        58648,\r
-        59232,\r
-        59768,\r
-        60248,\r
-        60729,\r
-        61210,\r
-        61690,\r
-        62171,\r
-        62651,\r
-        63132,\r
-        63613,\r
-        64093,\r
-        64574,\r
-        65054,\r
-        65535,\r
-            0,\r
-        28808,\r
-        38775,\r
-        46801,\r
-        51785,\r
-        55886,\r
-        59410,\r
-        62572,\r
-        65535,\r
-            0,\r
-        27376,\r
-        38639,\r
-        45052,\r
-        51465,\r
-        55448,\r
-        59021,\r
-        62594,\r
-        65535,\r
-            0,\r
-        33403,\r
-        39569,\r
-        45102,\r
-        49961,\r
-        54047,\r
-        57959,\r
-        61788,\r
-        65535,\r
-            0,\r
-        25851,\r
-        43356,\r
-        47828,\r
-        52204,\r
-        55964,\r
-        59413,\r
-        62507,\r
-        65535,\r
-            0,\r
-        34277,\r
-        40337,\r
-        45432,\r
-        50311,\r
-        54326,\r
-        58171,\r
-        61853,\r
-        65535,\r
-            0,\r
-        33538,\r
-        39865,\r
-        45302,\r
-        50076,\r
-        54549,\r
-        58478,\r
-        62159,\r
-        65535,\r
-            0,\r
-        27445,\r
-        35258,\r
-        40665,\r
-        46072,\r
-        51362,\r
-        56540,\r
-        61086,\r
-        65535,\r
-            0,\r
-        22080,\r
-        30779,\r
-        37065,\r
-        43085,\r
-        48849,\r
-        54613,\r
-        60133,\r
-        65535,\r
-            0,\r
-        13417,\r
-        21748,\r
-        30078,\r
-        38231,\r
-        46383,\r
-        53091,\r
-        59515,\r
-        65535\r
-};\r
-\r
-const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB1_16_CDF_start_ptr[ NLSF_MSVQ_CB1_16_STAGES ] =\r
-{\r
-     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[   0 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  33 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  42 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  51 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  60 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  69 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  78 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  87 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  96 ],\r
-     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[ 105 ]\r
-};\r
-\r
-const SKP_int SKP_Silk_NLSF_MSVQ_CB1_16_CDF_middle_idx[ NLSF_MSVQ_CB1_16_STAGES ] =\r
-{\r
-       5,\r
-       2,\r
-       2,\r
-       2,\r
-       2,\r
-       2,\r
-       2,\r
-       3,\r
-       3,\r
-       4\r
-};\r
-\r
-const SKP_int16 SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[ NLSF_MSVQ_CB1_16_VECTORS ] =\r
-{\r
-               57,               98,\r
-              133,              134,\r
-              138,              144,\r
-              145,              147,\r
-              152,              177,\r
-              177,              178,\r
-              181,              183,\r
-              184,              202,\r
-              206,              215,\r
-              218,              222,\r
-              227,              227,\r
-              227,              227,\r
-              227,              227,\r
-              227,              227,\r
-              227,              227,\r
-              227,              227,\r
-               38,               87,\r
-               97,              119,\r
-              128,              135,\r
-              140,              143,\r
-               40,               81,\r
-              107,              107,\r
-              129,              134,\r
-              134,              143,\r
-               31,              109,\r
-              114,              120,\r
-              128,              130,\r
-              131,              132,\r
-               43,               61,\r
-              124,              125,\r
-              132,              136,\r
-              141,              142,\r
-               30,              110,\r
-              118,              120,\r
-              129,              131,\r
-              133,              133,\r
-               31,              108,\r
-              115,              121,\r
-              124,              130,\r
-              133,              137,\r
-               40,               98,\r
-              115,              115,\r
-              116,              117,\r
-              123,              124,\r
-               50,               93,\r
-              108,              110,\r
-              112,              112,\r
-              114,              115,\r
-               73,               95,\r
-               95,               96,\r
-               96,              105,\r
-              107,              110\r
-};\r
-\r
-const SKP_int SKP_Silk_NLSF_MSVQ_CB1_16_ndelta_min_Q15[ 16 + 1 ] =\r
-{\r
-              148,\r
-                3,\r
-               60,\r
-               68,\r
-              117,\r
-               86,\r
-              121,\r
-              124,\r
-              152,\r
-              153,\r
-              207,\r
-              151,\r
-              225,\r
-              239,\r
-              126,\r
-              183,\r
-              792\r
-};\r
-\r
-const SKP_int16 SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 * NLSF_MSVQ_CB1_16_VECTORS ] =\r
-{\r
-             1309,             3060,             5071,             6996,\r
-             9028,            10938,            12934,            14891,\r
-            16933,            18854,            20792,            22764,\r
-            24753,            26659,            28626,            30501,\r
-             1264,             2745,             4610,             6408,\r
-             8286,            10043,            12084,            14108,\r
-            16118,            18163,            20095,            22164,\r
-            24264,            26316,            28329,            30251,\r
-             1044,             2080,             3672,             5179,\r
-             7140,             9100,            11070,            13065,\r
-            15423,            17790,            19931,            22101,\r
-            24290,            26361,            28499,            30418,\r
-             1131,             2476,             4478,             6149,\r
-             7902,             9875,            11938,            13809,\r
-            15869,            17730,            19948,            21707,\r
-            23761,            25535,            27426,            28917,\r
-             1040,             2004,             4026,             6100,\r
-             8432,            10494,            12610,            14694,\r
-            16797,            18775,            20799,            22782,\r
-            24772,            26682,            28631,            30516,\r
-             2310,             3812,             5913,             7933,\r
-            10033,            11881,            13885,            15798,\r
-            17751,            19576,            21482,            23276,\r
-            25157,            27010,            28833,            30623,\r
-             1254,             2847,             5013,             6781,\r
-             8626,            10370,            12726,            14633,\r
-            16281,            17852,            19870,            21472,\r
-            23002,            24629,            26710,            27960,\r
-             1468,             3059,             4987,             7026,\r
-             8741,            10412,            12281,            14020,\r
-            15970,            17723,            19640,            21522,\r
-            23472,            25661,            27986,            30225,\r
-             2171,             3566,             5605,             7384,\r
-             9404,            11220,            13030,            14758,\r
-            16687,            18417,            20346,            22091,\r
-            24055,            26212,            28356,            30397,\r
-             2409,             4676,             7543,             9786,\r
-            11419,            12935,            14368,            15653,\r
-            17366,            18943,            20762,            22477,\r
-            24440,            26327,            28284,            30242,\r
-             2354,             4222,             6820,             9107,\r
-            11596,            13934,            15973,            17682,\r
-            19158,            20517,            21991,            23420,\r
-            25178,            26936,            28794,            30527,\r
-             1323,             2414,             4184,             6039,\r
-             7534,             9398,            11099,            13097,\r
-            14799,            16451,            18434,            20887,\r
-            23490,            25838,            28046,            30225,\r
-             1361,             3243,             6048,             8511,\r
-            11001,            13145,            15073,            16608,\r
-            18126,            19381,            20912,            22607,\r
-            24660,            26668,            28663,            30566,\r
-             1216,             2648,             5901,             8422,\r
-            10037,            11425,            12973,            14603,\r
-            16686,            18600,            20555,            22415,\r
-            24450,            26280,            28206,            30077,\r
-             2417,             4048,             6316,             8433,\r
-            10510,            12757,            15072,            17295,\r
-            19573,            21503,            23329,            24782,\r
-            26235,            27689,            29214,            30819,\r
-             1012,             2345,             4991,             7377,\r
-             9465,            11916,            14296,            16566,\r
-            18672,            20544,            22292,            23838,\r
-            25415,            27050,            28848,            30551,\r
-             1937,             3693,             6267,             8019,\r
-            10372,            12194,            14287,            15657,\r
-            17431,            18864,            20769,            22206,\r
-            24037,            25463,            27383,            28602,\r
-             1969,             3305,             5017,             6726,\r
-             8375,             9993,            11634,            13280,\r
-            15078,            16751,            18464,            20119,\r
-            21959,            23858,            26224,            29298,\r
-             1198,             2647,             5428,             7423,\r
-             9775,            12155,            14665,            16344,\r
-            18121,            19790,            21557,            22847,\r
-            24484,            25742,            27639,            28711,\r
-             1636,             3353,             5447,             7597,\r
-             9837,            11647,            13964,            16019,\r
-            17862,            20116,            22319,            24037,\r
-            25966,            28086,            29914,            31294,\r
-             2676,             4105,             6378,             8223,\r
-            10058,            11549,            13072,            14453,\r
-            15956,            17355,            18931,            20402,\r
-            22183,            23884,            25717,            27723,\r
-             1373,             2593,             4449,             5633,\r
-             7300,             8425,             9474,            10818,\r
-            12769,            15722,            19002,            21429,\r
-            23682,            25924,            28135,            30333,\r
-             1596,             3183,             5378,             7164,\r
-             8670,            10105,            11470,            12834,\r
-            13991,            15042,            16642,            17903,\r
-            20759,            25283,            27770,            30240,\r
-             2037,             3987,             6237,             8117,\r
-             9954,            12245,            14217,            15892,\r
-            17775,            20114,            22314,            25942,\r
-            26305,            26483,            26796,            28561,\r
-             2181,             3858,             5760,             7924,\r
-            10041,            11577,            13769,            15700,\r
-            17429,            19879,            23583,            24538,\r
-            25212,            25693,            28688,            30507,\r
-             1992,             3882,             6474,             7883,\r
-             9381,            12672,            14340,            15701,\r
-            16658,            17832,            20850,            22885,\r
-            24677,            26457,            28491,            30460,\r
-             2391,             3988,             5448,             7432,\r
-            11014,            12579,            13140,            14146,\r
-            15898,            18592,            21104,            22993,\r
-            24673,            27186,            28142,            29612,\r
-             1713,             5102,             6989,             7798,\r
-             8670,            10110,            12746,            14881,\r
-            16709,            18407,            20126,            22107,\r
-            24181,            26198,            28237,            30137,\r
-             1612,             3617,             6148,             8359,\r
-             9576,            11528,            14936,            17809,\r
-            18287,            18729,            19001,            21111,\r
-            24631,            26596,            28740,            30643,\r
-             2266,             4168,             7862,             9546,\r
-             9618,             9703,            10134,            13897,\r
-            16265,            18432,            20587,            22605,\r
-            24754,            26994,            29125,            30840,\r
-             1840,             3917,             6272,             7809,\r
-             9714,            11438,            13767,            15799,\r
-            19244,            21972,            22980,            23180,\r
-            23723,            25650,            29117,            31085,\r
-             1458,             3612,             6008,             7488,\r
-             9827,            11893,            14086,            15734,\r
-            17440,            19535,            22424,            24767,\r
-            29246,            29928,            30516,            30947,\r
-             -102,             -121,              -31,               -6,\r
-                5,               -2,                8,              -18,\r
-               -4,                6,               14,               -2,\r
-              -12,              -16,              -12,              -60,\r
-             -126,             -353,             -574,             -677,\r
-             -657,             -617,             -498,             -393,\r
-             -348,             -277,             -225,             -164,\r
-             -102,              -70,              -31,               33,\r
-                4,              379,              387,              551,\r
-              605,              620,              532,              482,\r
-              442,              454,              385,              347,\r
-              322,              299,              266,              200,\r
-             1168,              951,              672,              246,\r
-               60,             -161,             -259,             -234,\r
-             -253,             -282,             -203,             -187,\r
-             -155,             -176,             -198,             -178,\r
-               10,              170,              393,              609,\r
-              555,              208,             -330,             -571,\r
-             -769,             -633,             -319,              -43,\r
-               95,              105,              106,              116,\r
-             -152,             -140,             -125,                5,\r
-              173,              274,              264,              331,\r
-              -37,             -293,             -609,             -786,\r
-             -959,             -814,             -645,             -238,\r
-              -91,               36,              -11,             -101,\r
-             -279,             -227,              -40,               90,\r
-              530,              677,              890,             1104,\r
-              999,              835,              564,              295,\r
-             -280,             -364,             -340,             -331,\r
-             -284,              288,              761,              880,\r
-              988,              627,              146,             -226,\r
-             -203,             -181,             -142,               39,\r
-               24,              -26,             -107,              -92,\r
-             -161,             -135,             -131,              -88,\r
-             -160,             -156,              -75,              -43,\r
-              -36,               -6,              -33,               33,\r
-             -324,             -415,             -108,              124,\r
-              157,              191,              203,              197,\r
-              144,              109,              152,              176,\r
-              190,              122,              101,              159,\r
-              663,              668,              480,              400,\r
-              379,              444,              446,              458,\r
-              343,              351,              310,              228,\r
-              133,               44,               75,               63,\r
-              -84,               39,              -29,               35,\r
-              -94,             -233,             -261,             -354,\r
-               77,              262,              -24,             -145,\r
-             -333,             -409,             -404,             -597,\r
-             -488,             -300,              910,              592,\r
-              412,              120,              130,              -51,\r
-              -37,              -77,             -172,             -181,\r
-             -159,             -148,              -72,              -62,\r
-              510,              516,              113,             -585,\r
-            -1075,             -957,             -417,             -195,\r
-                9,                7,              -88,             -173,\r
-              -91,               54,               98,               95,\r
-              -28,              197,             -527,             -621,\r
-              157,              122,             -168,              147,\r
-              309,              300,              336,              315,\r
-              396,              408,              376,              106,\r
-             -162,             -170,             -315,               98,\r
-              821,              908,              570,              -33,\r
-             -312,             -568,             -572,             -378,\r
-             -107,               23,              156,               93,\r
-             -129,              -87,               20,              -72,\r
-              -37,               40,               21,               27,\r
-               48,               75,               77,               65,\r
-               46,               71,               66,               47,\r
-              136,              344,              236,              322,\r
-              170,              283,              269,              291,\r
-              162,              -43,             -204,             -259,\r
-             -240,             -305,             -350,             -312,\r
-              447,              348,              345,              257,\r
-               71,             -131,              -77,             -190,\r
-             -202,              -40,               35,              133,\r
-              261,              365,              438,              303,\r
-               -8,               22,              140,              137,\r
-             -300,             -641,             -764,             -268,\r
-              -23,              -25,               73,             -162,\r
-             -150,             -212,              -72,                6,\r
-               39,               78,              104,              -93,\r
-             -308,             -136,              117,              -71,\r
-             -513,             -820,             -700,             -450,\r
-             -161,              -23,               29,               78,\r
-              337,              106,             -406,             -782,\r
-             -112,              233,              383,               62,\r
-             -126,                6,              -77,              -29,\r
-             -146,             -123,              -51,              -27,\r
-              -27,             -381,             -641,              402,\r
-              539,                8,             -207,             -366,\r
-              -36,              -27,             -204,             -227,\r
-             -237,             -189,              -64,               51,\r
-              -92,             -137,             -281,               62,\r
-              233,               92,              148,              294,\r
-              363,              416,              564,              625,\r
-              370,              -36,             -469,             -462,\r
-              102,              168,               32,              117,\r
-              -21,               97,              139,               89,\r
-              104,               35,                4,               82,\r
-               66,               58,               73,               93,\r
-              -76,             -320,             -236,             -189,\r
-             -203,             -142,              -27,              -73,\r
-                9,               -9,              -25,               12,\r
-              -15,                4,                4,              -50,\r
-              314,              180,              162,              -49,\r
-              199,             -108,             -227,              -66,\r
-             -447,              -67,             -264,             -394,\r
-                5,               55,             -133,             -176,\r
-             -116,             -241,              272,              109,\r
-              282,              262,              192,              -64,\r
-             -392,             -514,              156,              203,\r
-              154,               72,              -34,             -160,\r
-              -73,                3,              -33,             -431,\r
-              321,               18,             -567,             -590,\r
-             -108,               88,               66,               51,\r
-              -31,             -193,              -46,               65,\r
-              -29,              -23,              215,              -31,\r
-              101,             -113,               32,              304,\r
-               88,              320,              448,                5,\r
-             -439,             -562,             -508,             -135,\r
-              -13,             -171,               -8,              182,\r
-              -99,             -181,             -149,              376,\r
-              476,               64,             -396,             -652,\r
-             -150,              176,              222,               65,\r
-             -590,              719,              271,              399,\r
-              245,               72,             -156,             -152,\r
-             -176,               59,               94,              125,\r
-               -9,               -7,                9,                1,\r
-              -61,             -116,              -82,                1,\r
-               79,               22,              -44,              -15,\r
-              -48,              -65,              -62,             -101,\r
-             -102,              -54,              -70,              -78,\r
-              -80,              -25,              398,               71,\r
-              139,               38,               90,              194,\r
-              222,              249,              165,               94,\r
-              221,              262,              163,               91,\r
-             -206,              573,              200,             -287,\r
-             -147,                5,              -18,              -85,\r
-              -74,             -125,              -87,               85,\r
-              141,                4,               -4,               28,\r
-              234,               48,             -150,             -111,\r
-             -506,              237,             -209,              345,\r
-               94,             -124,               77,              121,\r
-              143,               12,              -80,              -48,\r
-              191,              144,              -93,              -65,\r
-             -151,             -643,              435,              106,\r
-               87,                7,               65,              102,\r
-               94,               68,                5,               99,\r
-              222,               93,               94,              355,\r
-              -13,              -89,             -228,             -503,\r
-              287,              109,              108,              449,\r
-              253,              -29,             -109,             -116,\r
-               15,              -73,              -20,              131,\r
-             -147,               72,               59,             -150,\r
-             -594,              273,              316,              132,\r
-              199,              106,              198,              212,\r
-              220,               82,               45,              -13,\r
-              223,              137,              270,               38,\r
-              252,              135,             -177,             -207,\r
-             -360,             -102,              403,              406,\r
-              -14,               83,               64,               51,\r
-               -7,              -99,              -97,              -88,\r
-             -124,              -65,               42,               32,\r
-               28,               29,               12,               20,\r
-              119,              -26,             -212,             -201,\r
-              373,              251,              141,              103,\r
-               36,              -52,               66,               18,\r
-               -6,              -95,             -196,                5,\r
-               98,              -85,             -108,              218,\r
-             -164,               20,              356,              172,\r
-               37,              266,               23,              112,\r
-              -24,              -99,              -92,             -178,\r
-               29,             -278,              388,              -60,\r
-             -220,              300,              -13,              154,\r
-              191,               15,              -37,             -110,\r
-             -153,             -150,             -114,               -7,\r
-              -94,              -31,              -62,             -177,\r
-                4,              -70,               35,              453,\r
-              147,             -247,             -328,              101,\r
-               20,             -114,              147,              108,\r
-             -119,             -109,             -102,             -238,\r
-               55,             -102,              173,              -89,\r
-              129,              138,             -330,             -160,\r
-              485,              154,              -59,             -170,\r
-              -20,              -34,             -261,              -40,\r
-             -129,               77,              -84,               69,\r
-               83,              160,              169,               63,\r
-             -516,               30,              336,               52,\r
-               -0,              -52,             -124,              158,\r
-               19,              197,              -10,             -375,\r
-              405,              285,              114,             -395,\r
-              -47,              196,               62,               87,\r
-             -106,              -65,              -75,              -69,\r
-              -13,               34,               99,               59,\r
-               83,               98,               44,                0,\r
-               24,               18,               17,               70,\r
-              -22,              194,              208,              144,\r
-              -79,              -15,               32,             -104,\r
-              -28,             -105,             -186,             -212,\r
-             -228,              -79,              -76,               51,\r
-              -71,               72,              118,              -34,\r
-               -3,             -171,                5,                2,\r
-             -108,             -125,               62,              -58,\r
-               58,             -121,               73,             -466,\r
-               92,               63,              -94,              -78,\r
-              -76,              212,               36,             -225,\r
-              -71,             -354,              152,              143,\r
-              -79,             -246,              -51,              -31,\r
-               -6,             -270,              240,              210,\r
-               30,             -157,             -231,               74,\r
-             -146,               88,             -273,              156,\r
-               92,               56,               71,                2,\r
-              318,              164,               32,             -110,\r
-              -35,              -41,              -95,             -106,\r
-               11,              132,              -68,               55,\r
-              123,              -83,             -149,              212,\r
-              132,                0,             -194,               55,\r
-              206,             -108,             -353,              289,\r
-             -195,                1,              233,              -22,\r
-              -60,               20,               26,               68,\r
-              166,               27,              -58,              130,\r
-              112,              107,               27,             -165,\r
-              115,              -93,              -37,               38,\r
-               83,              483,               65,             -229,\r
-              -13,              157,               85,               50,\r
-              136,               10,               32,               83,\r
-               82,               55,                5,               -9,\r
-              -52,              -78,              -81,              -51,\r
-               40,               18,             -127,             -224,\r
-              -41,               53,             -210,             -113,\r
-               24,              -17,             -187,              -89,\r
-                8,              121,               83,               77,\r
-               91,              -74,              -35,             -112,\r
-             -161,             -173,              102,              132,\r
-             -125,              -61,              103,             -260,\r
-               52,              166,              -32,             -156,\r
-              -87,              -56,               60,              -70,\r
-             -124,              242,              114,             -251,\r
-             -166,              201,              127,               28,\r
-              -11,               23,              -80,             -115,\r
-              -20,              -51,             -348,              340,\r
-              -34,              133,               13,               92,\r
-             -124,             -136,             -120,              -26,\r
-               -6,               17,               28,               21,\r
-              120,             -168,              160,              -35,\r
-              115,               28,                9,                7,\r
-              -56,               39,              156,              256,\r
-              -18,                1,              277,               82,\r
-              -70,             -144,              -88,              -13,\r
-              -59,             -157,                8,             -134,\r
-               21,              -40,               58,              -21,\r
-              194,             -276,               97,              279,\r
-              -56,             -140,              125,               57,\r
-             -184,             -204,              -70,               -2,\r
-              128,             -202,              -78,              230,\r
-              -23,              161,             -102,                1,\r
-                1,              180,              -31,              -86,\r
-             -167,              -57,              -60,               27,\r
-              -13,               99,              108,              111,\r
-               76,               69,               34,              -21,\r
-               53,               38,               34,               78,\r
-               73,              219,               51,               15,\r
-              -72,             -103,             -207,               30,\r
-              213,              -14,               31,              -94,\r
-              -40,             -144,               67,                4,\r
-              105,               59,             -240,               25,\r
-              244,               69,               58,               23,\r
-              -24,               -5,              -15,             -133,\r
-              -71,              -67,              181,               29,\r
-              -45,              121,               96,               51,\r
-              -72,              -53,               56,             -153,\r
-              -27,               85,              183,              211,\r
-              105,              -34,              -46,               43,\r
-              -72,              -93,               36,             -128,\r
-               29,              111,              -95,             -156,\r
-             -179,             -235,               21,              -39,\r
-              -71,              -33,              -61,             -252,\r
-              230,             -131,              157,              -21,\r
-              -85,              -28,             -123,               80,\r
-             -160,               63,               47,               -6,\r
-              -49,              -96,              -19,               17,\r
-              -58,               17,               -0,              -13,\r
-             -170,               25,              -35,               59,\r
-               10,              -31,             -413,               81,\r
-               62,               18,             -164,              245,\r
-               92,             -165,               42,               26,\r
-              126,             -248,              193,              -55,\r
-               16,               39,               14,               50\r
-};\r
-\r
-const SKP_Silk_NLSF_CBS SKP_Silk_NLSF_CB1_16_Stage_info[ NLSF_MSVQ_CB1_16_STAGES ] =\r
-{\r
-        {  32, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *   0 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[   0 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  32 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  32 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  40 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  40 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  48 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  48 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  56 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  56 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  64 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  64 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  72 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  72 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  80 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  80 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  88 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  88 ] },\r
-        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  96 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  96 ] }\r
-};\r
-\r
-const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB1_16 =\r
-{\r
-        NLSF_MSVQ_CB1_16_STAGES,\r
-        SKP_Silk_NLSF_CB1_16_Stage_info,\r
-        SKP_Silk_NLSF_MSVQ_CB1_16_ndelta_min_Q15,\r
-        SKP_Silk_NLSF_MSVQ_CB1_16_CDF,\r
-        SKP_Silk_NLSF_MSVQ_CB1_16_CDF_start_ptr,\r
-        SKP_Silk_NLSF_MSVQ_CB1_16_CDF_middle_idx\r
-};\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/**********************************************/
+/* This file has been automatically generated */
+/*                                            */
+/* ROM usage:  0.29 + 3.57 kB                 */
+/**********************************************/
+
+#include "SKP_Silk_structs.h"
+#include "SKP_Silk_tables_NLSF_CB1_16.h"
+#include "SKP_Silk_tables.h"
+
+const SKP_uint16 SKP_Silk_NLSF_MSVQ_CB1_16_CDF[ NLSF_MSVQ_CB1_16_VECTORS + NLSF_MSVQ_CB1_16_STAGES ] =
+{
+            0,
+        19099,
+        26957,
+        30639,
+        34242,
+        37546,
+        40447,
+        43287,
+        46005,
+        48445,
+        49865,
+        51284,
+        52673,
+        53975,
+        55221,
+        56441,
+        57267,
+        58025,
+        58648,
+        59232,
+        59768,
+        60248,
+        60729,
+        61210,
+        61690,
+        62171,
+        62651,
+        63132,
+        63613,
+        64093,
+        64574,
+        65054,
+        65535,
+            0,
+        28808,
+        38775,
+        46801,
+        51785,
+        55886,
+        59410,
+        62572,
+        65535,
+            0,
+        27376,
+        38639,
+        45052,
+        51465,
+        55448,
+        59021,
+        62594,
+        65535,
+            0,
+        33403,
+        39569,
+        45102,
+        49961,
+        54047,
+        57959,
+        61788,
+        65535,
+            0,
+        25851,
+        43356,
+        47828,
+        52204,
+        55964,
+        59413,
+        62507,
+        65535,
+            0,
+        34277,
+        40337,
+        45432,
+        50311,
+        54326,
+        58171,
+        61853,
+        65535,
+            0,
+        33538,
+        39865,
+        45302,
+        50076,
+        54549,
+        58478,
+        62159,
+        65535,
+            0,
+        27445,
+        35258,
+        40665,
+        46072,
+        51362,
+        56540,
+        61086,
+        65535,
+            0,
+        22080,
+        30779,
+        37065,
+        43085,
+        48849,
+        54613,
+        60133,
+        65535,
+            0,
+        13417,
+        21748,
+        30078,
+        38231,
+        46383,
+        53091,
+        59515,
+        65535
+};
+
+const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB1_16_CDF_start_ptr[ NLSF_MSVQ_CB1_16_STAGES ] =
+{
+     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[   0 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  33 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  42 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  51 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  60 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  69 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  78 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  87 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[  96 ],
+     &SKP_Silk_NLSF_MSVQ_CB1_16_CDF[ 105 ]
+};
+
+const SKP_int SKP_Silk_NLSF_MSVQ_CB1_16_CDF_middle_idx[ NLSF_MSVQ_CB1_16_STAGES ] =
+{
+       5,
+       2,
+       2,
+       2,
+       2,
+       2,
+       2,
+       3,
+       3,
+       4
+};
+
+const SKP_int16 SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[ NLSF_MSVQ_CB1_16_VECTORS ] =
+{
+               57,               98,
+              133,              134,
+              138,              144,
+              145,              147,
+              152,              177,
+              177,              178,
+              181,              183,
+              184,              202,
+              206,              215,
+              218,              222,
+              227,              227,
+              227,              227,
+              227,              227,
+              227,              227,
+              227,              227,
+              227,              227,
+               38,               87,
+               97,              119,
+              128,              135,
+              140,              143,
+               40,               81,
+              107,              107,
+              129,              134,
+              134,              143,
+               31,              109,
+              114,              120,
+              128,              130,
+              131,              132,
+               43,               61,
+              124,              125,
+              132,              136,
+              141,              142,
+               30,              110,
+              118,              120,
+              129,              131,
+              133,              133,
+               31,              108,
+              115,              121,
+              124,              130,
+              133,              137,
+               40,               98,
+              115,              115,
+              116,              117,
+              123,              124,
+               50,               93,
+              108,              110,
+              112,              112,
+              114,              115,
+               73,               95,
+               95,               96,
+               96,              105,
+              107,              110
+};
+
+const SKP_int SKP_Silk_NLSF_MSVQ_CB1_16_ndelta_min_Q15[ 16 + 1 ] =
+{
+              148,
+                3,
+               60,
+               68,
+              117,
+               86,
+              121,
+              124,
+              152,
+              153,
+              207,
+              151,
+              225,
+              239,
+              126,
+              183,
+              792
+};
+
+const SKP_int16 SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 * NLSF_MSVQ_CB1_16_VECTORS ] =
+{
+             1309,             3060,             5071,             6996,
+             9028,            10938,            12934,            14891,
+            16933,            18854,            20792,            22764,
+            24753,            26659,            28626,            30501,
+             1264,             2745,             4610,             6408,
+             8286,            10043,            12084,            14108,
+            16118,            18163,            20095,            22164,
+            24264,            26316,            28329,            30251,
+             1044,             2080,             3672,             5179,
+             7140,             9100,            11070,            13065,
+            15423,            17790,            19931,            22101,
+            24290,            26361,            28499,            30418,
+             1131,             2476,             4478,             6149,
+             7902,             9875,            11938,            13809,
+            15869,            17730,            19948,            21707,
+            23761,            25535,            27426,            28917,
+             1040,             2004,             4026,             6100,
+             8432,            10494,            12610,            14694,
+            16797,            18775,            20799,            22782,
+            24772,            26682,            28631,            30516,
+             2310,             3812,             5913,             7933,
+            10033,            11881,            13885,            15798,
+            17751,            19576,            21482,            23276,
+            25157,            27010,            28833,            30623,
+             1254,             2847,             5013,             6781,
+             8626,            10370,            12726,            14633,
+            16281,            17852,            19870,            21472,
+            23002,            24629,            26710,            27960,
+             1468,             3059,             4987,             7026,
+             8741,            10412,            12281,            14020,
+            15970,            17723,            19640,            21522,
+            23472,            25661,            27986,            30225,
+             2171,             3566,             5605,             7384,
+             9404,            11220,            13030,            14758,
+            16687,            18417,            20346,            22091,
+            24055,            26212,            28356,            30397,
+             2409,             4676,             7543,             9786,
+            11419,            12935,            14368,            15653,
+            17366,            18943,            20762,            22477,
+            24440,            26327,            28284,            30242,
+             2354,             4222,             6820,             9107,
+            11596,            13934,            15973,            17682,
+            19158,            20517,            21991,            23420,
+            25178,            26936,            28794,            30527,
+             1323,             2414,             4184,             6039,
+             7534,             9398,            11099,            13097,
+            14799,            16451,            18434,            20887,
+            23490,            25838,            28046,            30225,
+             1361,             3243,             6048,             8511,
+            11001,            13145,            15073,            16608,
+            18126,            19381,            20912,            22607,
+            24660,            26668,            28663,            30566,
+             1216,             2648,             5901,             8422,
+            10037,            11425,            12973,            14603,
+            16686,            18600,            20555,            22415,
+            24450,            26280,            28206,            30077,
+             2417,             4048,             6316,             8433,
+            10510,            12757,            15072,            17295,
+            19573,            21503,            23329,            24782,
+            26235,            27689,            29214,            30819,
+             1012,             2345,             4991,             7377,
+             9465,            11916,            14296,            16566,
+            18672,            20544,            22292,            23838,
+            25415,            27050,            28848,            30551,
+             1937,             3693,             6267,             8019,
+            10372,            12194,            14287,            15657,
+            17431,            18864,            20769,            22206,
+            24037,            25463,            27383,            28602,
+             1969,             3305,             5017,             6726,
+             8375,             9993,            11634,            13280,
+            15078,            16751,            18464,            20119,
+            21959,            23858,            26224,            29298,
+             1198,             2647,             5428,             7423,
+             9775,            12155,            14665,            16344,
+            18121,            19790,            21557,            22847,
+            24484,            25742,            27639,            28711,
+             1636,             3353,             5447,             7597,
+             9837,            11647,            13964,            16019,
+            17862,            20116,            22319,            24037,
+            25966,            28086,            29914,            31294,
+             2676,             4105,             6378,             8223,
+            10058,            11549,            13072,            14453,
+            15956,            17355,            18931,            20402,
+            22183,            23884,            25717,            27723,
+             1373,             2593,             4449,             5633,
+             7300,             8425,             9474,            10818,
+            12769,            15722,            19002,            21429,
+            23682,            25924,            28135,            30333,
+             1596,             3183,             5378,             7164,
+             8670,            10105,            11470,            12834,
+            13991,            15042,            16642,            17903,
+            20759,            25283,            27770,            30240,
+             2037,             3987,             6237,             8117,
+             9954,            12245,            14217,            15892,
+            17775,            20114,            22314,            25942,
+            26305,            26483,            26796,            28561,
+             2181,             3858,             5760,             7924,
+            10041,            11577,            13769,            15700,
+            17429,            19879,            23583,            24538,
+            25212,            25693,            28688,            30507,
+             1992,             3882,             6474,             7883,
+             9381,            12672,            14340,            15701,
+            16658,            17832,            20850,            22885,
+            24677,            26457,            28491,            30460,
+             2391,             3988,             5448,             7432,
+            11014,            12579,            13140,            14146,
+            15898,            18592,            21104,            22993,
+            24673,            27186,            28142,            29612,
+             1713,             5102,             6989,             7798,
+             8670,            10110,            12746,            14881,
+            16709,            18407,            20126,            22107,
+            24181,            26198,            28237,            30137,
+             1612,             3617,             6148,             8359,
+             9576,            11528,            14936,            17809,
+            18287,            18729,            19001,            21111,
+            24631,            26596,            28740,            30643,
+             2266,             4168,             7862,             9546,
+             9618,             9703,            10134,            13897,
+            16265,            18432,            20587,            22605,
+            24754,            26994,            29125,            30840,
+             1840,             3917,             6272,             7809,
+             9714,            11438,            13767,            15799,
+            19244,            21972,            22980,            23180,
+            23723,            25650,            29117,            31085,
+             1458,             3612,             6008,             7488,
+             9827,            11893,            14086,            15734,
+            17440,            19535,            22424,            24767,
+            29246,            29928,            30516,            30947,
+             -102,             -121,              -31,               -6,
+                5,               -2,                8,              -18,
+               -4,                6,               14,               -2,
+              -12,              -16,              -12,              -60,
+             -126,             -353,             -574,             -677,
+             -657,             -617,             -498,             -393,
+             -348,             -277,             -225,             -164,
+             -102,              -70,              -31,               33,
+                4,              379,              387,              551,
+              605,              620,              532,              482,
+              442,              454,              385,              347,
+              322,              299,              266,              200,
+             1168,              951,              672,              246,
+               60,             -161,             -259,             -234,
+             -253,             -282,             -203,             -187,
+             -155,             -176,             -198,             -178,
+               10,              170,              393,              609,
+              555,              208,             -330,             -571,
+             -769,             -633,             -319,              -43,
+               95,              105,              106,              116,
+             -152,             -140,             -125,                5,
+              173,              274,              264,              331,
+              -37,             -293,             -609,             -786,
+             -959,             -814,             -645,             -238,
+              -91,               36,              -11,             -101,
+             -279,             -227,              -40,               90,
+              530,              677,              890,             1104,
+              999,              835,              564,              295,
+             -280,             -364,             -340,             -331,
+             -284,              288,              761,              880,
+              988,              627,              146,             -226,
+             -203,             -181,             -142,               39,
+               24,              -26,             -107,              -92,
+             -161,             -135,             -131,              -88,
+             -160,             -156,              -75,              -43,
+              -36,               -6,              -33,               33,
+             -324,             -415,             -108,              124,
+              157,              191,              203,              197,
+              144,              109,              152,              176,
+              190,              122,              101,              159,
+              663,              668,              480,              400,
+              379,              444,              446,              458,
+              343,              351,              310,              228,
+              133,               44,               75,               63,
+              -84,               39,              -29,               35,
+              -94,             -233,             -261,             -354,
+               77,              262,              -24,             -145,
+             -333,             -409,             -404,             -597,
+             -488,             -300,              910,              592,
+              412,              120,              130,              -51,
+              -37,              -77,             -172,             -181,
+             -159,             -148,              -72,              -62,
+              510,              516,              113,             -585,
+            -1075,             -957,             -417,             -195,
+                9,                7,              -88,             -173,
+              -91,               54,               98,               95,
+              -28,              197,             -527,             -621,
+              157,              122,             -168,              147,
+              309,              300,              336,              315,
+              396,              408,              376,              106,
+             -162,             -170,             -315,               98,
+              821,              908,              570,              -33,
+             -312,             -568,             -572,             -378,
+             -107,               23,              156,               93,
+             -129,              -87,               20,              -72,
+              -37,               40,               21,               27,
+               48,               75,               77,               65,
+               46,               71,               66,               47,
+              136,              344,              236,              322,
+              170,              283,              269,              291,
+              162,              -43,             -204,             -259,
+             -240,             -305,             -350,             -312,
+              447,              348,              345,              257,
+               71,             -131,              -77,             -190,
+             -202,              -40,               35,              133,
+              261,              365,              438,              303,
+               -8,               22,              140,              137,
+             -300,             -641,             -764,             -268,
+              -23,              -25,               73,             -162,
+             -150,             -212,              -72,                6,
+               39,               78,              104,              -93,
+             -308,             -136,              117,              -71,
+             -513,             -820,             -700,             -450,
+             -161,              -23,               29,               78,
+              337,              106,             -406,             -782,
+             -112,              233,              383,               62,
+             -126,                6,              -77,              -29,
+             -146,             -123,              -51,              -27,
+              -27,             -381,             -641,              402,
+              539,                8,             -207,             -366,
+              -36,              -27,             -204,             -227,
+             -237,             -189,              -64,               51,
+              -92,             -137,             -281,               62,
+              233,               92,              148,              294,
+              363,              416,              564,              625,
+              370,              -36,             -469,             -462,
+              102,              168,               32,              117,
+              -21,               97,              139,               89,
+              104,               35,                4,               82,
+               66,               58,               73,               93,
+              -76,             -320,             -236,             -189,
+             -203,             -142,              -27,              -73,
+                9,               -9,              -25,               12,
+              -15,                4,                4,              -50,
+              314,              180,              162,              -49,
+              199,             -108,             -227,              -66,
+             -447,              -67,             -264,             -394,
+                5,               55,             -133,             -176,
+             -116,             -241,              272,              109,
+              282,              262,              192,              -64,
+             -392,             -514,              156,              203,
+              154,               72,              -34,             -160,
+              -73,                3,              -33,             -431,
+              321,               18,             -567,             -590,
+             -108,               88,               66,               51,
+              -31,             -193,              -46,               65,
+              -29,              -23,              215,              -31,
+              101,             -113,               32,              304,
+               88,              320,              448,                5,
+             -439,             -562,             -508,             -135,
+              -13,             -171,               -8,              182,
+              -99,             -181,             -149,              376,
+              476,               64,             -396,             -652,
+             -150,              176,              222,               65,
+             -590,              719,              271,              399,
+              245,               72,             -156,             -152,
+             -176,               59,               94,              125,
+               -9,               -7,                9,                1,
+              -61,             -116,              -82,                1,
+               79,               22,              -44,              -15,
+              -48,              -65,              -62,             -101,
+             -102,              -54,              -70,              -78,
+              -80,              -25,              398,               71,
+              139,               38,               90,              194,
+              222,              249,              165,               94,
+              221,              262,              163,               91,
+             -206,              573,              200,             -287,
+             -147,                5,              -18,              -85,
+              -74,             -125,              -87,               85,
+              141,                4,               -4,               28,
+              234,               48,             -150,             -111,
+             -506,              237,             -209,              345,
+               94,             -124,               77,              121,
+              143,               12,              -80,              -48,
+              191,              144,              -93,              -65,
+             -151,             -643,              435,              106,
+               87,                7,               65,              102,
+               94,               68,                5,               99,
+              222,               93,               94,              355,
+              -13,              -89,             -228,             -503,
+              287,              109,              108,              449,
+              253,              -29,             -109,             -116,
+               15,              -73,              -20,              131,
+             -147,               72,               59,             -150,
+             -594,              273,              316,              132,
+              199,              106,              198,              212,
+              220,               82,               45,              -13,
+              223,              137,              270,               38,
+              252,              135,             -177,             -207,
+             -360,             -102,              403,              406,
+              -14,               83,               64,               51,
+               -7,              -99,              -97,              -88,
+             -124,              -65,               42,               32,
+               28,               29,               12,               20,
+              119,              -26,             -212,             -201,
+              373,              251,              141,              103,
+               36,              -52,               66,               18,
+               -6,              -95,             -196,                5,
+               98,              -85,             -108,              218,
+             -164,               20,              356,              172,
+               37,              266,               23,              112,
+              -24,              -99,              -92,             -178,
+               29,             -278,              388,              -60,
+             -220,              300,              -13,              154,
+              191,               15,              -37,             -110,
+             -153,             -150,             -114,               -7,
+              -94,              -31,              -62,             -177,
+                4,              -70,               35,              453,
+              147,             -247,             -328,              101,
+               20,             -114,              147,              108,
+             -119,             -109,             -102,             -238,
+               55,             -102,              173,              -89,
+              129,              138,             -330,             -160,
+              485,              154,              -59,             -170,
+              -20,              -34,             -261,              -40,
+             -129,               77,              -84,               69,
+               83,              160,              169,               63,
+             -516,               30,              336,               52,
+               -0,              -52,             -124,              158,
+               19,              197,              -10,             -375,
+              405,              285,              114,             -395,
+              -47,              196,               62,               87,
+             -106,              -65,              -75,              -69,
+              -13,               34,               99,               59,
+               83,               98,               44,                0,
+               24,               18,               17,               70,
+              -22,              194,              208,              144,
+              -79,              -15,               32,             -104,
+              -28,             -105,             -186,             -212,
+             -228,              -79,              -76,               51,
+              -71,               72,              118,              -34,
+               -3,             -171,                5,                2,
+             -108,             -125,               62,              -58,
+               58,             -121,               73,             -466,
+               92,               63,              -94,              -78,
+              -76,              212,               36,             -225,
+              -71,             -354,              152,              143,
+              -79,             -246,              -51,              -31,
+               -6,             -270,              240,              210,
+               30,             -157,             -231,               74,
+             -146,               88,             -273,              156,
+               92,               56,               71,                2,
+              318,              164,               32,             -110,
+              -35,              -41,              -95,             -106,
+               11,              132,              -68,               55,
+              123,              -83,             -149,              212,
+              132,                0,             -194,               55,
+              206,             -108,             -353,              289,
+             -195,                1,              233,              -22,
+              -60,               20,               26,               68,
+              166,               27,              -58,              130,
+              112,              107,               27,             -165,
+              115,              -93,              -37,               38,
+               83,              483,               65,             -229,
+              -13,              157,               85,               50,
+              136,               10,               32,               83,
+               82,               55,                5,               -9,
+              -52,              -78,              -81,              -51,
+               40,               18,             -127,             -224,
+              -41,               53,             -210,             -113,
+               24,              -17,             -187,              -89,
+                8,              121,               83,               77,
+               91,              -74,              -35,             -112,
+             -161,             -173,              102,              132,
+             -125,              -61,              103,             -260,
+               52,              166,              -32,             -156,
+              -87,              -56,               60,              -70,
+             -124,              242,              114,             -251,
+             -166,              201,              127,               28,
+              -11,               23,              -80,             -115,
+              -20,              -51,             -348,              340,
+              -34,              133,               13,               92,
+             -124,             -136,             -120,              -26,
+               -6,               17,               28,               21,
+              120,             -168,              160,              -35,
+              115,               28,                9,                7,
+              -56,               39,              156,              256,
+              -18,                1,              277,               82,
+              -70,             -144,              -88,              -13,
+              -59,             -157,                8,             -134,
+               21,              -40,               58,              -21,
+              194,             -276,               97,              279,
+              -56,             -140,              125,               57,
+             -184,             -204,              -70,               -2,
+              128,             -202,              -78,              230,
+              -23,              161,             -102,                1,
+                1,              180,              -31,              -86,
+             -167,              -57,              -60,               27,
+              -13,               99,              108,              111,
+               76,               69,               34,              -21,
+               53,               38,               34,               78,
+               73,              219,               51,               15,
+              -72,             -103,             -207,               30,
+              213,              -14,               31,              -94,
+              -40,             -144,               67,                4,
+              105,               59,             -240,               25,
+              244,               69,               58,               23,
+              -24,               -5,              -15,             -133,
+              -71,              -67,              181,               29,
+              -45,              121,               96,               51,
+              -72,              -53,               56,             -153,
+              -27,               85,              183,              211,
+              105,              -34,              -46,               43,
+              -72,              -93,               36,             -128,
+               29,              111,              -95,             -156,
+             -179,             -235,               21,              -39,
+              -71,              -33,              -61,             -252,
+              230,             -131,              157,              -21,
+              -85,              -28,             -123,               80,
+             -160,               63,               47,               -6,
+              -49,              -96,              -19,               17,
+              -58,               17,               -0,              -13,
+             -170,               25,              -35,               59,
+               10,              -31,             -413,               81,
+               62,               18,             -164,              245,
+               92,             -165,               42,               26,
+              126,             -248,              193,              -55,
+               16,               39,               14,               50
+};
+
+const SKP_Silk_NLSF_CBS SKP_Silk_NLSF_CB1_16_Stage_info[ NLSF_MSVQ_CB1_16_STAGES ] =
+{
+        {  32, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *   0 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[   0 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  32 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  32 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  40 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  40 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  48 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  48 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  56 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  56 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  64 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  64 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  72 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  72 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  80 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  80 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  88 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  88 ] },
+        {   8, &SKP_Silk_NLSF_MSVQ_CB1_16_Q15[ 16 *  96 ], &SKP_Silk_NLSF_MSVQ_CB1_16_rates_Q5[  96 ] }
+};
+
+const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB1_16 =
+{
+        NLSF_MSVQ_CB1_16_STAGES,
+        SKP_Silk_NLSF_CB1_16_Stage_info,
+        SKP_Silk_NLSF_MSVQ_CB1_16_ndelta_min_Q15,
+        SKP_Silk_NLSF_MSVQ_CB1_16_CDF,
+        SKP_Silk_NLSF_MSVQ_CB1_16_CDF_start_ptr,
+        SKP_Silk_NLSF_MSVQ_CB1_16_CDF_middle_idx
+};
+
index f0539d398813f9c8aceef7c646fbe9fe9b9631d5..3187be4b6196015f87c2ace6fe730165be3ddc5e 100644 (file)
@@ -1,51 +1,51 @@
-/***********************************************************************\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
-#ifndef SKP_SILK_TABLES_NLSF_CB1_16_H\r
-#define SKP_SILK_TABLES_NLSF_CB1_16_H\r
-\r
-#include "SKP_Silk_define.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-#define NLSF_MSVQ_CB1_16_STAGES       10\r
-#define NLSF_MSVQ_CB1_16_VECTORS      104\r
-\r
-/* NLSF codebook entropy coding tables */\r
-extern const SKP_uint16         SKP_Silk_NLSF_MSVQ_CB1_16_CDF[ NLSF_MSVQ_CB1_16_VECTORS + NLSF_MSVQ_CB1_16_STAGES ];\r
-extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB1_16_CDF_start_ptr[                  NLSF_MSVQ_CB1_16_STAGES ];\r
-extern const SKP_int            SKP_Silk_NLSF_MSVQ_CB1_16_CDF_middle_idx[                 NLSF_MSVQ_CB1_16_STAGES ];\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_TABLES_NLSF_CB1_16_H
+#define SKP_SILK_TABLES_NLSF_CB1_16_H
+
+#include "SKP_Silk_define.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define NLSF_MSVQ_CB1_16_STAGES       10
+#define NLSF_MSVQ_CB1_16_VECTORS      104
+
+/* NLSF codebook entropy coding tables */
+extern const SKP_uint16         SKP_Silk_NLSF_MSVQ_CB1_16_CDF[ NLSF_MSVQ_CB1_16_VECTORS + NLSF_MSVQ_CB1_16_STAGES ];
+extern const SKP_uint16 * const SKP_Silk_NLSF_MSVQ_CB1_16_CDF_start_ptr[                  NLSF_MSVQ_CB1_16_STAGES ];
+extern const SKP_int            SKP_Silk_NLSF_MSVQ_CB1_16_CDF_middle_idx[                 NLSF_MSVQ_CB1_16_STAGES ];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
index f04ba36dea52200121659885268042826c6515df..74128fd04c65cbcb50b0aac003d7a2e2d4055b4a 100644 (file)
@@ -1,77 +1,77 @@
-/***********************************************************************\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_tables.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-const SKP_uint16 SKP_Silk_gain_CDF[ 2 ][ 65 ] = \r
-{\r
-{\r
-         0,     18,     45,     94,    181,    320,    519,    777,\r
-      1093,   1468,   1909,   2417,   2997,   3657,   4404,   5245,\r
-      6185,   7228,   8384,   9664,  11069,  12596,  14244,  16022,\r
-     17937,  19979,  22121,  24345,  26646,  29021,  31454,  33927,\r
-     36438,  38982,  41538,  44068,  46532,  48904,  51160,  53265,\r
-     55184,  56904,  58422,  59739,  60858,  61793,  62568,  63210,\r
-     63738,  64165,  64504,  64769,  64976,  65133,  65249,  65330,\r
-     65386,  65424,  65451,  65471,  65487,  65501,  65513,  65524,\r
-     65535\r
-},\r
-{\r
-         0,    214,    581,   1261,   2376,   3920,   5742,   7632,\r
-      9449,  11157,  12780,  14352,  15897,  17427,  18949,  20462,\r
-     21957,  23430,  24889,  26342,  27780,  29191,  30575,  31952,\r
-     33345,  34763,  36200,  37642,  39083,  40519,  41930,  43291,\r
-     44602,  45885,  47154,  48402,  49619,  50805,  51959,  53069,\r
-     54127,  55140,  56128,  57101,  58056,  58979,  59859,  60692,\r
-     61468,  62177,  62812,  63368,  63845,  64242,  64563,  64818,\r
-     65023,  65184,  65306,  65391,  65447,  65482,  65505,  65521,\r
-     65535\r
-}\r
-};\r
-\r
-const SKP_int SKP_Silk_gain_CDF_offset = 32;\r
-\r
-\r
-const SKP_uint16 SKP_Silk_delta_gain_CDF[ 46 ] = {\r
-         0,   2358,   3856,   7023,  15376,  53058,  59135,  61555,\r
-     62784,  63498,  63949,  64265,  64478,  64647,  64783,  64894,\r
-     64986,  65052,  65113,  65169,  65213,  65252,  65284,  65314,\r
-     65338,  65359,  65377,  65392,  65403,  65415,  65424,  65432,\r
-     65440,  65448,  65455,  65462,  65470,  65477,  65484,  65491,\r
-     65499,  65506,  65513,  65521,  65528,  65535\r
-};\r
-\r
-const SKP_int SKP_Silk_delta_gain_CDF_offset = 5;\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_tables.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+const SKP_uint16 SKP_Silk_gain_CDF[ 2 ][ 65 ] = 
+{
+{
+         0,     18,     45,     94,    181,    320,    519,    777,
+      1093,   1468,   1909,   2417,   2997,   3657,   4404,   5245,
+      6185,   7228,   8384,   9664,  11069,  12596,  14244,  16022,
+     17937,  19979,  22121,  24345,  26646,  29021,  31454,  33927,
+     36438,  38982,  41538,  44068,  46532,  48904,  51160,  53265,
+     55184,  56904,  58422,  59739,  60858,  61793,  62568,  63210,
+     63738,  64165,  64504,  64769,  64976,  65133,  65249,  65330,
+     65386,  65424,  65451,  65471,  65487,  65501,  65513,  65524,
+     65535
+},
+{
+         0,    214,    581,   1261,   2376,   3920,   5742,   7632,
+      9449,  11157,  12780,  14352,  15897,  17427,  18949,  20462,
+     21957,  23430,  24889,  26342,  27780,  29191,  30575,  31952,
+     33345,  34763,  36200,  37642,  39083,  40519,  41930,  43291,
+     44602,  45885,  47154,  48402,  49619,  50805,  51959,  53069,
+     54127,  55140,  56128,  57101,  58056,  58979,  59859,  60692,
+     61468,  62177,  62812,  63368,  63845,  64242,  64563,  64818,
+     65023,  65184,  65306,  65391,  65447,  65482,  65505,  65521,
+     65535
+}
+};
+
+const SKP_int SKP_Silk_gain_CDF_offset = 32;
+
+
+const SKP_uint16 SKP_Silk_delta_gain_CDF[ 46 ] = {
+         0,   2358,   3856,   7023,  15376,  53058,  59135,  61555,
+     62784,  63498,  63949,  64265,  64478,  64647,  64783,  64894,
+     64986,  65052,  65113,  65169,  65213,  65252,  65284,  65314,
+     65338,  65359,  65377,  65392,  65403,  65415,  65424,  65432,
+     65440,  65448,  65455,  65462,  65470,  65477,  65484,  65491,
+     65499,  65506,  65513,  65521,  65528,  65535
+};
+
+const SKP_int SKP_Silk_delta_gain_CDF_offset = 5;
+
+#ifdef __cplusplus
+}
+#endif
index 45213c4df57573ce91e5919473269df867b41662..057782120a8d44812e5fd621532852a259ee1b1b 100644 (file)
-/***********************************************************************\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_structs.h"\r
-#include "SKP_Silk_define.h"\r
-#include "SKP_Silk_tables.h"\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-/* Piece-wise linear mapping from bitrate in kbps to coding quality in dB SNR */\r
-const SKP_int32 TargetRate_table_NB[ TARGET_RATE_TAB_SZ ] = {\r
-    0,      8000,   9000,   11000,  13000,  16000,  22000,  MAX_TARGET_RATE_BPS\r
-};\r
-const SKP_int32 TargetRate_table_MB[ TARGET_RATE_TAB_SZ ] = {\r
-    0,      10000,  12000,  14000,  17000,  21000,  28000,  MAX_TARGET_RATE_BPS\r
-};\r
-const SKP_int32 TargetRate_table_WB[ TARGET_RATE_TAB_SZ ] = {\r
-    0,      11000,  14000,  17000,  21000,  26000,  36000,  MAX_TARGET_RATE_BPS\r
-};\r
-const SKP_int32 TargetRate_table_SWB[ TARGET_RATE_TAB_SZ ] = {\r
-    0,      13000,  16000,  19000,  25000,  32000,  46000,  MAX_TARGET_RATE_BPS\r
-};\r
-const SKP_int32 SNR_table_Q1[ TARGET_RATE_TAB_SZ ] = {\r
-    19,     31,     35,     39,     43,     47,     54,     64\r
-};\r
-\r
-const SKP_int32 SNR_table_one_bit_per_sample_Q7[ 4 ] = {\r
-    1984,   2240,   2408,   2708\r
-};\r
-\r
-/* Filter coeficicnts for HP filter: 4. Order filter implementad as two biquad filters  */\r
-const SKP_int16 SKP_Silk_SWB_detect_B_HP_Q13[ NB_SOS ][ 3 ] = {\r
-    //{400, -550, 400}, {400, 130, 400}, {400, 390, 400}\r
-    {575, -948, 575}, {575, -221, 575}, {575, 104, 575} \r
-};\r
-const SKP_int16 SKP_Silk_SWB_detect_A_HP_Q13[ NB_SOS ][ 2 ] = {\r
-    {14613, 6868}, {12883, 7337}, {11586, 7911}\r
-    //{14880, 6900}, {14400, 7300}, {13700, 7800}\r
-};\r
-\r
-/* Decoder high-pass filter coefficients for 24 kHz sampling, -6 dB @ 44 Hz */\r
-const SKP_int16 SKP_Silk_Dec_A_HP_24[ DEC_HP_ORDER     ] = {-16220, 8030};              // second order AR coefs, Q13\r
-const SKP_int16 SKP_Silk_Dec_B_HP_24[ DEC_HP_ORDER + 1 ] = {8000, -16000, 8000};        // second order MA coefs, Q13\r
-\r
-/* Decoder high-pass filter coefficients for 16 kHz sampling, - 6 dB @ 46 Hz */\r
-const SKP_int16 SKP_Silk_Dec_A_HP_16[ DEC_HP_ORDER     ] = {-16127, 7940};              // second order AR coefs, Q13\r
-const SKP_int16 SKP_Silk_Dec_B_HP_16[ DEC_HP_ORDER + 1 ] = {8000, -16000, 8000};        // second order MA coefs, Q13\r
-\r
-/* Decoder high-pass filter coefficients for 12 kHz sampling, -6 dB @ 44 Hz */\r
-const SKP_int16 SKP_Silk_Dec_A_HP_12[ DEC_HP_ORDER     ] = {-16043, 7859};              // second order AR coefs, Q13\r
-const SKP_int16 SKP_Silk_Dec_B_HP_12[ DEC_HP_ORDER + 1 ] = {8000, -16000, 8000};        // second order MA coefs, Q13\r
-\r
-/* Decoder high-pass filter coefficients for 8 kHz sampling, -6 dB @ 43 Hz */\r
-const SKP_int16 SKP_Silk_Dec_A_HP_8[ DEC_HP_ORDER     ] = {-15885, 7710};               // second order AR coefs, Q13\r
-const SKP_int16 SKP_Silk_Dec_B_HP_8[ DEC_HP_ORDER + 1 ] = {8000, -16000, 8000};         // second order MA coefs, Q13\r
-\r
-/* table for LSB coding */\r
-const SKP_uint16 SKP_Silk_lsb_CDF[ 3 ] = {0,  40000,  65535};\r
-\r
-/* tables for LTPScale */\r
-const SKP_uint16 SKP_Silk_LTPscale_CDF[ 4 ] = {0,  32000,  48000,  65535};\r
-const SKP_int    SKP_Silk_LTPscale_offset   = 2;\r
-\r
-/* tables for VAD flag */\r
-const SKP_uint16 SKP_Silk_vadflag_CDF[ 3 ] = {0,  22000,  65535}; // 66% for speech, 33% for no speech\r
-const SKP_int    SKP_Silk_vadflag_offset   = 1;\r
-\r
-/* tables for sampling rate */\r
-const SKP_int    SKP_Silk_SamplingRates_table[ 4 ] = {8, 12, 16, 24};\r
-const SKP_uint16 SKP_Silk_SamplingRates_CDF[ 5 ]   = {0,  16000,  32000,  48000,  65535};\r
-const SKP_int    SKP_Silk_SamplingRates_offset     = 2;\r
-\r
-/* tables for NLSF interpolation factor */\r
-const SKP_uint16 SKP_Silk_NLSF_interpolation_factor_CDF[ 6 ] = {0,   3706,   8703,  19226,  30926,  65535};\r
-const SKP_int    SKP_Silk_NLSF_interpolation_factor_offset   = 4;\r
-\r
-/* Table for frame termination indication */\r
-const SKP_uint16 SKP_Silk_FrameTermination_CDF[ 5 ] = {0, 20000, 45000, 56000, 65535};\r
-const SKP_int    SKP_Silk_FrameTermination_offset   = 2;\r
-\r
-/* Table for random seed */\r
-const SKP_uint16 SKP_Silk_Seed_CDF[ 5 ] = {0, 16384, 32768, 49152, 65535};\r
-const SKP_int    SKP_Silk_Seed_offset   = 2;\r
-\r
-/* Quantization offsets */\r
-const SKP_int16  SKP_Silk_Quantization_Offsets_Q10[ 2 ][ 2 ] = {\r
-    { OFFSET_VL_Q10, OFFSET_VH_Q10 }, { OFFSET_UVL_Q10, OFFSET_UVH_Q10 }\r
-};\r
-\r
-/* Table for LTPScale */\r
-const SKP_int16 SKP_Silk_LTPScales_table_Q14[ 3 ] = { 15565, 11469, 8192 };\r
-\r
-#if SWITCH_TRANSITION_FILTERING\r
-/*  Elliptic/Cauer filters designed with 0.1 dB passband ripple, \r
-        80 dB minimum stopband attenuation, and\r
-        [0.95 : 0.15 : 0.35] normalized cut off frequencies. */\r
-\r
-/* Interpolation points for filter coefficients used in the bandwidth transition smoother */\r
-const SKP_int32 SKP_Silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NB ] = \r
-{\r
-{    250767114,  501534038,  250767114  },\r
-{    209867381,  419732057,  209867381  },\r
-{    170987846,  341967853,  170987846  },\r
-{    131531482,  263046905,  131531482  },\r
-{     89306658,  178584282,   89306658  }\r
-};\r
-\r
-/* Interpolation points for filter coefficients used in the bandwidth transition smoother */\r
-const SKP_int32 SKP_Silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NA ] = \r
-{\r
-{    506393414,  239854379  },\r
-{    411067935,  169683996  },\r
-{    306733530,  116694253  },\r
-{    185807084,   77959395  },\r
-{     35497197,   57401098  }\r
-};\r
-#endif\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_structs.h"
+#include "SKP_Silk_define.h"
+#include "SKP_Silk_tables.h"
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* Piece-wise linear mapping from bitrate in kbps to coding quality in dB SNR */
+const SKP_int32 TargetRate_table_NB[ TARGET_RATE_TAB_SZ ] = {
+    0,      8000,   9000,   11000,  13000,  16000,  22000,  MAX_TARGET_RATE_BPS
+};
+const SKP_int32 TargetRate_table_MB[ TARGET_RATE_TAB_SZ ] = {
+    0,      10000,  12000,  14000,  17000,  21000,  28000,  MAX_TARGET_RATE_BPS
+};
+const SKP_int32 TargetRate_table_WB[ TARGET_RATE_TAB_SZ ] = {
+    0,      11000,  14000,  17000,  21000,  26000,  36000,  MAX_TARGET_RATE_BPS
+};
+const SKP_int32 TargetRate_table_SWB[ TARGET_RATE_TAB_SZ ] = {
+    0,      13000,  16000,  19000,  25000,  32000,  46000,  MAX_TARGET_RATE_BPS
+};
+const SKP_int32 SNR_table_Q1[ TARGET_RATE_TAB_SZ ] = {
+    19,     31,     35,     39,     43,     47,     54,     64
+};
+
+const SKP_int32 SNR_table_one_bit_per_sample_Q7[ 4 ] = {
+    1984,   2240,   2408,   2708
+};
+
+/* Filter coeficicnts for HP filter: 4. Order filter implementad as two biquad filters  */
+const SKP_int16 SKP_Silk_SWB_detect_B_HP_Q13[ NB_SOS ][ 3 ] = {
+    //{400, -550, 400}, {400, 130, 400}, {400, 390, 400}
+    {575, -948, 575}, {575, -221, 575}, {575, 104, 575} 
+};
+const SKP_int16 SKP_Silk_SWB_detect_A_HP_Q13[ NB_SOS ][ 2 ] = {
+    {14613, 6868}, {12883, 7337}, {11586, 7911}
+    //{14880, 6900}, {14400, 7300}, {13700, 7800}
+};
+
+/* Decoder high-pass filter coefficients for 24 kHz sampling, -6 dB @ 44 Hz */
+const SKP_int16 SKP_Silk_Dec_A_HP_24[ DEC_HP_ORDER     ] = {-16220, 8030};              // second order AR coefs, Q13
+const SKP_int16 SKP_Silk_Dec_B_HP_24[ DEC_HP_ORDER + 1 ] = {8000, -16000, 8000};        // second order MA coefs, Q13
+
+/* Decoder high-pass filter coefficients for 16 kHz sampling, - 6 dB @ 46 Hz */
+const SKP_int16 SKP_Silk_Dec_A_HP_16[ DEC_HP_ORDER     ] = {-16127, 7940};              // second order AR coefs, Q13
+const SKP_int16 SKP_Silk_Dec_B_HP_16[ DEC_HP_ORDER + 1 ] = {8000, -16000, 8000};        // second order MA coefs, Q13
+
+/* Decoder high-pass filter coefficients for 12 kHz sampling, -6 dB @ 44 Hz */
+const SKP_int16 SKP_Silk_Dec_A_HP_12[ DEC_HP_ORDER     ] = {-16043, 7859};              // second order AR coefs, Q13
+const SKP_int16 SKP_Silk_Dec_B_HP_12[ DEC_HP_ORDER + 1 ] = {8000, -16000, 8000};        // second order MA coefs, Q13
+
+/* Decoder high-pass filter coefficients for 8 kHz sampling, -6 dB @ 43 Hz */
+const SKP_int16 SKP_Silk_Dec_A_HP_8[ DEC_HP_ORDER     ] = {-15885, 7710};               // second order AR coefs, Q13
+const SKP_int16 SKP_Silk_Dec_B_HP_8[ DEC_HP_ORDER + 1 ] = {8000, -16000, 8000};         // second order MA coefs, Q13
+
+/* table for LSB coding */
+const SKP_uint16 SKP_Silk_lsb_CDF[ 3 ] = {0,  40000,  65535};
+
+/* tables for LTPScale */
+const SKP_uint16 SKP_Silk_LTPscale_CDF[ 4 ] = {0,  32000,  48000,  65535};
+const SKP_int    SKP_Silk_LTPscale_offset   = 2;
+
+/* tables for VAD flag */
+const SKP_uint16 SKP_Silk_vadflag_CDF[ 3 ] = {0,  22000,  65535}; // 66% for speech, 33% for no speech
+const SKP_int    SKP_Silk_vadflag_offset   = 1;
+
+/* tables for sampling rate */
+const SKP_int    SKP_Silk_SamplingRates_table[ 4 ] = {8, 12, 16, 24};
+const SKP_uint16 SKP_Silk_SamplingRates_CDF[ 5 ]   = {0,  16000,  32000,  48000,  65535};
+const SKP_int    SKP_Silk_SamplingRates_offset     = 2;
+
+/* tables for NLSF interpolation factor */
+const SKP_uint16 SKP_Silk_NLSF_interpolation_factor_CDF[ 6 ] = {0,   3706,   8703,  19226,  30926,  65535};
+const SKP_int    SKP_Silk_NLSF_interpolation_factor_offset   = 4;
+
+/* Table for frame termination indication */
+const SKP_uint16 SKP_Silk_FrameTermination_CDF[ 5 ] = {0, 20000, 45000, 56000, 65535};
+const SKP_int    SKP_Silk_FrameTermination_offset   = 2;
+
+/* Table for random seed */
+const SKP_uint16 SKP_Silk_Seed_CDF[ 5 ] = {0, 16384, 32768, 49152, 65535};
+const SKP_int    SKP_Silk_Seed_offset   = 2;
+
+/* Quantization offsets */
+const SKP_int16  SKP_Silk_Quantization_Offsets_Q10[ 2 ][ 2 ] = {
+    { OFFSET_VL_Q10, OFFSET_VH_Q10 }, { OFFSET_UVL_Q10, OFFSET_UVH_Q10 }
+};
+
+/* Table for LTPScale */
+const SKP_int16 SKP_Silk_LTPScales_table_Q14[ 3 ] = { 15565, 11469, 8192 };
+
+#if SWITCH_TRANSITION_FILTERING
+/*  Elliptic/Cauer filters designed with 0.1 dB passband ripple, 
+        80 dB minimum stopband attenuation, and
+        [0.95 : 0.15 : 0.35] normalized cut off frequencies. */
+
+/* Interpolation points for filter coefficients used in the bandwidth transition smoother */
+const SKP_int32 SKP_Silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NB ] = 
+{
+{    250767114,  501534038,  250767114  },
+{    209867381,  419732057,  209867381  },
+{    170987846,  341967853,  170987846  },
+{    131531482,  263046905,  131531482  },
+{     89306658,  178584282,   89306658  }
+};
+
+/* Interpolation points for filter coefficients used in the bandwidth transition smoother */
+const SKP_int32 SKP_Silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NA ] = 
+{
+{    506393414,  239854379  },
+{    411067935,  169683996  },
+{    306733530,  116694253  },
+{    185807084,   77959395  },
+{     35497197,   57401098  }
+};
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
index fcf28d863094bc22f30b0751968bd181d5601e9b..6d08d0aa9f55b67ea71997be68bd6be9007d9d71 100644 (file)
-/***********************************************************************\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_tables.h"\r
-\r
-const SKP_uint16 SKP_Silk_pitch_lag_NB_CDF[ 8 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ] = {\r
-         0,    194,    395,    608,    841,   1099,   1391,   1724,\r
-      2105,   2544,   3047,   3624,   4282,   5027,   5865,   6799,\r
-      7833,   8965,  10193,  11510,  12910,  14379,  15905,  17473,\r
-     19065,  20664,  22252,  23814,  25335,  26802,  28206,  29541,\r
-     30803,  31992,  33110,  34163,  35156,  36098,  36997,  37861,\r
-     38698,  39515,  40319,  41115,  41906,  42696,  43485,  44273,\r
-     45061,  45847,  46630,  47406,  48175,  48933,  49679,  50411,\r
-     51126,  51824,  52502,  53161,  53799,  54416,  55011,  55584,\r
-     56136,  56666,  57174,  57661,  58126,  58570,  58993,  59394,\r
-     59775,  60134,  60472,  60790,  61087,  61363,  61620,  61856,\r
-     62075,  62275,  62458,  62625,  62778,  62918,  63045,  63162,\r
-     63269,  63368,  63459,  63544,  63623,  63698,  63769,  63836,\r
-     63901,  63963,  64023,  64081,  64138,  64194,  64248,  64301,\r
-     64354,  64406,  64457,  64508,  64558,  64608,  64657,  64706,\r
-     64754,  64803,  64851,  64899,  64946,  64994,  65041,  65088,\r
-     65135,  65181,  65227,  65272,  65317,  65361,  65405,  65449,\r
-     65492,  65535\r
-};\r
-\r
-const SKP_int SKP_Silk_pitch_lag_NB_CDF_offset = 43;\r
-\r
-const SKP_uint16 SKP_Silk_pitch_contour_NB_CDF[ 12 ] = {\r
-         0,  14445,  18587,  25628,  30013,  34859,  40597,  48426,\r
-     54460,  59033,  62990,  65535\r
-};\r
-\r
-const SKP_int SKP_Silk_pitch_contour_NB_CDF_offset = 5;\r
-\r
-const SKP_uint16 SKP_Silk_pitch_lag_MB_CDF[ 12 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ] = {\r
-         0,    132,    266,    402,    542,    686,    838,    997,\r
-      1167,   1349,   1546,   1760,   1993,   2248,   2528,   2835,\r
-      3173,   3544,   3951,   4397,   4882,   5411,   5984,   6604,\r
-      7270,   7984,   8745,   9552,  10405,  11300,  12235,  13206,\r
-     14209,  15239,  16289,  17355,  18430,  19507,  20579,  21642,\r
-     22688,  23712,  24710,  25677,  26610,  27507,  28366,  29188,\r
-     29971,  30717,  31427,  32104,  32751,  33370,  33964,  34537,\r
-     35091,  35630,  36157,  36675,  37186,  37692,  38195,  38697,\r
-     39199,  39701,  40206,  40713,  41222,  41733,  42247,  42761,\r
-     43277,  43793,  44309,  44824,  45336,  45845,  46351,  46851,\r
-     47347,  47836,  48319,  48795,  49264,  49724,  50177,  50621,\r
-     51057,  51484,  51902,  52312,  52714,  53106,  53490,  53866,\r
-     54233,  54592,  54942,  55284,  55618,  55944,  56261,  56571,\r
-     56873,  57167,  57453,  57731,  58001,  58263,  58516,  58762,\r
-     58998,  59226,  59446,  59656,  59857,  60050,  60233,  60408,\r
-     60574,  60732,  60882,  61024,  61159,  61288,  61410,  61526,\r
-     61636,  61742,  61843,  61940,  62033,  62123,  62210,  62293,\r
-     62374,  62452,  62528,  62602,  62674,  62744,  62812,  62879,\r
-     62945,  63009,  63072,  63135,  63196,  63256,  63316,  63375,\r
-     63434,  63491,  63549,  63605,  63661,  63717,  63772,  63827,\r
-     63881,  63935,  63988,  64041,  64094,  64147,  64199,  64252,\r
-     64304,  64356,  64409,  64461,  64513,  64565,  64617,  64669,\r
-     64721,  64773,  64824,  64875,  64925,  64975,  65024,  65072,\r
-     65121,  65168,  65215,  65262,  65308,  65354,  65399,  65445,\r
-     65490,  65535\r
-};\r
-\r
-const SKP_int SKP_Silk_pitch_lag_MB_CDF_offset = 64;\r
-\r
-const SKP_uint16 SKP_Silk_pitch_lag_WB_CDF[ 16 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ] = {\r
-         0,    106,    213,    321,    429,    539,    651,    766,\r
-       884,   1005,   1132,   1264,   1403,   1549,   1705,   1870,\r
-      2047,   2236,   2439,   2658,   2893,   3147,   3420,   3714,\r
-      4030,   4370,   4736,   5127,   5546,   5993,   6470,   6978,\r
-      7516,   8086,   8687,   9320,   9985,  10680,  11405,  12158,\r
-     12938,  13744,  14572,  15420,  16286,  17166,  18057,  18955,\r
-     19857,  20759,  21657,  22547,  23427,  24293,  25141,  25969,\r
-     26774,  27555,  28310,  29037,  29736,  30406,  31048,  31662,\r
-     32248,  32808,  33343,  33855,  34345,  34815,  35268,  35704,\r
-     36127,  36537,  36938,  37330,  37715,  38095,  38471,  38844,\r
-     39216,  39588,  39959,  40332,  40707,  41084,  41463,  41844,\r
-     42229,  42615,  43005,  43397,  43791,  44186,  44583,  44982,\r
-     45381,  45780,  46179,  46578,  46975,  47371,  47765,  48156,\r
-     48545,  48930,  49312,  49690,  50064,  50433,  50798,  51158,\r
-     51513,  51862,  52206,  52544,  52877,  53204,  53526,  53842,\r
-     54152,  54457,  54756,  55050,  55338,  55621,  55898,  56170,\r
-     56436,  56697,  56953,  57204,  57449,  57689,  57924,  58154,\r
-     58378,  58598,  58812,  59022,  59226,  59426,  59620,  59810,\r
-     59994,  60173,  60348,  60517,  60681,  60840,  60993,  61141,\r
-     61284,  61421,  61553,  61679,  61800,  61916,  62026,  62131,\r
-     62231,  62326,  62417,  62503,  62585,  62663,  62737,  62807,\r
-     62874,  62938,  62999,  63057,  63113,  63166,  63217,  63266,\r
-     63314,  63359,  63404,  63446,  63488,  63528,  63567,  63605,\r
-     63642,  63678,  63713,  63748,  63781,  63815,  63847,  63879,\r
-     63911,  63942,  63973,  64003,  64033,  64063,  64092,  64121,\r
-     64150,  64179,  64207,  64235,  64263,  64291,  64319,  64347,\r
-     64374,  64401,  64428,  64455,  64481,  64508,  64534,  64560,\r
-     64585,  64610,  64635,  64660,  64685,  64710,  64734,  64758,\r
-     64782,  64807,  64831,  64855,  64878,  64902,  64926,  64950,\r
-     64974,  64998,  65022,  65045,  65069,  65093,  65116,  65139,\r
-     65163,  65186,  65209,  65231,  65254,  65276,  65299,  65321,\r
-     65343,  65364,  65386,  65408,  65429,  65450,  65471,  65493,\r
-     65514,  65535\r
-};\r
-\r
-const SKP_int SKP_Silk_pitch_lag_WB_CDF_offset = 86;\r
-\r
-\r
-const SKP_uint16 SKP_Silk_pitch_lag_SWB_CDF[ 24 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ] = {\r
-         0,    253,    505,    757,   1008,   1258,   1507,   1755,\r
-      2003,   2249,   2494,   2738,   2982,   3225,   3469,   3713,\r
-      3957,   4202,   4449,   4698,   4949,   5203,   5460,   5720,\r
-      5983,   6251,   6522,   6798,   7077,   7361,   7650,   7942,\r
-      8238,   8539,   8843,   9150,   9461,   9775,  10092,  10411,\r
-     10733,  11057,  11383,  11710,  12039,  12370,  12701,  13034,\r
-     13368,  13703,  14040,  14377,  14716,  15056,  15398,  15742,\r
-     16087,  16435,  16785,  17137,  17492,  17850,  18212,  18577,\r
-     18946,  19318,  19695,  20075,  20460,  20849,  21243,  21640,\r
-     22041,  22447,  22856,  23269,  23684,  24103,  24524,  24947,\r
-     25372,  25798,  26225,  26652,  27079,  27504,  27929,  28352,\r
-     28773,  29191,  29606,  30018,  30427,  30831,  31231,  31627,\r
-     32018,  32404,  32786,  33163,  33535,  33902,  34264,  34621,\r
-     34973,  35320,  35663,  36000,  36333,  36662,  36985,  37304,\r
-     37619,  37929,  38234,  38535,  38831,  39122,  39409,  39692,\r
-     39970,  40244,  40513,  40778,  41039,  41295,  41548,  41796,\r
-     42041,  42282,  42520,  42754,  42985,  43213,  43438,  43660,\r
-     43880,  44097,  44312,  44525,  44736,  44945,  45153,  45359,\r
-     45565,  45769,  45972,  46175,  46377,  46578,  46780,  46981,\r
-     47182,  47383,  47585,  47787,  47989,  48192,  48395,  48599,\r
-     48804,  49009,  49215,  49422,  49630,  49839,  50049,  50259,\r
-     50470,  50682,  50894,  51107,  51320,  51533,  51747,  51961,\r
-     52175,  52388,  52601,  52813,  53025,  53236,  53446,  53655,\r
-     53863,  54069,  54274,  54477,  54679,  54879,  55078,  55274,\r
-     55469,  55662,  55853,  56042,  56230,  56415,  56598,  56779,\r
-     56959,  57136,  57311,  57484,  57654,  57823,  57989,  58152,\r
-     58314,  58473,  58629,  58783,  58935,  59084,  59230,  59373,\r
-     59514,  59652,  59787,  59919,  60048,  60174,  60297,  60417,\r
-     60533,  60647,  60757,  60865,  60969,  61070,  61167,  61262,\r
-     61353,  61442,  61527,  61609,  61689,  61765,  61839,  61910,\r
-     61979,  62045,  62109,  62170,  62230,  62287,  62343,  62396,\r
-     62448,  62498,  62547,  62594,  62640,  62685,  62728,  62770,\r
-     62811,  62852,  62891,  62929,  62967,  63004,  63040,  63075,\r
-     63110,  63145,  63178,  63212,  63244,  63277,  63308,  63340,\r
-     63371,  63402,  63432,  63462,  63491,  63521,  63550,  63578,\r
-     63607,  63635,  63663,  63690,  63718,  63744,  63771,  63798,\r
-     63824,  63850,  63875,  63900,  63925,  63950,  63975,  63999,\r
-     64023,  64046,  64069,  64092,  64115,  64138,  64160,  64182,\r
-     64204,  64225,  64247,  64268,  64289,  64310,  64330,  64351,\r
-     64371,  64391,  64411,  64431,  64450,  64470,  64489,  64508,\r
-     64527,  64545,  64564,  64582,  64600,  64617,  64635,  64652,\r
-     64669,  64686,  64702,  64719,  64735,  64750,  64766,  64782,\r
-     64797,  64812,  64827,  64842,  64857,  64872,  64886,  64901,\r
-     64915,  64930,  64944,  64959,  64974,  64988,  65003,  65018,\r
-     65033,  65048,  65063,  65078,  65094,  65109,  65125,  65141,\r
-     65157,  65172,  65188,  65204,  65220,  65236,  65252,  65268,\r
-     65283,  65299,  65314,  65330,  65345,  65360,  65375,  65390,\r
-     65405,  65419,  65434,  65449,  65463,  65477,  65492,  65506,\r
-     65521,  65535\r
-};\r
-\r
-const SKP_int SKP_Silk_pitch_lag_SWB_CDF_offset = 128;\r
-\r
-\r
-const SKP_uint16 SKP_Silk_pitch_contour_CDF[ 35 ] = {\r
-         0,    372,    843,   1315,   1836,   2644,   3576,   4719,\r
-      6088,   7621,   9396,  11509,  14245,  17618,  20777,  24294,\r
-     27992,  33116,  40100,  44329,  47558,  50679,  53130,  55557,\r
-     57510,  59022,  60285,  61345,  62316,  63140,  63762,  64321,\r
-     64729,  65099,  65535\r
-};\r
-\r
-const SKP_int SKP_Silk_pitch_contour_CDF_offset = 17;\r
-\r
-const SKP_uint16 SKP_Silk_pitch_delta_CDF[23] = {\r
-         0,    343,    740,   1249,   1889,   2733,   3861,   5396,\r
-      7552,  10890,  16053,  24152,  30220,  34680,  37973,  40405,\r
-     42243,  43708,  44823,  45773,  46462,  47055,  65535\r
-};\r
-\r
-const SKP_int SKP_Silk_pitch_delta_CDF_offset = 11;\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_tables.h"
+
+const SKP_uint16 SKP_Silk_pitch_lag_NB_CDF[ 8 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ] = {
+         0,    194,    395,    608,    841,   1099,   1391,   1724,
+      2105,   2544,   3047,   3624,   4282,   5027,   5865,   6799,
+      7833,   8965,  10193,  11510,  12910,  14379,  15905,  17473,
+     19065,  20664,  22252,  23814,  25335,  26802,  28206,  29541,
+     30803,  31992,  33110,  34163,  35156,  36098,  36997,  37861,
+     38698,  39515,  40319,  41115,  41906,  42696,  43485,  44273,
+     45061,  45847,  46630,  47406,  48175,  48933,  49679,  50411,
+     51126,  51824,  52502,  53161,  53799,  54416,  55011,  55584,
+     56136,  56666,  57174,  57661,  58126,  58570,  58993,  59394,
+     59775,  60134,  60472,  60790,  61087,  61363,  61620,  61856,
+     62075,  62275,  62458,  62625,  62778,  62918,  63045,  63162,
+     63269,  63368,  63459,  63544,  63623,  63698,  63769,  63836,
+     63901,  63963,  64023,  64081,  64138,  64194,  64248,  64301,
+     64354,  64406,  64457,  64508,  64558,  64608,  64657,  64706,
+     64754,  64803,  64851,  64899,  64946,  64994,  65041,  65088,
+     65135,  65181,  65227,  65272,  65317,  65361,  65405,  65449,
+     65492,  65535
+};
+
+const SKP_int SKP_Silk_pitch_lag_NB_CDF_offset = 43;
+
+const SKP_uint16 SKP_Silk_pitch_contour_NB_CDF[ 12 ] = {
+         0,  14445,  18587,  25628,  30013,  34859,  40597,  48426,
+     54460,  59033,  62990,  65535
+};
+
+const SKP_int SKP_Silk_pitch_contour_NB_CDF_offset = 5;
+
+const SKP_uint16 SKP_Silk_pitch_lag_MB_CDF[ 12 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ] = {
+         0,    132,    266,    402,    542,    686,    838,    997,
+      1167,   1349,   1546,   1760,   1993,   2248,   2528,   2835,
+      3173,   3544,   3951,   4397,   4882,   5411,   5984,   6604,
+      7270,   7984,   8745,   9552,  10405,  11300,  12235,  13206,
+     14209,  15239,  16289,  17355,  18430,  19507,  20579,  21642,
+     22688,  23712,  24710,  25677,  26610,  27507,  28366,  29188,
+     29971,  30717,  31427,  32104,  32751,  33370,  33964,  34537,
+     35091,  35630,  36157,  36675,  37186,  37692,  38195,  38697,
+     39199,  39701,  40206,  40713,  41222,  41733,  42247,  42761,
+     43277,  43793,  44309,  44824,  45336,  45845,  46351,  46851,
+     47347,  47836,  48319,  48795,  49264,  49724,  50177,  50621,
+     51057,  51484,  51902,  52312,  52714,  53106,  53490,  53866,
+     54233,  54592,  54942,  55284,  55618,  55944,  56261,  56571,
+     56873,  57167,  57453,  57731,  58001,  58263,  58516,  58762,
+     58998,  59226,  59446,  59656,  59857,  60050,  60233,  60408,
+     60574,  60732,  60882,  61024,  61159,  61288,  61410,  61526,
+     61636,  61742,  61843,  61940,  62033,  62123,  62210,  62293,
+     62374,  62452,  62528,  62602,  62674,  62744,  62812,  62879,
+     62945,  63009,  63072,  63135,  63196,  63256,  63316,  63375,
+     63434,  63491,  63549,  63605,  63661,  63717,  63772,  63827,
+     63881,  63935,  63988,  64041,  64094,  64147,  64199,  64252,
+     64304,  64356,  64409,  64461,  64513,  64565,  64617,  64669,
+     64721,  64773,  64824,  64875,  64925,  64975,  65024,  65072,
+     65121,  65168,  65215,  65262,  65308,  65354,  65399,  65445,
+     65490,  65535
+};
+
+const SKP_int SKP_Silk_pitch_lag_MB_CDF_offset = 64;
+
+const SKP_uint16 SKP_Silk_pitch_lag_WB_CDF[ 16 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ] = {
+         0,    106,    213,    321,    429,    539,    651,    766,
+       884,   1005,   1132,   1264,   1403,   1549,   1705,   1870,
+      2047,   2236,   2439,   2658,   2893,   3147,   3420,   3714,
+      4030,   4370,   4736,   5127,   5546,   5993,   6470,   6978,
+      7516,   8086,   8687,   9320,   9985,  10680,  11405,  12158,
+     12938,  13744,  14572,  15420,  16286,  17166,  18057,  18955,
+     19857,  20759,  21657,  22547,  23427,  24293,  25141,  25969,
+     26774,  27555,  28310,  29037,  29736,  30406,  31048,  31662,
+     32248,  32808,  33343,  33855,  34345,  34815,  35268,  35704,
+     36127,  36537,  36938,  37330,  37715,  38095,  38471,  38844,
+     39216,  39588,  39959,  40332,  40707,  41084,  41463,  41844,
+     42229,  42615,  43005,  43397,  43791,  44186,  44583,  44982,
+     45381,  45780,  46179,  46578,  46975,  47371,  47765,  48156,
+     48545,  48930,  49312,  49690,  50064,  50433,  50798,  51158,
+     51513,  51862,  52206,  52544,  52877,  53204,  53526,  53842,
+     54152,  54457,  54756,  55050,  55338,  55621,  55898,  56170,
+     56436,  56697,  56953,  57204,  57449,  57689,  57924,  58154,
+     58378,  58598,  58812,  59022,  59226,  59426,  59620,  59810,
+     59994,  60173,  60348,  60517,  60681,  60840,  60993,  61141,
+     61284,  61421,  61553,  61679,  61800,  61916,  62026,  62131,
+     62231,  62326,  62417,  62503,  62585,  62663,  62737,  62807,
+     62874,  62938,  62999,  63057,  63113,  63166,  63217,  63266,
+     63314,  63359,  63404,  63446,  63488,  63528,  63567,  63605,
+     63642,  63678,  63713,  63748,  63781,  63815,  63847,  63879,
+     63911,  63942,  63973,  64003,  64033,  64063,  64092,  64121,
+     64150,  64179,  64207,  64235,  64263,  64291,  64319,  64347,
+     64374,  64401,  64428,  64455,  64481,  64508,  64534,  64560,
+     64585,  64610,  64635,  64660,  64685,  64710,  64734,  64758,
+     64782,  64807,  64831,  64855,  64878,  64902,  64926,  64950,
+     64974,  64998,  65022,  65045,  65069,  65093,  65116,  65139,
+     65163,  65186,  65209,  65231,  65254,  65276,  65299,  65321,
+     65343,  65364,  65386,  65408,  65429,  65450,  65471,  65493,
+     65514,  65535
+};
+
+const SKP_int SKP_Silk_pitch_lag_WB_CDF_offset = 86;
+
+
+const SKP_uint16 SKP_Silk_pitch_lag_SWB_CDF[ 24 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) + 2 ] = {
+         0,    253,    505,    757,   1008,   1258,   1507,   1755,
+      2003,   2249,   2494,   2738,   2982,   3225,   3469,   3713,
+      3957,   4202,   4449,   4698,   4949,   5203,   5460,   5720,
+      5983,   6251,   6522,   6798,   7077,   7361,   7650,   7942,
+      8238,   8539,   8843,   9150,   9461,   9775,  10092,  10411,
+     10733,  11057,  11383,  11710,  12039,  12370,  12701,  13034,
+     13368,  13703,  14040,  14377,  14716,  15056,  15398,  15742,
+     16087,  16435,  16785,  17137,  17492,  17850,  18212,  18577,
+     18946,  19318,  19695,  20075,  20460,  20849,  21243,  21640,
+     22041,  22447,  22856,  23269,  23684,  24103,  24524,  24947,
+     25372,  25798,  26225,  26652,  27079,  27504,  27929,  28352,
+     28773,  29191,  29606,  30018,  30427,  30831,  31231,  31627,
+     32018,  32404,  32786,  33163,  33535,  33902,  34264,  34621,
+     34973,  35320,  35663,  36000,  36333,  36662,  36985,  37304,
+     37619,  37929,  38234,  38535,  38831,  39122,  39409,  39692,
+     39970,  40244,  40513,  40778,  41039,  41295,  41548,  41796,
+     42041,  42282,  42520,  42754,  42985,  43213,  43438,  43660,
+     43880,  44097,  44312,  44525,  44736,  44945,  45153,  45359,
+     45565,  45769,  45972,  46175,  46377,  46578,  46780,  46981,
+     47182,  47383,  47585,  47787,  47989,  48192,  48395,  48599,
+     48804,  49009,  49215,  49422,  49630,  49839,  50049,  50259,
+     50470,  50682,  50894,  51107,  51320,  51533,  51747,  51961,
+     52175,  52388,  52601,  52813,  53025,  53236,  53446,  53655,
+     53863,  54069,  54274,  54477,  54679,  54879,  55078,  55274,
+     55469,  55662,  55853,  56042,  56230,  56415,  56598,  56779,
+     56959,  57136,  57311,  57484,  57654,  57823,  57989,  58152,
+     58314,  58473,  58629,  58783,  58935,  59084,  59230,  59373,
+     59514,  59652,  59787,  59919,  60048,  60174,  60297,  60417,
+     60533,  60647,  60757,  60865,  60969,  61070,  61167,  61262,
+     61353,  61442,  61527,  61609,  61689,  61765,  61839,  61910,
+     61979,  62045,  62109,  62170,  62230,  62287,  62343,  62396,
+     62448,  62498,  62547,  62594,  62640,  62685,  62728,  62770,
+     62811,  62852,  62891,  62929,  62967,  63004,  63040,  63075,
+     63110,  63145,  63178,  63212,  63244,  63277,  63308,  63340,
+     63371,  63402,  63432,  63462,  63491,  63521,  63550,  63578,
+     63607,  63635,  63663,  63690,  63718,  63744,  63771,  63798,
+     63824,  63850,  63875,  63900,  63925,  63950,  63975,  63999,
+     64023,  64046,  64069,  64092,  64115,  64138,  64160,  64182,
+     64204,  64225,  64247,  64268,  64289,  64310,  64330,  64351,
+     64371,  64391,  64411,  64431,  64450,  64470,  64489,  64508,
+     64527,  64545,  64564,  64582,  64600,  64617,  64635,  64652,
+     64669,  64686,  64702,  64719,  64735,  64750,  64766,  64782,
+     64797,  64812,  64827,  64842,  64857,  64872,  64886,  64901,
+     64915,  64930,  64944,  64959,  64974,  64988,  65003,  65018,
+     65033,  65048,  65063,  65078,  65094,  65109,  65125,  65141,
+     65157,  65172,  65188,  65204,  65220,  65236,  65252,  65268,
+     65283,  65299,  65314,  65330,  65345,  65360,  65375,  65390,
+     65405,  65419,  65434,  65449,  65463,  65477,  65492,  65506,
+     65521,  65535
+};
+
+const SKP_int SKP_Silk_pitch_lag_SWB_CDF_offset = 128;
+
+
+const SKP_uint16 SKP_Silk_pitch_contour_CDF[ 35 ] = {
+         0,    372,    843,   1315,   1836,   2644,   3576,   4719,
+      6088,   7621,   9396,  11509,  14245,  17618,  20777,  24294,
+     27992,  33116,  40100,  44329,  47558,  50679,  53130,  55557,
+     57510,  59022,  60285,  61345,  62316,  63140,  63762,  64321,
+     64729,  65099,  65535
+};
+
+const SKP_int SKP_Silk_pitch_contour_CDF_offset = 17;
+
+const SKP_uint16 SKP_Silk_pitch_delta_CDF[23] = {
+         0,    343,    740,   1249,   1889,   2733,   3861,   5396,
+      7552,  10890,  16053,  24152,  30220,  34680,  37973,  40405,
+     42243,  43708,  44823,  45773,  46462,  47055,  65535
+};
+
+const SKP_int SKP_Silk_pitch_delta_CDF_offset = 11;
index 263611e6127da608b99a4dabcd0f8b0d3148e817..a45dc17e03ba2eaf9f5cdadfbce18d974a43096b 100644 (file)
-/***********************************************************************\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_tables.h"\r
-\r
-const SKP_int SKP_Silk_max_pulses_table[ 4 ] = {\r
-         6,      8,     12,     18\r
-};\r
-\r
-const SKP_uint16 SKP_Silk_pulses_per_block_CDF[ 10 ][ 21 ] = \r
-{\r
-{\r
-         0,  47113,  61501,  64590,  65125,  65277,  65352,  65407,\r
-     65450,  65474,  65488,  65501,  65508,  65514,  65516,  65520,\r
-     65521,  65523,  65524,  65526,  65535\r
-},\r
-{\r
-         0,  26368,  47760,  58803,  63085,  64567,  65113,  65333,\r
-     65424,  65474,  65498,  65511,  65517,  65520,  65523,  65525,\r
-     65526,  65528,  65529,  65530,  65535\r
-},\r
-{\r
-         0,   9601,  28014,  45877,  57210,  62560,  64611,  65260,\r
-     65447,  65500,  65511,  65519,  65521,  65525,  65526,  65529,\r
-     65530,  65531,  65532,  65534,  65535\r
-},\r
-{\r
-         0,   3351,  12462,  25972,  39782,  50686,  57644,  61525,\r
-     63521,  64506,  65009,  65255,  65375,  65441,  65471,  65488,\r
-     65497,  65505,  65509,  65512,  65535\r
-},\r
-{\r
-         0,    488,   2944,   9295,  19712,  32160,  43976,  53121,\r
-     59144,  62518,  64213,  65016,  65346,  65470,  65511,  65515,\r
-     65525,  65529,  65531,  65534,  65535\r
-},\r
-{\r
-         0,  17013,  30405,  40812,  48142,  53466,  57166,  59845,\r
-     61650,  62873,  63684,  64223,  64575,  64811,  64959,  65051,\r
-     65111,  65143,  65165,  65183,  65535\r
-},\r
-{\r
-         0,   2994,   8323,  15845,  24196,  32300,  39340,  45140,\r
-     49813,  53474,  56349,  58518,  60167,  61397,  62313,  62969,\r
-     63410,  63715,  63906,  64056,  65535\r
-},\r
-{\r
-         0,     88,    721,   2795,   7542,  14888,  24420,  34593,\r
-     43912,  51484,  56962,  60558,  62760,  64037,  64716,  65069,\r
-     65262,  65358,  65398,  65420,  65535\r
-},\r
-{\r
-         0,    287,    789,   2064,   4398,   8174,  13534,  20151,\r
-     27347,  34533,  41295,  47242,  52070,  55772,  58458,  60381,\r
-     61679,  62533,  63109,  63519,  65535\r
-},\r
-{\r
-         0,      1,      3,     91,   4521,  14708,  28329,  41955,\r
-     52116,  58375,  61729,  63534,  64459,  64924,  65092,  65164,\r
-     65182,  65198,  65203,  65211,  65535\r
-}\r
-};\r
-\r
-const SKP_int SKP_Silk_pulses_per_block_CDF_offset = 6;\r
-\r
-\r
-const SKP_int16 SKP_Silk_pulses_per_block_BITS_Q6[ 9 ][ 20 ] = \r
-{\r
-{\r
-        30,    140,    282,    444,    560,    625,    654,    677,\r
-       731,    780,    787,    844,    859,    960,    896,   1024,\r
-       960,   1024,    960,    821\r
-},\r
-{\r
-        84,    103,    164,    252,    350,    442,    526,    607,\r
-       663,    731,    787,    859,    923,    923,    960,   1024,\r
-       960,   1024,   1024,    875\r
-},\r
-{\r
-       177,    117,    120,    162,    231,    320,    426,    541,\r
-       657,    803,    832,    960,    896,   1024,    923,   1024,\r
-      1024,   1024,    960,   1024\r
-},\r
-{\r
-       275,    182,    146,    144,    166,    207,    261,    322,\r
-       388,    450,    516,    582,    637,    710,    762,    821,\r
-       832,    896,    923,    734\r
-},\r
-{\r
-       452,    303,    216,    170,    153,    158,    182,    220,\r
-       274,    337,    406,    489,    579,    681,    896,    811,\r
-       896,    960,    923,   1024\r
-},\r
-{\r
-       125,    147,    170,    202,    232,    265,    295,    332,\r
-       368,    406,    443,    483,    520,    563,    606,    646,\r
-       704,    739,    757,    483\r
-},\r
-{\r
-       285,    232,    200,    190,    193,    206,    224,    244,\r
-       266,    289,    315,    340,    367,    394,    425,    462,\r
-       496,    539,    561,    350\r
-},\r
-{\r
-       611,    428,    319,    242,    202,    178,    172,    180,\r
-       199,    229,    268,    313,    364,    422,    482,    538,\r
-       603,    683,    739,    586\r
-},\r
-{\r
-       501,    450,    364,    308,    264,    231,    212,    204,\r
-       204,    210,    222,    241,    265,    295,    326,    362,\r
-       401,    437,    469,    321\r
-}\r
-};\r
-\r
-const SKP_uint16 SKP_Silk_rate_levels_CDF[ 2 ][ 10 ] = \r
-{\r
-{\r
-         0,   2005,  12717,  20281,  31328,  36234,  45816,  57753,\r
-     63104,  65535\r
-},\r
-{\r
-         0,   8553,  23489,  36031,  46295,  53519,  56519,  59151,\r
-     64185,  65535\r
-}\r
-};\r
-\r
-const SKP_int SKP_Silk_rate_levels_CDF_offset = 4;\r
-\r
-\r
-const SKP_int16 SKP_Silk_rate_levels_BITS_Q6[ 2 ][ 9 ] = \r
-{\r
-{\r
-       322,    167,    199,    164,    239,    178,    157,    231,\r
-       304\r
-},\r
-{\r
-       188,    137,    153,    171,    204,    285,    297,    237,\r
-       358\r
-}\r
-};\r
-\r
-const SKP_uint16 SKP_Silk_shell_code_table0[ 33 ] = {\r
-         0,  32748,  65535,      0,   9505,  56230,  65535,      0,\r
-      4093,  32204,  61720,  65535,      0,   2285,  16207,  48750,\r
-     63424,  65535,      0,   1709,   9446,  32026,  55752,  63876,\r
-     65535,      0,   1623,   6986,  21845,  45381,  59147,  64186,\r
-     65535\r
-};\r
-\r
-const SKP_uint16 SKP_Silk_shell_code_table1[ 52 ] = {\r
-         0,  32691,  65535,      0,  12782,  52752,  65535,      0,\r
-      4847,  32665,  60899,  65535,      0,   2500,  17305,  47989,\r
-     63369,  65535,      0,   1843,  10329,  32419,  55433,  64277,\r
-     65535,      0,   1485,   7062,  21465,  43414,  59079,  64623,\r
-     65535,      0,      0,   4841,  14797,  31799,  49667,  61309,\r
-     65535,  65535,      0,      0,      0,   8032,  21695,  41078,\r
-     56317,  65535,  65535,  65535\r
-};\r
-\r
-const SKP_uint16 SKP_Silk_shell_code_table2[ 102 ] = {\r
-         0,  32615,  65535,      0,  14447,  50912,  65535,      0,\r
-      6301,  32587,  59361,  65535,      0,   3038,  18640,  46809,\r
-     62852,  65535,      0,   1746,  10524,  32509,  55273,  64278,\r
-     65535,      0,   1234,   6360,  21259,  43712,  59651,  64805,\r
-     65535,      0,   1020,   4461,  14030,  32286,  51249,  61904,\r
-     65100,  65535,      0,    851,   3435,  10006,  23241,  40797,\r
-     55444,  63009,  65252,  65535,      0,      0,   2075,   7137,\r
-     17119,  31499,  46982,  58723,  63976,  65535,  65535,      0,\r
-         0,      0,   3820,  11572,  23038,  37789,  51969,  61243,\r
-     65535,  65535,  65535,      0,      0,      0,      0,   6882,\r
-     16828,  30444,  44844,  57365,  65535,  65535,  65535,  65535,\r
-         0,      0,      0,      0,      0,  10093,  22963,  38779,\r
-     54426,  65535,  65535,  65535,  65535,  65535\r
-};\r
-\r
-const SKP_uint16 SKP_Silk_shell_code_table3[ 207 ] = {\r
-         0,  32324,  65535,      0,  15328,  49505,  65535,      0,\r
-      7474,  32344,  57955,  65535,      0,   3944,  19450,  45364,\r
-     61873,  65535,      0,   2338,  11698,  32435,  53915,  63734,\r
-     65535,      0,   1506,   7074,  21778,  42972,  58861,  64590,\r
-     65535,      0,   1027,   4490,  14383,  32264,  50980,  61712,\r
-     65043,  65535,      0,    760,   3022,   9696,  23264,  41465,\r
-     56181,  63253,  65251,  65535,      0,    579,   2256,   6873,\r
-     16661,  31951,  48250,  59403,  64198,  65360,  65535,      0,\r
-       464,   1783,   5181,  12269,  24247,  39877,  53490,  61502,\r
-     64591,  65410,  65535,      0,    366,   1332,   3880,   9273,\r
-     18585,  32014,  45928,  56659,  62616,  64899,  65483,  65535,\r
-         0,    286,   1065,   3089,   6969,  14148,  24859,  38274,\r
-     50715,  59078,  63448,  65091,  65481,  65535,      0,      0,\r
-       482,   2010,   5302,  10408,  18988,  30698,  43634,  54233,\r
-     60828,  64119,  65288,  65535,  65535,      0,      0,      0,\r
-      1006,   3531,   7857,  14832,  24543,  36272,  47547,  56883,\r
-     62327,  64746,  65535,  65535,  65535,      0,      0,      0,\r
-         0,   1863,   4950,  10730,  19284,  29397,  41382,  52335,\r
-     59755,  63834,  65535,  65535,  65535,  65535,      0,      0,\r
-         0,      0,      0,   2513,   7290,  14487,  24275,  35312,\r
-     46240,  55841,  62007,  65535,  65535,  65535,  65535,  65535,\r
-         0,      0,      0,      0,      0,      0,   3606,   9573,\r
-     18764,  28667,  40220,  51290,  59924,  65535,  65535,  65535,\r
-     65535,  65535,  65535,      0,      0,      0,      0,      0,\r
-         0,      0,   4879,  13091,  23376,  36061,  49395,  59315,\r
-     65535,  65535,  65535,  65535,  65535,  65535,  65535\r
-};\r
-\r
-const SKP_uint16 SKP_Silk_shell_code_table_offsets[ 19 ] = {\r
-         0,      0,      3,      7,     12,     18,     25,     33,\r
-        42,     52,     63,     75,     88,    102,    117,    133,\r
-       150,    168,    187\r
-};\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_tables.h"
+
+const SKP_int SKP_Silk_max_pulses_table[ 4 ] = {
+         6,      8,     12,     18
+};
+
+const SKP_uint16 SKP_Silk_pulses_per_block_CDF[ 10 ][ 21 ] = 
+{
+{
+         0,  47113,  61501,  64590,  65125,  65277,  65352,  65407,
+     65450,  65474,  65488,  65501,  65508,  65514,  65516,  65520,
+     65521,  65523,  65524,  65526,  65535
+},
+{
+         0,  26368,  47760,  58803,  63085,  64567,  65113,  65333,
+     65424,  65474,  65498,  65511,  65517,  65520,  65523,  65525,
+     65526,  65528,  65529,  65530,  65535
+},
+{
+         0,   9601,  28014,  45877,  57210,  62560,  64611,  65260,
+     65447,  65500,  65511,  65519,  65521,  65525,  65526,  65529,
+     65530,  65531,  65532,  65534,  65535
+},
+{
+         0,   3351,  12462,  25972,  39782,  50686,  57644,  61525,
+     63521,  64506,  65009,  65255,  65375,  65441,  65471,  65488,
+     65497,  65505,  65509,  65512,  65535
+},
+{
+         0,    488,   2944,   9295,  19712,  32160,  43976,  53121,
+     59144,  62518,  64213,  65016,  65346,  65470,  65511,  65515,
+     65525,  65529,  65531,  65534,  65535
+},
+{
+         0,  17013,  30405,  40812,  48142,  53466,  57166,  59845,
+     61650,  62873,  63684,  64223,  64575,  64811,  64959,  65051,
+     65111,  65143,  65165,  65183,  65535
+},
+{
+         0,   2994,   8323,  15845,  24196,  32300,  39340,  45140,
+     49813,  53474,  56349,  58518,  60167,  61397,  62313,  62969,
+     63410,  63715,  63906,  64056,  65535
+},
+{
+         0,     88,    721,   2795,   7542,  14888,  24420,  34593,
+     43912,  51484,  56962,  60558,  62760,  64037,  64716,  65069,
+     65262,  65358,  65398,  65420,  65535
+},
+{
+         0,    287,    789,   2064,   4398,   8174,  13534,  20151,
+     27347,  34533,  41295,  47242,  52070,  55772,  58458,  60381,
+     61679,  62533,  63109,  63519,  65535
+},
+{
+         0,      1,      3,     91,   4521,  14708,  28329,  41955,
+     52116,  58375,  61729,  63534,  64459,  64924,  65092,  65164,
+     65182,  65198,  65203,  65211,  65535
+}
+};
+
+const SKP_int SKP_Silk_pulses_per_block_CDF_offset = 6;
+
+
+const SKP_int16 SKP_Silk_pulses_per_block_BITS_Q6[ 9 ][ 20 ] = 
+{
+{
+        30,    140,    282,    444,    560,    625,    654,    677,
+       731,    780,    787,    844,    859,    960,    896,   1024,
+       960,   1024,    960,    821
+},
+{
+        84,    103,    164,    252,    350,    442,    526,    607,
+       663,    731,    787,    859,    923,    923,    960,   1024,
+       960,   1024,   1024,    875
+},
+{
+       177,    117,    120,    162,    231,    320,    426,    541,
+       657,    803,    832,    960,    896,   1024,    923,   1024,
+      1024,   1024,    960,   1024
+},
+{
+       275,    182,    146,    144,    166,    207,    261,    322,
+       388,    450,    516,    582,    637,    710,    762,    821,
+       832,    896,    923,    734
+},
+{
+       452,    303,    216,    170,    153,    158,    182,    220,
+       274,    337,    406,    489,    579,    681,    896,    811,
+       896,    960,    923,   1024
+},
+{
+       125,    147,    170,    202,    232,    265,    295,    332,
+       368,    406,    443,    483,    520,    563,    606,    646,
+       704,    739,    757,    483
+},
+{
+       285,    232,    200,    190,    193,    206,    224,    244,
+       266,    289,    315,    340,    367,    394,    425,    462,
+       496,    539,    561,    350
+},
+{
+       611,    428,    319,    242,    202,    178,    172,    180,
+       199,    229,    268,    313,    364,    422,    482,    538,
+       603,    683,    739,    586
+},
+{
+       501,    450,    364,    308,    264,    231,    212,    204,
+       204,    210,    222,    241,    265,    295,    326,    362,
+       401,    437,    469,    321
+}
+};
+
+const SKP_uint16 SKP_Silk_rate_levels_CDF[ 2 ][ 10 ] = 
+{
+{
+         0,   2005,  12717,  20281,  31328,  36234,  45816,  57753,
+     63104,  65535
+},
+{
+         0,   8553,  23489,  36031,  46295,  53519,  56519,  59151,
+     64185,  65535
+}
+};
+
+const SKP_int SKP_Silk_rate_levels_CDF_offset = 4;
+
+
+const SKP_int16 SKP_Silk_rate_levels_BITS_Q6[ 2 ][ 9 ] = 
+{
+{
+       322,    167,    199,    164,    239,    178,    157,    231,
+       304
+},
+{
+       188,    137,    153,    171,    204,    285,    297,    237,
+       358
+}
+};
+
+const SKP_uint16 SKP_Silk_shell_code_table0[ 33 ] = {
+         0,  32748,  65535,      0,   9505,  56230,  65535,      0,
+      4093,  32204,  61720,  65535,      0,   2285,  16207,  48750,
+     63424,  65535,      0,   1709,   9446,  32026,  55752,  63876,
+     65535,      0,   1623,   6986,  21845,  45381,  59147,  64186,
+     65535
+};
+
+const SKP_uint16 SKP_Silk_shell_code_table1[ 52 ] = {
+         0,  32691,  65535,      0,  12782,  52752,  65535,      0,
+      4847,  32665,  60899,  65535,      0,   2500,  17305,  47989,
+     63369,  65535,      0,   1843,  10329,  32419,  55433,  64277,
+     65535,      0,   1485,   7062,  21465,  43414,  59079,  64623,
+     65535,      0,      0,   4841,  14797,  31799,  49667,  61309,
+     65535,  65535,      0,      0,      0,   8032,  21695,  41078,
+     56317,  65535,  65535,  65535
+};
+
+const SKP_uint16 SKP_Silk_shell_code_table2[ 102 ] = {
+         0,  32615,  65535,      0,  14447,  50912,  65535,      0,
+      6301,  32587,  59361,  65535,      0,   3038,  18640,  46809,
+     62852,  65535,      0,   1746,  10524,  32509,  55273,  64278,
+     65535,      0,   1234,   6360,  21259,  43712,  59651,  64805,
+     65535,      0,   1020,   4461,  14030,  32286,  51249,  61904,
+     65100,  65535,      0,    851,   3435,  10006,  23241,  40797,
+     55444,  63009,  65252,  65535,      0,      0,   2075,   7137,
+     17119,  31499,  46982,  58723,  63976,  65535,  65535,      0,
+         0,      0,   3820,  11572,  23038,  37789,  51969,  61243,
+     65535,  65535,  65535,      0,      0,      0,      0,   6882,
+     16828,  30444,  44844,  57365,  65535,  65535,  65535,  65535,
+         0,      0,      0,      0,      0,  10093,  22963,  38779,
+     54426,  65535,  65535,  65535,  65535,  65535
+};
+
+const SKP_uint16 SKP_Silk_shell_code_table3[ 207 ] = {
+         0,  32324,  65535,      0,  15328,  49505,  65535,      0,
+      7474,  32344,  57955,  65535,      0,   3944,  19450,  45364,
+     61873,  65535,      0,   2338,  11698,  32435,  53915,  63734,
+     65535,      0,   1506,   7074,  21778,  42972,  58861,  64590,
+     65535,      0,   1027,   4490,  14383,  32264,  50980,  61712,
+     65043,  65535,      0,    760,   3022,   9696,  23264,  41465,
+     56181,  63253,  65251,  65535,      0,    579,   2256,   6873,
+     16661,  31951,  48250,  59403,  64198,  65360,  65535,      0,
+       464,   1783,   5181,  12269,  24247,  39877,  53490,  61502,
+     64591,  65410,  65535,      0,    366,   1332,   3880,   9273,
+     18585,  32014,  45928,  56659,  62616,  64899,  65483,  65535,
+         0,    286,   1065,   3089,   6969,  14148,  24859,  38274,
+     50715,  59078,  63448,  65091,  65481,  65535,      0,      0,
+       482,   2010,   5302,  10408,  18988,  30698,  43634,  54233,
+     60828,  64119,  65288,  65535,  65535,      0,      0,      0,
+      1006,   3531,   7857,  14832,  24543,  36272,  47547,  56883,
+     62327,  64746,  65535,  65535,  65535,      0,      0,      0,
+         0,   1863,   4950,  10730,  19284,  29397,  41382,  52335,
+     59755,  63834,  65535,  65535,  65535,  65535,      0,      0,
+         0,      0,      0,   2513,   7290,  14487,  24275,  35312,
+     46240,  55841,  62007,  65535,  65535,  65535,  65535,  65535,
+         0,      0,      0,      0,      0,      0,   3606,   9573,
+     18764,  28667,  40220,  51290,  59924,  65535,  65535,  65535,
+     65535,  65535,  65535,      0,      0,      0,      0,      0,
+         0,      0,   4879,  13091,  23376,  36061,  49395,  59315,
+     65535,  65535,  65535,  65535,  65535,  65535,  65535
+};
+
+const SKP_uint16 SKP_Silk_shell_code_table_offsets[ 19 ] = {
+         0,      0,      3,      7,     12,     18,     25,     33,
+        42,     52,     63,     75,     88,    102,    117,    133,
+       150,    168,    187
+};
+
index f2aa0793f9099ffdfe1b944417596e7988b4e785..16bd5a37758a7e5fcf5176d931bb8189ce9b6048 100644 (file)
@@ -1,42 +1,42 @@
-/***********************************************************************\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_tables.h"\r
-\r
-const SKP_uint16 SKP_Silk_sign_CDF[ 36 ] = \r
-{\r
-         37840,  36944,  36251,  35304,\r
-         34715,  35503,  34529,  34296,\r
-         34016,  47659,  44945,  42503,\r
-         40235,  38569,  40254,  37851,\r
-         37243,  36595,  43410,  44121,\r
-         43127,  40978,  38845,  40433,\r
-         38252,  37795,  36637,  59159,\r
-         55630,  51806,  48073,  45036,\r
-         48416,  43857,  42678,  41146,\r
-};\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_tables.h"
+
+const SKP_uint16 SKP_Silk_sign_CDF[ 36 ] = 
+{
+         37840,  36944,  36251,  35304,
+         34715,  35503,  34529,  34296,
+         34016,  47659,  44945,  42503,
+         40235,  38569,  40254,  37851,
+         37243,  36595,  43410,  44121,
+         43127,  40978,  38845,  40433,
+         38252,  37795,  36637,  59159,
+         55630,  51806,  48073,  45036,
+         48416,  43857,  42678,  41146,
+};
+
index 93cf454c33b31e8a1d80e9cb095ca6deccfef7c4..5b3deb4bb34c972e7e800e0f6fde7531bd15baf3 100644 (file)
@@ -1,52 +1,52 @@
-/***********************************************************************\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_tables.h"\r
-\r
-const SKP_uint16 SKP_Silk_type_offset_CDF[ 5 ] = {\r
-         0,  37522,  41030,  44212,  65535\r
-};\r
-\r
-const SKP_int SKP_Silk_type_offset_CDF_offset = 2;\r
-\r
-\r
-const SKP_uint16 SKP_Silk_type_offset_joint_CDF[ 4 ][ 5 ] = \r
-{\r
-{\r
-         0,  57686,  61230,  62358,  65535\r
-},\r
-{\r
-         0,  18346,  40067,  43659,  65535\r
-},\r
-{\r
-         0,  22694,  24279,  35507,  65535\r
-},\r
-{\r
-         0,   6067,   7215,  13010,  65535\r
-}\r
-};\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_tables.h"
+
+const SKP_uint16 SKP_Silk_type_offset_CDF[ 5 ] = {
+         0,  37522,  41030,  44212,  65535
+};
+
+const SKP_int SKP_Silk_type_offset_CDF_offset = 2;
+
+
+const SKP_uint16 SKP_Silk_type_offset_joint_CDF[ 4 ][ 5 ] = 
+{
+{
+         0,  57686,  61230,  62358,  65535
+},
+{
+         0,  18346,  40067,  43659,  65535
+},
+{
+         0,  22694,  24279,  35507,  65535
+},
+{
+         0,   6067,   7215,  13010,  65535
+}
+};
+
index e98272d1b11ff4405eda0ecea7dcd8eae125fc54..aa0cae9cf67fd7923ff7156572536f82c788b787 100644 (file)
-/***********************************************************************\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
-#ifndef SKP_SILK_TUNING_PARAMETERS_H\r
-#define SKP_SILK_TUNING_PARAMETERS_H\r
-\r
-#ifdef __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-\r
-/*******************/\r
-/* Pitch estimator */\r
-/*******************/\r
-\r
-/* Level of noise floor for whitening filter LPC analysis in pitch analysis */\r
-#define FIND_PITCH_WHITE_NOISE_FRACTION                 1e-3f\r
-\r
-/* Bandwidth expansion for whitening filter in pitch analysis */\r
-#define FIND_PITCH_BANDWITH_EXPANSION                   0.99f\r
-\r
-/* Threshold used by pitch estimator for early escape */\r
-#define FIND_PITCH_CORRELATION_THRESHOLD_HC_MODE        0.7f\r
-#define FIND_PITCH_CORRELATION_THRESHOLD_MC_MODE        0.75f\r
-#define FIND_PITCH_CORRELATION_THRESHOLD_LC_MODE        0.8f\r
-\r
-/*********************/\r
-/* Linear prediction */\r
-/*********************/\r
-\r
-/* LPC analysis defines: regularization and bandwidth expansion */\r
-#define FIND_LPC_COND_FAC                               2.5e-5f\r
-#define FIND_LPC_CHIRP                                  0.99995f\r
-\r
-/* LTP analysis defines */\r
-#define FIND_LTP_COND_FAC                               1e-5f\r
-#define LTP_DAMPING                                     0.01f\r
-#define LTP_SMOOTHING                                   0.1f\r
-\r
-/* LTP quantization settings */\r
-#define MU_LTP_QUANT_NB                                 0.03f\r
-#define MU_LTP_QUANT_MB                                 0.025f\r
-#define MU_LTP_QUANT_WB                                 0.02f\r
-#define MU_LTP_QUANT_SWB                                0.016f\r
-\r
-/***********************/\r
-/* High pass filtering */\r
-/***********************/\r
-\r
-/* Smoothing parameters for low end of pitch frequency range estimation */\r
-#define VARIABLE_HP_SMTH_COEF1                          0.1f\r
-#define VARIABLE_HP_SMTH_COEF2                          0.015f\r
-\r
-/* Min and max values for low end of pitch frequency range estimation */\r
-#define VARIABLE_HP_MIN_FREQ                            80.0f\r
-#define VARIABLE_HP_MAX_FREQ                            150.0f\r
-\r
-/* Max absolute difference between log2 of pitch frequency and smoother state, to enter the smoother */\r
-#define VARIABLE_HP_MAX_DELTA_FREQ                      0.4f\r
-\r
-/***********/\r
-/* Various */\r
-/***********/\r
-\r
-/* Required speech activity for counting frame as active */\r
-#define WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES             0.7f        \r
-\r
-#define SPEECH_ACTIVITY_DTX_THRES                       0.1f\r
-\r
-/* Speech Activity LBRR enable threshold (needs tuning) */\r
-#define LBRR_SPEECH_ACTIVITY_THRES                      0.5f        \r
-\r
-/*************************/\r
-/* Perceptual parameters */\r
-/*************************/\r
-\r
-/* reduction in coding SNR during low speech activity */\r
-#define BG_SNR_DECR_dB                                  4.0f\r
-\r
-/* factor for reducing quantization noise during voiced speech */\r
-#define HARM_SNR_INCR_dB                                2.0f\r
-\r
-/* factor for reducing quantization noise for unvoiced sparse signals */\r
-#define SPARSE_SNR_INCR_dB                              2.0f\r
-\r
-/* threshold for sparseness measure above which to use lower quantization offset during unvoiced */\r
-#define SPARSENESS_THRESHOLD_QNT_OFFSET                 0.75f\r
-\r
-/* warping control */\r
-#define WARPING_MULTIPLIER                              0.015f\r
-\r
-/* fraction added to first autocorrelation value */\r
-#define SHAPE_WHITE_NOISE_FRACTION                      1e-5f\r
-\r
-/* noise shaping filter chirp factor */\r
-#define BANDWIDTH_EXPANSION                             0.95f\r
-\r
-/* difference between chirp factors for analysis and synthesis noise shaping filters at low bitrates */\r
-#define LOW_RATE_BANDWIDTH_EXPANSION_DELTA              0.01f\r
-\r
-/* gain reduction for fricatives */\r
-#define DE_ESSER_COEF_SWB_dB                            2.0f\r
-#define DE_ESSER_COEF_WB_dB                             1.0f\r
-\r
-/* extra harmonic boosting (signal shaping) at low bitrates */\r
-#define LOW_RATE_HARMONIC_BOOST                         0.1f\r
-\r
-/* extra harmonic boosting (signal shaping) for noisy input signals */\r
-#define LOW_INPUT_QUALITY_HARMONIC_BOOST                0.1f\r
-\r
-/* harmonic noise shaping */\r
-#define HARMONIC_SHAPING                                0.3f\r
-\r
-/* extra harmonic noise shaping for high bitrates or noisy input */\r
-#define HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING       0.2f\r
-\r
-/* parameter for shaping noise towards higher frequencies */\r
-#define HP_NOISE_COEF                                   0.3f\r
-\r
-/* parameter for shaping noise even more towards higher frequencies during voiced speech */\r
-#define HARM_HP_NOISE_COEF                              0.35f\r
-\r
-/* parameter for applying a high-pass tilt to the input signal */\r
-#define INPUT_TILT                                      0.05f\r
-\r
-/* parameter for extra high-pass tilt to the input signal at high rates */\r
-#define HIGH_RATE_INPUT_TILT                            0.1f\r
-\r
-/* parameter for reducing noise at the very low frequencies */\r
-#define LOW_FREQ_SHAPING                                3.0f\r
-\r
-/* less reduction of noise at the very low frequencies for signals with low SNR at low frequencies */\r
-#define LOW_QUALITY_LOW_FREQ_SHAPING_DECR               0.5f\r
-\r
-/* noise floor to put a lower limit on the quantization step size */\r
-#define NOISE_FLOOR_dB                                  4.0f\r
-\r
-/* noise floor relative to active speech gain level */\r
-#define RELATIVE_MIN_GAIN_dB                            -50.0f\r
-\r
-/* subframe smoothing coefficient for determining active speech gain level (lower -> more smoothing) */\r
-#define GAIN_SMOOTHING_COEF                             1e-3f\r
-\r
-/* subframe smoothing coefficient for HarmBoost, HarmShapeGain, Tilt (lower -> more smoothing) */\r
-#define SUBFR_SMTH_COEF                                 0.4f\r
-\r
-/* parameters defining the R/D tradeoff in the residual quantizer */\r
-#define LAMBDA_OFFSET                                   1.2f\r
-#define LAMBDA_SPEECH_ACT                               -0.3f\r
-#define LAMBDA_DELAYED_DECISIONS                        -0.05f\r
-#define LAMBDA_INPUT_QUALITY                            -0.2f\r
-#define LAMBDA_CODING_QUALITY                           -0.1f\r
-#define LAMBDA_QUANT_OFFSET                             1.5f\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif // SKP_SILK_TUNING_PARAMETERS_H\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifndef SKP_SILK_TUNING_PARAMETERS_H
+#define SKP_SILK_TUNING_PARAMETERS_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/*******************/
+/* Pitch estimator */
+/*******************/
+
+/* Level of noise floor for whitening filter LPC analysis in pitch analysis */
+#define FIND_PITCH_WHITE_NOISE_FRACTION                 1e-3f
+
+/* Bandwidth expansion for whitening filter in pitch analysis */
+#define FIND_PITCH_BANDWITH_EXPANSION                   0.99f
+
+/* Threshold used by pitch estimator for early escape */
+#define FIND_PITCH_CORRELATION_THRESHOLD_HC_MODE        0.7f
+#define FIND_PITCH_CORRELATION_THRESHOLD_MC_MODE        0.75f
+#define FIND_PITCH_CORRELATION_THRESHOLD_LC_MODE        0.8f
+
+/*********************/
+/* Linear prediction */
+/*********************/
+
+/* LPC analysis defines: regularization and bandwidth expansion */
+#define FIND_LPC_COND_FAC                               2.5e-5f
+#define FIND_LPC_CHIRP                                  0.99995f
+
+/* LTP analysis defines */
+#define FIND_LTP_COND_FAC                               1e-5f
+#define LTP_DAMPING                                     0.01f
+#define LTP_SMOOTHING                                   0.1f
+
+/* LTP quantization settings */
+#define MU_LTP_QUANT_NB                                 0.03f
+#define MU_LTP_QUANT_MB                                 0.025f
+#define MU_LTP_QUANT_WB                                 0.02f
+#define MU_LTP_QUANT_SWB                                0.016f
+
+/***********************/
+/* High pass filtering */
+/***********************/
+
+/* Smoothing parameters for low end of pitch frequency range estimation */
+#define VARIABLE_HP_SMTH_COEF1                          0.1f
+#define VARIABLE_HP_SMTH_COEF2                          0.015f
+
+/* Min and max values for low end of pitch frequency range estimation */
+#define VARIABLE_HP_MIN_FREQ                            80.0f
+#define VARIABLE_HP_MAX_FREQ                            150.0f
+
+/* Max absolute difference between log2 of pitch frequency and smoother state, to enter the smoother */
+#define VARIABLE_HP_MAX_DELTA_FREQ                      0.4f
+
+/***********/
+/* Various */
+/***********/
+
+/* Required speech activity for counting frame as active */
+#define WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES             0.7f        
+
+#define SPEECH_ACTIVITY_DTX_THRES                       0.1f
+
+/* Speech Activity LBRR enable threshold (needs tuning) */
+#define LBRR_SPEECH_ACTIVITY_THRES                      0.5f        
+
+/*************************/
+/* Perceptual parameters */
+/*************************/
+
+/* reduction in coding SNR during low speech activity */
+#define BG_SNR_DECR_dB                                  4.0f
+
+/* factor for reducing quantization noise during voiced speech */
+#define HARM_SNR_INCR_dB                                2.0f
+
+/* factor for reducing quantization noise for unvoiced sparse signals */
+#define SPARSE_SNR_INCR_dB                              2.0f
+
+/* threshold for sparseness measure above which to use lower quantization offset during unvoiced */
+#define SPARSENESS_THRESHOLD_QNT_OFFSET                 0.75f
+
+/* warping control */
+#define WARPING_MULTIPLIER                              0.015f
+
+/* fraction added to first autocorrelation value */
+#define SHAPE_WHITE_NOISE_FRACTION                      1e-5f
+
+/* noise shaping filter chirp factor */
+#define BANDWIDTH_EXPANSION                             0.95f
+
+/* difference between chirp factors for analysis and synthesis noise shaping filters at low bitrates */
+#define LOW_RATE_BANDWIDTH_EXPANSION_DELTA              0.01f
+
+/* gain reduction for fricatives */
+#define DE_ESSER_COEF_SWB_dB                            2.0f
+#define DE_ESSER_COEF_WB_dB                             1.0f
+
+/* extra harmonic boosting (signal shaping) at low bitrates */
+#define LOW_RATE_HARMONIC_BOOST                         0.1f
+
+/* extra harmonic boosting (signal shaping) for noisy input signals */
+#define LOW_INPUT_QUALITY_HARMONIC_BOOST                0.1f
+
+/* harmonic noise shaping */
+#define HARMONIC_SHAPING                                0.3f
+
+/* extra harmonic noise shaping for high bitrates or noisy input */
+#define HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING       0.2f
+
+/* parameter for shaping noise towards higher frequencies */
+#define HP_NOISE_COEF                                   0.3f
+
+/* parameter for shaping noise even more towards higher frequencies during voiced speech */
+#define HARM_HP_NOISE_COEF                              0.35f
+
+/* parameter for applying a high-pass tilt to the input signal */
+#define INPUT_TILT                                      0.05f
+
+/* parameter for extra high-pass tilt to the input signal at high rates */
+#define HIGH_RATE_INPUT_TILT                            0.1f
+
+/* parameter for reducing noise at the very low frequencies */
+#define LOW_FREQ_SHAPING                                3.0f
+
+/* less reduction of noise at the very low frequencies for signals with low SNR at low frequencies */
+#define LOW_QUALITY_LOW_FREQ_SHAPING_DECR               0.5f
+
+/* noise floor to put a lower limit on the quantization step size */
+#define NOISE_FLOOR_dB                                  4.0f
+
+/* noise floor relative to active speech gain level */
+#define RELATIVE_MIN_GAIN_dB                            -50.0f
+
+/* subframe smoothing coefficient for determining active speech gain level (lower -> more smoothing) */
+#define GAIN_SMOOTHING_COEF                             1e-3f
+
+/* subframe smoothing coefficient for HarmBoost, HarmShapeGain, Tilt (lower -> more smoothing) */
+#define SUBFR_SMTH_COEF                                 0.4f
+
+/* parameters defining the R/D tradeoff in the residual quantizer */
+#define LAMBDA_OFFSET                                   1.2f
+#define LAMBDA_SPEECH_ACT                               -0.3f
+#define LAMBDA_DELAYED_DECISIONS                        -0.05f
+#define LAMBDA_INPUT_QUALITY                            -0.2f
+#define LAMBDA_CODING_QUALITY                           -0.1f
+#define LAMBDA_QUANT_OFFSET                             1.5f
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // SKP_SILK_TUNING_PARAMETERS_H
index 9a8d80db2bac5275f9669b616cd57d86350f3b89..84851d23dc77c87527c0c9ec937bfb922a276eda 100644 (file)
@@ -1,86 +1,86 @@
-/***********************************************************************\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_FIX.h"\r
-\r
-#define QC  10\r
-#define QS  14\r
-\r
-\r
-/* Autocorrelations for a warped frequency axis */\r
-void SKP_Silk_warped_autocorrelation_FIX(\r
-          SKP_int32                 *corr,              /* O    Result [order + 1]                      */\r
-          SKP_int                   *scale,             /* O    Scaling of the correlation vector       */\r
-    const SKP_int16                 *input,             /* I    Input data to correlate                 */\r
-    const SKP_int16                 warping_Q16,        /* I    Warping coefficient                     */\r
-    const SKP_int                   length,             /* I    Length of input                         */\r
-    const SKP_int                   order               /* I    Correlation order (even)                */\r
-)\r
-{\r
-    SKP_int   n, i, lsh;\r
-    SKP_int32 tmp1_QS, tmp2_QS;\r
-    SKP_int32 state_QS[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };\r
-    SKP_int64 corr_QC[  MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };\r
-\r
-    /* Order must be even */\r
-    SKP_assert( ( order & 1 ) == 0 );\r
-    SKP_assert( 2 * QS - QC >= 0 );\r
-\r
-    /* Loop over samples */\r
-    for( n = 0; n < length; n++ ) {\r
-        tmp1_QS = SKP_LSHIFT32( ( SKP_int32 )input[ n ], QS );\r
-        /* Loop over allpass sections */\r
-        for( i = 0; i < order; i += 2 ) {\r
-            /* Output of allpass section */\r
-            tmp2_QS = SKP_SMLAWB( state_QS[ i ], state_QS[ i + 1 ] - tmp1_QS, warping_Q16 );\r
-            state_QS[ i ]  = tmp1_QS;\r
-            corr_QC[  i ] += SKP_RSHIFT64( SKP_SMULL( tmp1_QS, state_QS[ 0 ] ), 2 * QS - QC );\r
-            /* Output of allpass section */\r
-            tmp1_QS = SKP_SMLAWB( state_QS[ i + 1 ], state_QS[ i + 2 ] - tmp2_QS, warping_Q16 );\r
-            state_QS[ i + 1 ]  = tmp2_QS;\r
-            corr_QC[  i + 1 ] += SKP_RSHIFT64( SKP_SMULL( tmp2_QS, state_QS[ 0 ] ), 2 * QS - QC );\r
-        }\r
-        state_QS[ order ] = tmp1_QS;\r
-        corr_QC[  order ] += SKP_RSHIFT64( SKP_SMULL( tmp1_QS, state_QS[ 0 ] ), 2 * QS - QC );\r
-    }\r
-\r
-    lsh = SKP_Silk_CLZ64( corr_QC[ 0 ] ) - 35;\r
-    lsh = SKP_LIMIT( lsh, -12 - QC, 30 - QC );\r
-    *scale = -( QC + lsh ); \r
-    SKP_assert( *scale >= -30 && *scale <= 12 );\r
-    if( lsh >= 0 ) {\r
-        for( i = 0; i < order + 1; i++ ) {\r
-            corr[ i ] = ( SKP_int32 )SKP_CHECK_FIT32( SKP_LSHIFT64( corr_QC[ i ], lsh ) );\r
-        }\r
-    } else {\r
-        for( i = 0; i < order + 1; i++ ) {\r
-            corr[ i ] = ( SKP_int32 )SKP_CHECK_FIT32( SKP_RSHIFT64( corr_QC[ i ], -lsh ) );\r
-        }    \r
-    }\r
-    SKP_assert( corr_QC[ 0 ] >= 0 ); // If breaking, decrease QC\r
-}\r
-\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main_FIX.h"
+
+#define QC  10
+#define QS  14
+
+
+/* Autocorrelations for a warped frequency axis */
+void SKP_Silk_warped_autocorrelation_FIX(
+          SKP_int32                 *corr,              /* O    Result [order + 1]                      */
+          SKP_int                   *scale,             /* O    Scaling of the correlation vector       */
+    const SKP_int16                 *input,             /* I    Input data to correlate                 */
+    const SKP_int16                 warping_Q16,        /* I    Warping coefficient                     */
+    const SKP_int                   length,             /* I    Length of input                         */
+    const SKP_int                   order               /* I    Correlation order (even)                */
+)
+{
+    SKP_int   n, i, lsh;
+    SKP_int32 tmp1_QS, tmp2_QS;
+    SKP_int32 state_QS[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };
+    SKP_int64 corr_QC[  MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };
+
+    /* Order must be even */
+    SKP_assert( ( order & 1 ) == 0 );
+    SKP_assert( 2 * QS - QC >= 0 );
+
+    /* Loop over samples */
+    for( n = 0; n < length; n++ ) {
+        tmp1_QS = SKP_LSHIFT32( ( SKP_int32 )input[ n ], QS );
+        /* Loop over allpass sections */
+        for( i = 0; i < order; i += 2 ) {
+            /* Output of allpass section */
+            tmp2_QS = SKP_SMLAWB( state_QS[ i ], state_QS[ i + 1 ] - tmp1_QS, warping_Q16 );
+            state_QS[ i ]  = tmp1_QS;
+            corr_QC[  i ] += SKP_RSHIFT64( SKP_SMULL( tmp1_QS, state_QS[ 0 ] ), 2 * QS - QC );
+            /* Output of allpass section */
+            tmp1_QS = SKP_SMLAWB( state_QS[ i + 1 ], state_QS[ i + 2 ] - tmp2_QS, warping_Q16 );
+            state_QS[ i + 1 ]  = tmp2_QS;
+            corr_QC[  i + 1 ] += SKP_RSHIFT64( SKP_SMULL( tmp2_QS, state_QS[ 0 ] ), 2 * QS - QC );
+        }
+        state_QS[ order ] = tmp1_QS;
+        corr_QC[  order ] += SKP_RSHIFT64( SKP_SMULL( tmp1_QS, state_QS[ 0 ] ), 2 * QS - QC );
+    }
+
+    lsh = SKP_Silk_CLZ64( corr_QC[ 0 ] ) - 35;
+    lsh = SKP_LIMIT( lsh, -12 - QC, 30 - QC );
+    *scale = -( QC + lsh ); 
+    SKP_assert( *scale >= -30 && *scale <= 12 );
+    if( lsh >= 0 ) {
+        for( i = 0; i < order + 1; i++ ) {
+            corr[ i ] = ( SKP_int32 )SKP_CHECK_FIT32( SKP_LSHIFT64( corr_QC[ i ], lsh ) );
+        }
+    } else {
+        for( i = 0; i < order + 1; i++ ) {
+            corr[ i ] = ( SKP_int32 )SKP_CHECK_FIT32( SKP_RSHIFT64( corr_QC[ i ], -lsh ) );
+        }    
+    }
+    SKP_assert( corr_QC[ 0 ] >= 0 ); // If breaking, decrease QC
+}
+
index b17f79655c2f5e200972384cae1d7b5ef9e3d4fb..072fb77d40d2455576ba8746d2697caf43830710 100644 (file)
-/***********************************************************************\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
-/*****************************/\r
-/* Silk decoder test program */\r
-/*****************************/\r
-\r
-#ifdef _WIN32\r
-#define _CRT_SECURE_NO_DEPRECATE    1\r
-#endif\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include "SKP_Silk_SDK_API.h"\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* Define codec specific settings should be moved to h file */\r
-#define MAX_BYTES_PER_FRAME     1024\r
-#define MAX_INPUT_FRAMES        5\r
-#define MAX_FRAME_LENGTH        480\r
-#define FRAME_LENGTH_MS         20\r
-#define MAX_API_FS_KHZ          48\r
-#define MAX_LBRR_DELAY          2\r
-\r
-#ifdef _SYSTEM_IS_BIG_ENDIAN\r
-/* Function to convert a little endian int16 to a */\r
-/* big endian int16 or vica verca                 */\r
-void swap_endian(\r
-    SKP_int16       vec[],\r
-    SKP_int         len\r
-)\r
-{\r
-    SKP_int i;\r
-    SKP_int16 tmp;\r
-    SKP_uint8 *p1, *p2;\r
-\r
-    for( i = 0; i < len; i++ ){\r
-        tmp = vec[ i ];\r
-        p1 = (SKP_uint8 *)&vec[ i ]; p2 = (SKP_uint8 *)&tmp;\r
-        p1[ 0 ] = p2[ 1 ]; p1[ 1 ] = p2[ 0 ];\r
-    }\r
-}\r
-#endif\r
-\r
-/* Seed for the random number generator, which is used for simulating packet loss */\r
-static SKP_int32 rand_seed = 1;\r
-\r
-static void print_usage(char* argv[]) {\r
-    printf( "\nusage: %s in.bit out.pcm [settings]\n", argv[ 0 ] );\r
-    printf( "\nstream.bit   : Bitstream input to decoder" );\r
-    printf( "\nout.pcm      : Speech output from decoder" );\r
-    printf( "\n   settings:" );\r
-    printf( "\n-Fs_API <Hz> : Sampling rate of output signal in Hz; default: 24000" );\r
-    printf( "\n-loss <perc> : Simulated packet loss percentage (0-100); default: 0" );\r
-    printf( "\n" );\r
-}\r
-\r
-int main( int argc, char* argv[] )\r
-{\r
-    size_t    counter;\r
-    SKP_int32 args, totPackets, i, k;\r
-    SKP_int16 ret, len, tot_len;\r
-    SKP_int16 nBytes;\r
-    SKP_uint8 payload[    MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES * ( MAX_LBRR_DELAY + 1 ) ];\r
-    SKP_uint8 *payloadEnd = NULL, *payloadToDec = NULL;\r
-    SKP_uint8 FECpayload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ], *payloadPtr;\r
-    SKP_int16 nBytesFEC;\r
-    SKP_int16 nBytesPerPacket[ MAX_LBRR_DELAY + 1 ], totBytes;\r
-    SKP_int16 out[ ( ( FRAME_LENGTH_MS * MAX_API_FS_KHZ ) << 1 ) * MAX_INPUT_FRAMES ], *outPtr;\r
-    char      speechOutFileName[ 150 ], bitInFileName[ 150 ];\r
-    FILE      *bitInFile, *speechOutFile;\r
-    SKP_int32 API_Fs_Hz = 0;\r
-    SKP_int32 decSizeBytes;\r
-    void      *psDec;\r
-    float     loss_prob;\r
-    SKP_int32 frames, lost, quiet;\r
-    SKP_SILK_SDK_DecControlStruct DecControl;\r
-\r
-    if( argc < 3 ) {\r
-        print_usage( argv );\r
-        exit( 0 );\r
-    } \r
-\r
-    /* default settings */\r
-    quiet     = 0;\r
-    loss_prob = 0.0f;\r
-\r
-    /* get arguments */\r
-    args = 1;\r
-    strcpy( bitInFileName, argv[ args ] );\r
-    args++;\r
-    strcpy( speechOutFileName, argv[ args ] );\r
-    args++;\r
-    while( args < argc ) {\r
-        if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) {\r
-            sscanf( argv[ args + 1 ], "%f", &loss_prob );\r
-            args += 2;\r
-        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-Fs_API" ) == 0 ) {\r
-            sscanf( argv[ args + 1 ], "%d", &API_Fs_Hz );\r
-            args += 2;\r
-        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-quiet" ) == 0 ) {\r
-            quiet = 1;\r
-            args++;\r
-        } else {\r
-            printf( "Error: unrecognized setting: %s\n\n", argv[ args ] );\r
-            print_usage( argv );\r
-            exit( 0 );\r
-        }\r
-    }\r
-\r
-    if( !quiet ) {\r
-        printf("******************* Silk Decoder v %s ****************\n", SKP_Silk_SDK_get_version());\r
-        printf("******************* Compiled for %d bit cpu ********* \n", (int)sizeof(void*) * 8 );\r
-        printf( "Input:                       %s\n", bitInFileName );\r
-        printf( "Output:                      %s\n", speechOutFileName );\r
-    }\r
-\r
-    /* Open files */\r
-    bitInFile = fopen( bitInFileName, "rb" );\r
-    if( bitInFile == NULL ) {\r
-        printf( "Error: could not open input file %s\n", bitInFileName );\r
-        exit( 0 );\r
-    } \r
-\r
-    /* Check Silk header */\r
-    {\r
-        char header_buf[ 50 ];\r
-        counter = fread( header_buf, sizeof( char ), strlen( "#!SILK_V3" ), bitInFile );\r
-        header_buf[ strlen( "#!SILK_V3" ) ] = ( char )0; /* Terminate with a null character */\r
-        if( strcmp( header_buf, "#!SILK_V3" ) != 0 ) { \r
-            /* Non-equal strings */\r
-            printf( "Error: Wrong Header %s\n", header_buf );\r
-            exit( 0 );\r
-        }\r
-    }\r
-\r
-    speechOutFile = fopen( speechOutFileName, "wb" );\r
-    if( speechOutFile == NULL ) {\r
-        printf( "Error: could not open output file %s\n", speechOutFileName );\r
-        exit( 0 );\r
-    }\r
-\r
-    /* Set the samplingrate that is requested for the output */\r
-    if( API_Fs_Hz == 0 ) {\r
-        DecControl.API_sampleRate = 24000;\r
-    } else {\r
-        DecControl.API_sampleRate = API_Fs_Hz;\r
-    }\r
-\r
-    /* Initialize to one frame per packet, for proper concealment before first packet arrives */\r
-    DecControl.framesPerPacket = 1;\r
-\r
-    /* Create decoder */\r
-    ret = SKP_Silk_SDK_Get_Decoder_Size( &decSizeBytes );\r
-    if( ret ) {\r
-        printf( "\nSKP_Silk_SDK_Get_Decoder_Size returned %d", ret );\r
-    }\r
-    psDec = malloc( decSizeBytes );\r
-\r
-    /* Reset decoder */\r
-    ret = SKP_Silk_SDK_InitDecoder( psDec );\r
-    if( ret ) {\r
-        printf( "\nSKP_Silk_InitDecoder returned %d", ret );\r
-    }\r
-\r
-    totPackets = 0;\r
-    payloadEnd = payload;\r
-\r
-    /* Simulate the jitter buffer holding MAX_FEC_DELAY packets */\r
-    for( i = 0; i < MAX_LBRR_DELAY; i++ ) {\r
-        /* Read payload size */\r
-        counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );\r
-#ifdef _SYSTEM_IS_BIG_ENDIAN\r
-        swap_endian( &nBytes, 1 );\r
-#endif\r
-        /* Read payload */\r
-        counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );\r
-\r
-        if( ( SKP_int16 )counter < nBytes ) {\r
-            break;\r
-        }\r
-        nBytesPerPacket[ i ] = nBytes;\r
-        payloadEnd          += nBytes;\r
-    }\r
-\r
-    while( 1 ) {\r
-        /* Read payload size */\r
-        counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );\r
-#ifdef _SYSTEM_IS_BIG_ENDIAN\r
-        swap_endian( &nBytes, 1 );\r
-#endif\r
-        if( nBytes < 0 || counter < 1 ) {\r
-            break;\r
-        }\r
-        \r
-        /* Read payload */\r
-        counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );\r
-        if( ( SKP_int16 )counter < nBytes ) {\r
-            break;\r
-        }\r
-\r
-        /* Simulate losses */\r
-        rand_seed = SKP_RAND( rand_seed );\r
-        if( ( ( ( float )( ( rand_seed >> 16 ) + ( 1 << 15 ) ) ) / 65535.0f >= ( loss_prob / 100.0f ) ) && ( counter > 0 ) ) {\r
-            nBytesPerPacket[ MAX_LBRR_DELAY ] = nBytes;\r
-            payloadEnd                       += nBytes;\r
-        } else {\r
-            nBytesPerPacket[ MAX_LBRR_DELAY ] = 0;\r
-        }\r
-\r
-        if( nBytesPerPacket[ 0 ] == 0 ) {\r
-            /* Indicate lost packet */\r
-            lost = 1;\r
-\r
-            /* Packet loss. Search after FEC in next packets. Should be done in the jitter buffer */\r
-            payloadPtr = payload;\r
-            for( i = 0; i < MAX_LBRR_DELAY; i++ ) {\r
-                if( nBytesPerPacket[ i + 1 ] > 0 ) {\r
-                    SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );\r
-                    if( nBytesFEC > 0 ) {\r
-                        payloadToDec = FECpayload;\r
-                        nBytes = nBytesFEC;\r
-                        lost = 0;\r
-                        break;\r
-                    }\r
-                }\r
-                payloadPtr += nBytesPerPacket[ i + 1 ];\r
-            }\r
-        } else {\r
-            lost = 0;\r
-            nBytes = nBytesPerPacket[ 0 ];\r
-            payloadToDec = payload;\r
-        }\r
-\r
-        /* Silk decoder */\r
-        outPtr = out;\r
-        tot_len = 0;\r
-\r
-        if( lost == 0 ) {\r
-            /* No Loss: Decode all frames in the packet */\r
-            frames = 0;\r
-            do {\r
-                /* Decode 20 ms */\r
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );\r
-                if( ret ) {\r
-                    printf( "\nSKP_Silk_SDK_Decode returned %d", ret );\r
-                }\r
-\r
-                frames++;\r
-                outPtr  += len;\r
-                tot_len += len;\r
-                if( frames > MAX_INPUT_FRAMES ) {\r
-                    /* Hack for corrupt stream that could generate too many frames */\r
-                    outPtr  = out;\r
-                    tot_len = 0;\r
-                    frames  = 0;\r
-                }\r
-                /* Until last 20 ms frame of packet has been decoded */\r
-            } while( DecControl.moreInternalDecoderFrames ); \r
-        } else {    \r
-            /* Loss: Decode enough frames to cover one packet duration */\r
-            for( i = 0; i < DecControl.framesPerPacket; i++ ) {\r
-                /* Generate 20 ms */\r
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );\r
-                if( ret ) {\r
-                    printf( "\nSKP_Silk_Decode returned %d", ret );\r
-                }\r
-                outPtr  += len;\r
-                tot_len += len;\r
-            }\r
-        }\r
-        totPackets++;\r
-\r
-        /* Write output to file */\r
-#ifdef _SYSTEM_IS_BIG_ENDIAN   \r
-        swap_endian( out, tot_len );\r
-#endif\r
-        fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile );\r
-\r
-        /* Update buffer */\r
-        totBytes = 0;\r
-        for( i = 0; i < MAX_LBRR_DELAY; i++ ) {\r
-            totBytes += nBytesPerPacket[ i + 1 ];\r
-        }\r
-        SKP_memmove( payload, &payload[ nBytesPerPacket[ 0 ] ], totBytes * sizeof( SKP_uint8 ) );\r
-        payloadEnd -= nBytesPerPacket[ 0 ];\r
-        SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) );\r
-\r
-        if( !quiet ) {\r
-            fprintf( stderr, "\rPackets decoded:             %d", totPackets );\r
-        }\r
-    }\r
-\r
-    /* Empty the recieve buffer */\r
-    for( k = 0; k < MAX_LBRR_DELAY; k++ ) {\r
-        if( nBytesPerPacket[ 0 ] == 0 ) {\r
-            /* Indicate lost packet */\r
-            lost = 1;\r
-\r
-            /* Packet loss. Search after FEC in next packets. Should be done in the jitter buffer */\r
-            payloadPtr = payload;\r
-            for( i = 0; i < MAX_LBRR_DELAY; i++ ) {\r
-                if( nBytesPerPacket[ i + 1 ] > 0 ) {\r
-                    SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );\r
-                    if( nBytesFEC > 0 ) {\r
-                        payloadToDec = FECpayload;\r
-                        nBytes = nBytesFEC;\r
-                        lost = 0;\r
-                        break;\r
-                    }\r
-                }\r
-                payloadPtr += nBytesPerPacket[ i + 1 ];\r
-            }\r
-        } else {\r
-            lost = 0;\r
-            nBytes = nBytesPerPacket[ 0 ];\r
-            payloadToDec = payload;\r
-        }\r
-\r
-        /* Silk decoder */\r
-        outPtr  = out;\r
-        tot_len = 0;\r
-\r
-        if( lost == 0 ) {\r
-            /* No loss: Decode all frames in the packet */\r
-            frames = 0;\r
-            do {\r
-                /* Decode 20 ms */\r
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );\r
-                if( ret ) {\r
-                    printf( "\nSKP_Silk_SDK_Decode returned %d", ret );\r
-                }\r
-\r
-                frames++;\r
-                outPtr  += len;\r
-                tot_len += len;\r
-                if( frames > MAX_INPUT_FRAMES ) {\r
-                    /* Hack for corrupt stream that could generate too many frames */\r
-                    outPtr  = out;\r
-                    tot_len = 0;\r
-                    frames  = 0;\r
-                }\r
-            /* Until last 20 ms frame of packet has been decoded */\r
-            } while( DecControl.moreInternalDecoderFrames );\r
-        } else {    \r
-            /* Loss: Decode enough frames to cover one packet duration */\r
-\r
-            /* Generate 20 ms */\r
-            for( i = 0; i < DecControl.framesPerPacket; i++ ) {\r
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );\r
-                if( ret ) {\r
-                    printf( "\nSKP_Silk_Decode returned %d", ret );\r
-                }\r
-                outPtr  += len;\r
-                tot_len += len;\r
-            }\r
-        }\r
-        totPackets++;\r
-\r
-        /* Write output to file */\r
-#ifdef _SYSTEM_IS_BIG_ENDIAN   \r
-        swap_endian( out, tot_len );\r
-#endif\r
-        fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile );\r
-\r
-        /* Update Buffer */\r
-        totBytes = 0;\r
-        for( i = 0; i < MAX_LBRR_DELAY; i++ ) {\r
-            totBytes += nBytesPerPacket[ i + 1 ];\r
-        }\r
-        SKP_memmove( payload, &payload[ nBytesPerPacket[ 0 ] ], totBytes * sizeof( SKP_uint8 ) );\r
-        payloadEnd -= nBytesPerPacket[ 0 ];\r
-        SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) );\r
-\r
-        if( !quiet ) {\r
-            fprintf( stderr, "\rPackets decoded:              %d", totPackets );\r
-        }\r
-    }\r
-\r
-    if( !quiet ) {\r
-        printf( "\nDecoding Finished \n" );\r
-    }\r
-\r
-    /* Free decoder */\r
-    free( psDec );\r
-\r
-    /* Close files */\r
-    fclose( speechOutFile );\r
-    fclose( bitInFile );\r
-\r
-    return 0;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+
+/*****************************/
+/* Silk decoder test program */
+/*****************************/
+
+#ifdef _WIN32
+#define _CRT_SECURE_NO_DEPRECATE    1
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "SKP_Silk_SDK_API.h"
+#include "SKP_Silk_SigProc_FIX.h"
+
+/* Define codec specific settings should be moved to h file */
+#define MAX_BYTES_PER_FRAME     1024
+#define MAX_INPUT_FRAMES        5
+#define MAX_FRAME_LENGTH        480
+#define FRAME_LENGTH_MS         20
+#define MAX_API_FS_KHZ          48
+#define MAX_LBRR_DELAY          2
+
+#ifdef _SYSTEM_IS_BIG_ENDIAN
+/* Function to convert a little endian int16 to a */
+/* big endian int16 or vica verca                 */
+void swap_endian(
+    SKP_int16       vec[],
+    SKP_int         len
+)
+{
+    SKP_int i;
+    SKP_int16 tmp;
+    SKP_uint8 *p1, *p2;
+
+    for( i = 0; i < len; i++ ){
+        tmp = vec[ i ];
+        p1 = (SKP_uint8 *)&vec[ i ]; p2 = (SKP_uint8 *)&tmp;
+        p1[ 0 ] = p2[ 1 ]; p1[ 1 ] = p2[ 0 ];
+    }
+}
+#endif
+
+/* Seed for the random number generator, which is used for simulating packet loss */
+static SKP_int32 rand_seed = 1;
+
+static void print_usage(char* argv[]) {
+    printf( "\nusage: %s in.bit out.pcm [settings]\n", argv[ 0 ] );
+    printf( "\nstream.bit   : Bitstream input to decoder" );
+    printf( "\nout.pcm      : Speech output from decoder" );
+    printf( "\n   settings:" );
+    printf( "\n-Fs_API <Hz> : Sampling rate of output signal in Hz; default: 24000" );
+    printf( "\n-loss <perc> : Simulated packet loss percentage (0-100); default: 0" );
+    printf( "\n" );
+}
+
+int main( int argc, char* argv[] )
+{
+    size_t    counter;
+    SKP_int32 args, totPackets, i, k;
+    SKP_int16 ret, len, tot_len;
+    SKP_int16 nBytes;
+    SKP_uint8 payload[    MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES * ( MAX_LBRR_DELAY + 1 ) ];
+    SKP_uint8 *payloadEnd = NULL, *payloadToDec = NULL;
+    SKP_uint8 FECpayload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ], *payloadPtr;
+    SKP_int16 nBytesFEC;
+    SKP_int16 nBytesPerPacket[ MAX_LBRR_DELAY + 1 ], totBytes;
+    SKP_int16 out[ ( ( FRAME_LENGTH_MS * MAX_API_FS_KHZ ) << 1 ) * MAX_INPUT_FRAMES ], *outPtr;
+    char      speechOutFileName[ 150 ], bitInFileName[ 150 ];
+    FILE      *bitInFile, *speechOutFile;
+    SKP_int32 API_Fs_Hz = 0;
+    SKP_int32 decSizeBytes;
+    void      *psDec;
+    float     loss_prob;
+    SKP_int32 frames, lost, quiet;
+    SKP_SILK_SDK_DecControlStruct DecControl;
+
+    if( argc < 3 ) {
+        print_usage( argv );
+        exit( 0 );
+    } 
+
+    /* default settings */
+    quiet     = 0;
+    loss_prob = 0.0f;
+
+    /* get arguments */
+    args = 1;
+    strcpy( bitInFileName, argv[ args ] );
+    args++;
+    strcpy( speechOutFileName, argv[ args ] );
+    args++;
+    while( args < argc ) {
+        if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) {
+            sscanf( argv[ args + 1 ], "%f", &loss_prob );
+            args += 2;
+        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-Fs_API" ) == 0 ) {
+            sscanf( argv[ args + 1 ], "%d", &API_Fs_Hz );
+            args += 2;
+        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-quiet" ) == 0 ) {
+            quiet = 1;
+            args++;
+        } else {
+            printf( "Error: unrecognized setting: %s\n\n", argv[ args ] );
+            print_usage( argv );
+            exit( 0 );
+        }
+    }
+
+    if( !quiet ) {
+        printf("******************* Silk Decoder v %s ****************\n", SKP_Silk_SDK_get_version());
+        printf("******************* Compiled for %d bit cpu ********* \n", (int)sizeof(void*) * 8 );
+        printf( "Input:                       %s\n", bitInFileName );
+        printf( "Output:                      %s\n", speechOutFileName );
+    }
+
+    /* Open files */
+    bitInFile = fopen( bitInFileName, "rb" );
+    if( bitInFile == NULL ) {
+        printf( "Error: could not open input file %s\n", bitInFileName );
+        exit( 0 );
+    } 
+
+    /* Check Silk header */
+    {
+        char header_buf[ 50 ];
+        counter = fread( header_buf, sizeof( char ), strlen( "#!SILK_V3" ), bitInFile );
+        header_buf[ strlen( "#!SILK_V3" ) ] = ( char )0; /* Terminate with a null character */
+        if( strcmp( header_buf, "#!SILK_V3" ) != 0 ) { 
+            /* Non-equal strings */
+            printf( "Error: Wrong Header %s\n", header_buf );
+            exit( 0 );
+        }
+    }
+
+    speechOutFile = fopen( speechOutFileName, "wb" );
+    if( speechOutFile == NULL ) {
+        printf( "Error: could not open output file %s\n", speechOutFileName );
+        exit( 0 );
+    }
+
+    /* Set the samplingrate that is requested for the output */
+    if( API_Fs_Hz == 0 ) {
+        DecControl.API_sampleRate = 24000;
+    } else {
+        DecControl.API_sampleRate = API_Fs_Hz;
+    }
+
+    /* Initialize to one frame per packet, for proper concealment before first packet arrives */
+    DecControl.framesPerPacket = 1;
+
+    /* Create decoder */
+    ret = SKP_Silk_SDK_Get_Decoder_Size( &decSizeBytes );
+    if( ret ) {
+        printf( "\nSKP_Silk_SDK_Get_Decoder_Size returned %d", ret );
+    }
+    psDec = malloc( decSizeBytes );
+
+    /* Reset decoder */
+    ret = SKP_Silk_SDK_InitDecoder( psDec );
+    if( ret ) {
+        printf( "\nSKP_Silk_InitDecoder returned %d", ret );
+    }
+
+    totPackets = 0;
+    payloadEnd = payload;
+
+    /* Simulate the jitter buffer holding MAX_FEC_DELAY packets */
+    for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
+        /* Read payload size */
+        counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );
+#ifdef _SYSTEM_IS_BIG_ENDIAN
+        swap_endian( &nBytes, 1 );
+#endif
+        /* Read payload */
+        counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );
+
+        if( ( SKP_int16 )counter < nBytes ) {
+            break;
+        }
+        nBytesPerPacket[ i ] = nBytes;
+        payloadEnd          += nBytes;
+    }
+
+    while( 1 ) {
+        /* Read payload size */
+        counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );
+#ifdef _SYSTEM_IS_BIG_ENDIAN
+        swap_endian( &nBytes, 1 );
+#endif
+        if( nBytes < 0 || counter < 1 ) {
+            break;
+        }
+        
+        /* Read payload */
+        counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );
+        if( ( SKP_int16 )counter < nBytes ) {
+            break;
+        }
+
+        /* Simulate losses */
+        rand_seed = SKP_RAND( rand_seed );
+        if( ( ( ( float )( ( rand_seed >> 16 ) + ( 1 << 15 ) ) ) / 65535.0f >= ( loss_prob / 100.0f ) ) && ( counter > 0 ) ) {
+            nBytesPerPacket[ MAX_LBRR_DELAY ] = nBytes;
+            payloadEnd                       += nBytes;
+        } else {
+            nBytesPerPacket[ MAX_LBRR_DELAY ] = 0;
+        }
+
+        if( nBytesPerPacket[ 0 ] == 0 ) {
+            /* Indicate lost packet */
+            lost = 1;
+
+            /* Packet loss. Search after FEC in next packets. Should be done in the jitter buffer */
+            payloadPtr = payload;
+            for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
+                if( nBytesPerPacket[ i + 1 ] > 0 ) {
+                    SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );
+                    if( nBytesFEC > 0 ) {
+                        payloadToDec = FECpayload;
+                        nBytes = nBytesFEC;
+                        lost = 0;
+                        break;
+                    }
+                }
+                payloadPtr += nBytesPerPacket[ i + 1 ];
+            }
+        } else {
+            lost = 0;
+            nBytes = nBytesPerPacket[ 0 ];
+            payloadToDec = payload;
+        }
+
+        /* Silk decoder */
+        outPtr = out;
+        tot_len = 0;
+
+        if( lost == 0 ) {
+            /* No Loss: Decode all frames in the packet */
+            frames = 0;
+            do {
+                /* Decode 20 ms */
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );
+                if( ret ) {
+                    printf( "\nSKP_Silk_SDK_Decode returned %d", ret );
+                }
+
+                frames++;
+                outPtr  += len;
+                tot_len += len;
+                if( frames > MAX_INPUT_FRAMES ) {
+                    /* Hack for corrupt stream that could generate too many frames */
+                    outPtr  = out;
+                    tot_len = 0;
+                    frames  = 0;
+                }
+                /* Until last 20 ms frame of packet has been decoded */
+            } while( DecControl.moreInternalDecoderFrames ); 
+        } else {    
+            /* Loss: Decode enough frames to cover one packet duration */
+            for( i = 0; i < DecControl.framesPerPacket; i++ ) {
+                /* Generate 20 ms */
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );
+                if( ret ) {
+                    printf( "\nSKP_Silk_Decode returned %d", ret );
+                }
+                outPtr  += len;
+                tot_len += len;
+            }
+        }
+        totPackets++;
+
+        /* Write output to file */
+#ifdef _SYSTEM_IS_BIG_ENDIAN   
+        swap_endian( out, tot_len );
+#endif
+        fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile );
+
+        /* Update buffer */
+        totBytes = 0;
+        for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
+            totBytes += nBytesPerPacket[ i + 1 ];
+        }
+        SKP_memmove( payload, &payload[ nBytesPerPacket[ 0 ] ], totBytes * sizeof( SKP_uint8 ) );
+        payloadEnd -= nBytesPerPacket[ 0 ];
+        SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) );
+
+        if( !quiet ) {
+            fprintf( stderr, "\rPackets decoded:             %d", totPackets );
+        }
+    }
+
+    /* Empty the recieve buffer */
+    for( k = 0; k < MAX_LBRR_DELAY; k++ ) {
+        if( nBytesPerPacket[ 0 ] == 0 ) {
+            /* Indicate lost packet */
+            lost = 1;
+
+            /* Packet loss. Search after FEC in next packets. Should be done in the jitter buffer */
+            payloadPtr = payload;
+            for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
+                if( nBytesPerPacket[ i + 1 ] > 0 ) {
+                    SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );
+                    if( nBytesFEC > 0 ) {
+                        payloadToDec = FECpayload;
+                        nBytes = nBytesFEC;
+                        lost = 0;
+                        break;
+                    }
+                }
+                payloadPtr += nBytesPerPacket[ i + 1 ];
+            }
+        } else {
+            lost = 0;
+            nBytes = nBytesPerPacket[ 0 ];
+            payloadToDec = payload;
+        }
+
+        /* Silk decoder */
+        outPtr  = out;
+        tot_len = 0;
+
+        if( lost == 0 ) {
+            /* No loss: Decode all frames in the packet */
+            frames = 0;
+            do {
+                /* Decode 20 ms */
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );
+                if( ret ) {
+                    printf( "\nSKP_Silk_SDK_Decode returned %d", ret );
+                }
+
+                frames++;
+                outPtr  += len;
+                tot_len += len;
+                if( frames > MAX_INPUT_FRAMES ) {
+                    /* Hack for corrupt stream that could generate too many frames */
+                    outPtr  = out;
+                    tot_len = 0;
+                    frames  = 0;
+                }
+            /* Until last 20 ms frame of packet has been decoded */
+            } while( DecControl.moreInternalDecoderFrames );
+        } else {    
+            /* Loss: Decode enough frames to cover one packet duration */
+
+            /* Generate 20 ms */
+            for( i = 0; i < DecControl.framesPerPacket; i++ ) {
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );
+                if( ret ) {
+                    printf( "\nSKP_Silk_Decode returned %d", ret );
+                }
+                outPtr  += len;
+                tot_len += len;
+            }
+        }
+        totPackets++;
+
+        /* Write output to file */
+#ifdef _SYSTEM_IS_BIG_ENDIAN   
+        swap_endian( out, tot_len );
+#endif
+        fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile );
+
+        /* Update Buffer */
+        totBytes = 0;
+        for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
+            totBytes += nBytesPerPacket[ i + 1 ];
+        }
+        SKP_memmove( payload, &payload[ nBytesPerPacket[ 0 ] ], totBytes * sizeof( SKP_uint8 ) );
+        payloadEnd -= nBytesPerPacket[ 0 ];
+        SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) );
+
+        if( !quiet ) {
+            fprintf( stderr, "\rPackets decoded:              %d", totPackets );
+        }
+    }
+
+    if( !quiet ) {
+        printf( "\nDecoding Finished \n" );
+    }
+
+    /* Free decoder */
+    free( psDec );
+
+    /* Close files */
+    fclose( speechOutFile );
+    fclose( bitInFile );
+
+    return 0;
+}
index 5595af5d8ce67bc6230cd0f68d75d5247ccf2704..97cc1ecd99c67743f6b8130a03a468a453a98c05 100644 (file)
-/***********************************************************************\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
-/*****************************/\r
-/* Silk encoder test program */\r
-/*****************************/\r
-\r
-#ifdef _WIN32\r
-#define _CRT_SECURE_NO_DEPRECATE    1\r
-#endif\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <math.h>\r
-#include "SKP_Silk_SDK_API.h"\r
-\r
-/* Define codec specific settings */\r
-#define MAX_BYTES_PER_FRAME     250 // Equals peak bitrate of 100 kbps \r
-#define MAX_INPUT_FRAMES        5\r
-#define MAX_LBRR_DELAY          2\r
-#define MAX_FRAME_LENGTH        480\r
-#define FRAME_LENGTH_MS         20\r
-#define MAX_API_FS_KHZ          48\r
-\r
-#ifdef _SYSTEM_IS_BIG_ENDIAN\r
-/* Function to convert a little endian int16 to a */\r
-/* big endian int16 or vica verca                 */\r
-void swap_endian(\r
-    SKP_int16       vec[],              /*  I/O array of */\r
-    SKP_int         len                 /*  I   length      */\r
-)\r
-{\r
-    SKP_int i;\r
-    SKP_int16 tmp;\r
-    SKP_uint8 *p1, *p2;\r
-\r
-    for( i = 0; i < len; i++ ){\r
-        tmp = vec[ i ];\r
-        p1 = (SKP_uint8 *)&vec[ i ]; p2 = (SKP_uint8 *)&tmp;\r
-        p1[ 0 ] = p2[ 1 ]; p1[ 1 ] = p2[ 0 ];\r
-    }\r
-}\r
-#endif\r
-\r
-static void print_usage( char* argv[] ) {\r
-    printf( "\nusage: %s in.pcm out.bit [settings]\n", argv[ 0 ] );\r
-    printf( "\nin.pcm               : Speech input to encoder" );\r
-    printf( "\nstream.bit           : Bitstream output from encoder" );\r
-    printf( "\n   settings:" );\r
-    printf( "\n-Fs_API <Hz>         : API sampling rate in Hz, default: 24000" );\r
-    printf( "\n-Fs_maxInternal <Hz> : Maximum internal sampling rate in Hz, default: 24000" ); \r
-    printf( "\n-packetlength <ms>   : Packet interval in ms, default: 20" );\r
-    printf( "\n-rate <bps>          : Target bitrate; default: 25000" );\r
-    printf( "\n-loss <perc>         : Uplink loss estimate, in percent (0-100); default: 0" );\r
-    printf( "\n-inbandFEC <flag>    : Enable inband FEC usage (0/1); default: 0" );\r
-    printf( "\n-complexity <comp>   : Set complexity, 0: low, 1: medium, 2: high; default: 2" );\r
-    printf( "\n-DTX <flag>          : Enable DTX (0/1); default: 0" );\r
-    printf( "\n-quiet               : Print only some basic values" );\r
-    printf( "\n");\r
-}\r
-\r
-int main( int argc, char* argv[] )\r
-{\r
-    size_t    counter;\r
-    SKP_int32 k, args, totPackets, totActPackets, ret;\r
-    SKP_int16 nBytes;\r
-    double    sumBytes, sumActBytes, avg_rate, act_rate, nrg;\r
-    SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ];\r
-    SKP_int16 in[ FRAME_LENGTH_MS * MAX_API_FS_KHZ * MAX_INPUT_FRAMES ];\r
-    char      speechInFileName[ 150 ], bitOutFileName[ 150 ];\r
-    FILE      *bitOutFile, *speechInFile;\r
-    SKP_int32 encSizeBytes;\r
-    void      *psEnc;\r
-#ifdef _SYSTEM_IS_BIG_ENDIAN\r
-    SKP_int16 nBytes_LE;\r
-#endif\r
-\r
-    /* default settings */\r
-    SKP_int32 API_fs_Hz = 24000;\r
-    SKP_int32 max_internal_fs_Hz = 0;\r
-    SKP_int32 targetRate_bps = 25000;\r
-    SKP_int32 packetSize_ms = 20;\r
-    SKP_int32 frameSizeReadFromFile_ms = 20;\r
-    SKP_int32 packetLoss_perc = 0, complexity_mode = 2, smplsSinceLastPacket;\r
-    SKP_int32 INBandFEC_enabled = 0, DTX_enabled = 0, quiet = 0;\r
-    SKP_SILK_SDK_EncControlStruct encControl; // Struct for input to encoder\r
-        \r
-    if( argc < 3 ) {\r
-        print_usage( argv );\r
-        exit( 0 );\r
-    } \r
-    \r
-    /* get arguments */\r
-    args = 1;\r
-    strcpy( speechInFileName, argv[ args ] );\r
-    args++;\r
-    strcpy( bitOutFileName,   argv[ args ] );\r
-    args++;\r
-    while( args < argc ) {\r
-        if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-Fs_API" ) == 0 ) {\r
-            sscanf( argv[ args + 1 ], "%d", &API_fs_Hz );\r
-            args += 2;\r
-        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-Fs_maxInternal" ) == 0 ) {\r
-            sscanf( argv[ args + 1 ], "%d", &max_internal_fs_Hz );\r
-            args += 2;\r
-        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-packetlength" ) == 0 ) {\r
-            sscanf( argv[ args + 1 ], "%d", &packetSize_ms );\r
-            args += 2;\r
-        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-rate" ) == 0 ) {\r
-            sscanf( argv[ args + 1 ], "%d", &targetRate_bps );\r
-            args += 2;\r
-        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) {\r
-            sscanf( argv[ args + 1 ], "%d", &packetLoss_perc );\r
-            args += 2;\r
-        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-complexity" ) == 0 ) {\r
-            sscanf( argv[ args + 1 ], "%d", &complexity_mode );\r
-            args += 2;\r
-        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-inbandFEC" ) == 0 ) {\r
-            sscanf( argv[ args + 1 ], "%d", &INBandFEC_enabled );\r
-            args += 2;\r
-        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-DTX") == 0 ) {\r
-            sscanf( argv[ args + 1 ], "%d", &DTX_enabled );\r
-            args += 2;\r
-        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-quiet" ) == 0 ) {\r
-            quiet = 1;\r
-            args++;\r
-        } else {\r
-            printf( "Error: unrecognized setting: %s\n\n", argv[ args ] );\r
-            print_usage( argv );\r
-            exit( 0 );\r
-        }\r
-    }\r
-\r
-    /* If no max internal is specified, set to minimum of API fs and 24 kHz */\r
-    if( max_internal_fs_Hz == 0 ) {\r
-        max_internal_fs_Hz = 24000;\r
-        if( API_fs_Hz < max_internal_fs_Hz ) {\r
-            max_internal_fs_Hz = API_fs_Hz;\r
-        }\r
-    }\r
-\r
-    /* Print options */\r
-    if( !quiet ) {\r
-        printf("******************* Silk Encoder v %s ****************\n", SKP_Silk_SDK_get_version());\r
-        printf("******************* Compiled for %d bit cpu ********* \n", (int)sizeof(void*) * 8 );\r
-        printf( "Input:                          %s\n",     speechInFileName );\r
-        printf( "Output:                         %s\n",     bitOutFileName );\r
-        printf( "API sampling rate:              %d Hz\n",  API_fs_Hz );\r
-        printf( "Maximum internal sampling rate: %d Hz\n",  max_internal_fs_Hz );\r
-        printf( "Packet interval:                %d ms\n",  packetSize_ms );\r
-        printf( "Inband FEC used:                %d\n",     INBandFEC_enabled );\r
-        printf( "DTX used:                       %d\n",     DTX_enabled );\r
-        printf( "Complexity:                     %d\n",     complexity_mode );\r
-        printf( "Target bitrate:                 %d bps\n", targetRate_bps );\r
-    }\r
-\r
-    /* Open files */\r
-    speechInFile = fopen( speechInFileName, "rb" );\r
-    if( speechInFile == NULL ) {\r
-        printf( "Error: could not open input file %s\n", speechInFileName );\r
-        exit( 0 );\r
-    }\r
-    bitOutFile = fopen( bitOutFileName, "wb" );\r
-    if( bitOutFile == NULL ) {\r
-        printf( "Error: could not open output file %s\n", bitOutFileName );\r
-        exit( 0 );\r
-    }\r
-\r
-    /* Add Silk header to stream */\r
-    {\r
-        static const char Silk_header[] = "#!SILK_V3";\r
-        fwrite( Silk_header, sizeof( char ), strlen( Silk_header ), bitOutFile );\r
-    }\r
-\r
-    /* Create Encoder */\r
-    ret = SKP_Silk_SDK_Get_Encoder_Size( &encSizeBytes );\r
-    if( ret ) {\r
-        printf( "\nSKP_Silk_create_encoder returned %d", ret );\r
-    }\r
-\r
-    psEnc = malloc( encSizeBytes );\r
-\r
-    /* Reset Encoder */\r
-    ret = SKP_Silk_SDK_InitEncoder( psEnc, &encControl );\r
-    if( ret ) {\r
-        printf( "\nSKP_Silk_reset_encoder returned %d", ret );\r
-    }\r
-    \r
-    /* Set Encoder parameters */\r
-    encControl.API_sampleRate        = API_fs_Hz;\r
-    encControl.maxInternalSampleRate = max_internal_fs_Hz;\r
-    encControl.packetSize            = ( packetSize_ms * API_fs_Hz ) / 1000;\r
-    encControl.packetLossPercentage  = packetLoss_perc;\r
-    encControl.useInBandFEC          = INBandFEC_enabled;\r
-    encControl.useDTX                = DTX_enabled;\r
-    encControl.complexity            = complexity_mode;\r
-    encControl.bitRate               = ( targetRate_bps > 0 ? targetRate_bps : 0 );\r
-\r
-    if( API_fs_Hz > MAX_API_FS_KHZ * 1000 || API_fs_Hz < 0 ) {\r
-        printf( "\nError: API sampling rate = %d out of range, valid range 8000 - 48000 \n \n", API_fs_Hz );\r
-        exit( 0 );\r
-    }\r
-\r
-    totPackets           = 0;\r
-    totActPackets        = 0;\r
-    smplsSinceLastPacket = 0;\r
-    sumBytes             = 0.0;\r
-    sumActBytes          = 0.0;\r
-    \r
-    while( 1 ) {\r
-        /* Read input from file */\r
-        counter = fread( in, sizeof( SKP_int16 ), ( frameSizeReadFromFile_ms * API_fs_Hz ) / 1000, speechInFile );\r
-#ifdef _SYSTEM_IS_BIG_ENDIAN\r
-        swap_endian( in, counter );\r
-#endif\r
-        if( (SKP_int)counter < ( ( frameSizeReadFromFile_ms * API_fs_Hz ) / 1000 ) ) {\r
-            break;\r
-        }\r
-\r
-        /* max payload size */\r
-        nBytes = MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES;\r
-\r
-        /* Silk Encoder */\r
-        ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, payload, &nBytes );\r
-        if( ret ) {\r
-            printf( "\nSKP_Silk_Encode returned %d", ret );\r
-            break;\r
-        }\r
-\r
-        /* Get packet size */\r
-        packetSize_ms = ( SKP_int )( ( 1000 * ( SKP_int32 )encControl.packetSize ) / encControl.API_sampleRate );\r
-\r
-        smplsSinceLastPacket += ( SKP_int )counter;\r
-        \r
-        if( ( ( 1000 * smplsSinceLastPacket ) / API_fs_Hz ) == packetSize_ms ) {\r
-            /* Sends a dummy zero size packet in case of DTX period  */\r
-            /* to make it work with the decoder test program.        */\r
-            /* In practice should be handled by RTP sequence numbers */\r
-            totPackets++;\r
-            sumBytes  += nBytes;\r
-            nrg = 0.0;\r
-            for( k = 0; k < ( SKP_int )counter; k++ ) {\r
-                nrg += in[ k ] * (double)in[ k ];\r
-            }\r
-            if( ( nrg / ( SKP_int )counter ) > 1e3 ) {\r
-                sumActBytes += nBytes;\r
-                totActPackets++;\r
-            }\r
-\r
-            /* Write payload size */\r
-#ifdef _SYSTEM_IS_BIG_ENDIAN\r
-            nBytes_LE = nBytes;\r
-            swap_endian( &nBytes_LE, 1 );\r
-            fwrite( &nBytes_LE, sizeof( SKP_int16 ), 1, bitOutFile );\r
-#else\r
-            fwrite( &nBytes, sizeof( SKP_int16 ), 1, bitOutFile );\r
-#endif\r
-\r
-            /* Write payload */\r
-            fwrite( payload, sizeof( SKP_uint8 ), nBytes, bitOutFile );\r
-        \r
-            if( !quiet ) {\r
-                fprintf( stderr, "\rPackets encoded:              %d", totPackets );\r
-            }\r
-            smplsSinceLastPacket = 0;\r
-        }\r
-    }\r
-\r
-    /* Write dummy because it can not end with 0 bytes */\r
-    nBytes = -1;\r
-\r
-    /* Write payload size */\r
-    fwrite( &nBytes, sizeof( SKP_int16 ), 1, bitOutFile );\r
-\r
-    /* Free Encoder */\r
-    free( psEnc );\r
-\r
-    fclose( speechInFile );\r
-    fclose( bitOutFile   );\r
-\r
-    avg_rate  = 8.0 / packetSize_ms * sumBytes       / totPackets;\r
-    act_rate  = 8.0 / packetSize_ms * sumActBytes    / totActPackets;\r
-    if( !quiet ) {\r
-        printf( "\nAverage bitrate:             %.3f kbps", avg_rate  );\r
-        printf( "\nActive bitrate:              %.3f kbps", act_rate  );\r
-        printf( "\n\n" );\r
-    } else {\r
-        /* print average and active bitrates */\r
-        printf( "%.3f %.3f \n", avg_rate, act_rate );\r
-    }\r
-    return 0;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+
+/*****************************/
+/* Silk encoder test program */
+/*****************************/
+
+#ifdef _WIN32
+#define _CRT_SECURE_NO_DEPRECATE    1
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "SKP_Silk_SDK_API.h"
+
+/* Define codec specific settings */
+#define MAX_BYTES_PER_FRAME     250 // Equals peak bitrate of 100 kbps 
+#define MAX_INPUT_FRAMES        5
+#define MAX_LBRR_DELAY          2
+#define MAX_FRAME_LENGTH        480
+#define FRAME_LENGTH_MS         20
+#define MAX_API_FS_KHZ          48
+
+#ifdef _SYSTEM_IS_BIG_ENDIAN
+/* Function to convert a little endian int16 to a */
+/* big endian int16 or vica verca                 */
+void swap_endian(
+    SKP_int16       vec[],              /*  I/O array of */
+    SKP_int         len                 /*  I   length      */
+)
+{
+    SKP_int i;
+    SKP_int16 tmp;
+    SKP_uint8 *p1, *p2;
+
+    for( i = 0; i < len; i++ ){
+        tmp = vec[ i ];
+        p1 = (SKP_uint8 *)&vec[ i ]; p2 = (SKP_uint8 *)&tmp;
+        p1[ 0 ] = p2[ 1 ]; p1[ 1 ] = p2[ 0 ];
+    }
+}
+#endif
+
+static void print_usage( char* argv[] ) {
+    printf( "\nusage: %s in.pcm out.bit [settings]\n", argv[ 0 ] );
+    printf( "\nin.pcm               : Speech input to encoder" );
+    printf( "\nstream.bit           : Bitstream output from encoder" );
+    printf( "\n   settings:" );
+    printf( "\n-Fs_API <Hz>         : API sampling rate in Hz, default: 24000" );
+    printf( "\n-Fs_maxInternal <Hz> : Maximum internal sampling rate in Hz, default: 24000" ); 
+    printf( "\n-packetlength <ms>   : Packet interval in ms, default: 20" );
+    printf( "\n-rate <bps>          : Target bitrate; default: 25000" );
+    printf( "\n-loss <perc>         : Uplink loss estimate, in percent (0-100); default: 0" );
+    printf( "\n-inbandFEC <flag>    : Enable inband FEC usage (0/1); default: 0" );
+    printf( "\n-complexity <comp>   : Set complexity, 0: low, 1: medium, 2: high; default: 2" );
+    printf( "\n-DTX <flag>          : Enable DTX (0/1); default: 0" );
+    printf( "\n-quiet               : Print only some basic values" );
+    printf( "\n");
+}
+
+int main( int argc, char* argv[] )
+{
+    size_t    counter;
+    SKP_int32 k, args, totPackets, totActPackets, ret;
+    SKP_int16 nBytes;
+    double    sumBytes, sumActBytes, avg_rate, act_rate, nrg;
+    SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ];
+    SKP_int16 in[ FRAME_LENGTH_MS * MAX_API_FS_KHZ * MAX_INPUT_FRAMES ];
+    char      speechInFileName[ 150 ], bitOutFileName[ 150 ];
+    FILE      *bitOutFile, *speechInFile;
+    SKP_int32 encSizeBytes;
+    void      *psEnc;
+#ifdef _SYSTEM_IS_BIG_ENDIAN
+    SKP_int16 nBytes_LE;
+#endif
+
+    /* default settings */
+    SKP_int32 API_fs_Hz = 24000;
+    SKP_int32 max_internal_fs_Hz = 0;
+    SKP_int32 targetRate_bps = 25000;
+    SKP_int32 packetSize_ms = 20;
+    SKP_int32 frameSizeReadFromFile_ms = 20;
+    SKP_int32 packetLoss_perc = 0, complexity_mode = 2, smplsSinceLastPacket;
+    SKP_int32 INBandFEC_enabled = 0, DTX_enabled = 0, quiet = 0;
+    SKP_SILK_SDK_EncControlStruct encControl; // Struct for input to encoder
+        
+    if( argc < 3 ) {
+        print_usage( argv );
+        exit( 0 );
+    } 
+    
+    /* get arguments */
+    args = 1;
+    strcpy( speechInFileName, argv[ args ] );
+    args++;
+    strcpy( bitOutFileName,   argv[ args ] );
+    args++;
+    while( args < argc ) {
+        if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-Fs_API" ) == 0 ) {
+            sscanf( argv[ args + 1 ], "%d", &API_fs_Hz );
+            args += 2;
+        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-Fs_maxInternal" ) == 0 ) {
+            sscanf( argv[ args + 1 ], "%d", &max_internal_fs_Hz );
+            args += 2;
+        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-packetlength" ) == 0 ) {
+            sscanf( argv[ args + 1 ], "%d", &packetSize_ms );
+            args += 2;
+        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-rate" ) == 0 ) {
+            sscanf( argv[ args + 1 ], "%d", &targetRate_bps );
+            args += 2;
+        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) {
+            sscanf( argv[ args + 1 ], "%d", &packetLoss_perc );
+            args += 2;
+        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-complexity" ) == 0 ) {
+            sscanf( argv[ args + 1 ], "%d", &complexity_mode );
+            args += 2;
+        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-inbandFEC" ) == 0 ) {
+            sscanf( argv[ args + 1 ], "%d", &INBandFEC_enabled );
+            args += 2;
+        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-DTX") == 0 ) {
+            sscanf( argv[ args + 1 ], "%d", &DTX_enabled );
+            args += 2;
+        } else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-quiet" ) == 0 ) {
+            quiet = 1;
+            args++;
+        } else {
+            printf( "Error: unrecognized setting: %s\n\n", argv[ args ] );
+            print_usage( argv );
+            exit( 0 );
+        }
+    }
+
+    /* If no max internal is specified, set to minimum of API fs and 24 kHz */
+    if( max_internal_fs_Hz == 0 ) {
+        max_internal_fs_Hz = 24000;
+        if( API_fs_Hz < max_internal_fs_Hz ) {
+            max_internal_fs_Hz = API_fs_Hz;
+        }
+    }
+
+    /* Print options */
+    if( !quiet ) {
+        printf("******************* Silk Encoder v %s ****************\n", SKP_Silk_SDK_get_version());
+        printf("******************* Compiled for %d bit cpu ********* \n", (int)sizeof(void*) * 8 );
+        printf( "Input:                          %s\n",     speechInFileName );
+        printf( "Output:                         %s\n",     bitOutFileName );
+        printf( "API sampling rate:              %d Hz\n",  API_fs_Hz );
+        printf( "Maximum internal sampling rate: %d Hz\n",  max_internal_fs_Hz );
+        printf( "Packet interval:                %d ms\n",  packetSize_ms );
+        printf( "Inband FEC used:                %d\n",     INBandFEC_enabled );
+        printf( "DTX used:                       %d\n",     DTX_enabled );
+        printf( "Complexity:                     %d\n",     complexity_mode );
+        printf( "Target bitrate:                 %d bps\n", targetRate_bps );
+    }
+
+    /* Open files */
+    speechInFile = fopen( speechInFileName, "rb" );
+    if( speechInFile == NULL ) {
+        printf( "Error: could not open input file %s\n", speechInFileName );
+        exit( 0 );
+    }
+    bitOutFile = fopen( bitOutFileName, "wb" );
+    if( bitOutFile == NULL ) {
+        printf( "Error: could not open output file %s\n", bitOutFileName );
+        exit( 0 );
+    }
+
+    /* Add Silk header to stream */
+    {
+        static const char Silk_header[] = "#!SILK_V3";
+        fwrite( Silk_header, sizeof( char ), strlen( Silk_header ), bitOutFile );
+    }
+
+    /* Create Encoder */
+    ret = SKP_Silk_SDK_Get_Encoder_Size( &encSizeBytes );
+    if( ret ) {
+        printf( "\nSKP_Silk_create_encoder returned %d", ret );
+    }
+
+    psEnc = malloc( encSizeBytes );
+
+    /* Reset Encoder */
+    ret = SKP_Silk_SDK_InitEncoder( psEnc, &encControl );
+    if( ret ) {
+        printf( "\nSKP_Silk_reset_encoder returned %d", ret );
+    }
+    
+    /* Set Encoder parameters */
+    encControl.API_sampleRate        = API_fs_Hz;
+    encControl.maxInternalSampleRate = max_internal_fs_Hz;
+    encControl.packetSize            = ( packetSize_ms * API_fs_Hz ) / 1000;
+    encControl.packetLossPercentage  = packetLoss_perc;
+    encControl.useInBandFEC          = INBandFEC_enabled;
+    encControl.useDTX                = DTX_enabled;
+    encControl.complexity            = complexity_mode;
+    encControl.bitRate               = ( targetRate_bps > 0 ? targetRate_bps : 0 );
+
+    if( API_fs_Hz > MAX_API_FS_KHZ * 1000 || API_fs_Hz < 0 ) {
+        printf( "\nError: API sampling rate = %d out of range, valid range 8000 - 48000 \n \n", API_fs_Hz );
+        exit( 0 );
+    }
+
+    totPackets           = 0;
+    totActPackets        = 0;
+    smplsSinceLastPacket = 0;
+    sumBytes             = 0.0;
+    sumActBytes          = 0.0;
+    
+    while( 1 ) {
+        /* Read input from file */
+        counter = fread( in, sizeof( SKP_int16 ), ( frameSizeReadFromFile_ms * API_fs_Hz ) / 1000, speechInFile );
+#ifdef _SYSTEM_IS_BIG_ENDIAN
+        swap_endian( in, counter );
+#endif
+        if( (SKP_int)counter < ( ( frameSizeReadFromFile_ms * API_fs_Hz ) / 1000 ) ) {
+            break;
+        }
+
+        /* max payload size */
+        nBytes = MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES;
+
+        /* Silk Encoder */
+        ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, payload, &nBytes );
+        if( ret ) {
+            printf( "\nSKP_Silk_Encode returned %d", ret );
+            break;
+        }
+
+        /* Get packet size */
+        packetSize_ms = ( SKP_int )( ( 1000 * ( SKP_int32 )encControl.packetSize ) / encControl.API_sampleRate );
+
+        smplsSinceLastPacket += ( SKP_int )counter;
+        
+        if( ( ( 1000 * smplsSinceLastPacket ) / API_fs_Hz ) == packetSize_ms ) {
+            /* Sends a dummy zero size packet in case of DTX period  */
+            /* to make it work with the decoder test program.        */
+            /* In practice should be handled by RTP sequence numbers */
+            totPackets++;
+            sumBytes  += nBytes;
+            nrg = 0.0;
+            for( k = 0; k < ( SKP_int )counter; k++ ) {
+                nrg += in[ k ] * (double)in[ k ];
+            }
+            if( ( nrg / ( SKP_int )counter ) > 1e3 ) {
+                sumActBytes += nBytes;
+                totActPackets++;
+            }
+
+            /* Write payload size */
+#ifdef _SYSTEM_IS_BIG_ENDIAN
+            nBytes_LE = nBytes;
+            swap_endian( &nBytes_LE, 1 );
+            fwrite( &nBytes_LE, sizeof( SKP_int16 ), 1, bitOutFile );
+#else
+            fwrite( &nBytes, sizeof( SKP_int16 ), 1, bitOutFile );
+#endif
+
+            /* Write payload */
+            fwrite( payload, sizeof( SKP_uint8 ), nBytes, bitOutFile );
+        
+            if( !quiet ) {
+                fprintf( stderr, "\rPackets encoded:              %d", totPackets );
+            }
+            smplsSinceLastPacket = 0;
+        }
+    }
+
+    /* Write dummy because it can not end with 0 bytes */
+    nBytes = -1;
+
+    /* Write payload size */
+    fwrite( &nBytes, sizeof( SKP_int16 ), 1, bitOutFile );
+
+    /* Free Encoder */
+    free( psEnc );
+
+    fclose( speechInFile );
+    fclose( bitOutFile   );
+
+    avg_rate  = 8.0 / packetSize_ms * sumBytes       / totPackets;
+    act_rate  = 8.0 / packetSize_ms * sumActBytes    / totActPackets;
+    if( !quiet ) {
+        printf( "\nAverage bitrate:             %.3f kbps", avg_rate  );
+        printf( "\nActive bitrate:              %.3f kbps", act_rate  );
+        printf( "\n\n" );
+    } else {
+        /* print average and active bitrates */
+        printf( "%.3f %.3f \n", avg_rate, act_rate );
+    }
+    return 0;
+}
index d0eb34dd7124f9a4f48f6745d9c0b5f6f16237fe..41073fb86cc9b2c03d4c79edde8603310e7ad967 100644 (file)
-/***********************************************************************\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
-* Compare two audio signals and compute weighted SNR difference\r
-*/\r
-\r
-#ifdef _WIN32\r
-#define _CRT_SECURE_NO_DEPRECATE    1\r
-#endif\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <math.h>\r
-\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-#define FRAME_LENGTH_MS         10\r
-#define WIN_LENGTH_MS           20\r
-#define BW_EXPANSION            0.7f\r
-\r
-#define MAX_FS_KHZ              48\r
-#define LPC_ORDER               10\r
-#define SNR_THRESHOLD           15.0\r
-\r
-#ifdef  __cplusplus\r
-extern "C"\r
-{\r
-#endif\r
-/* Internally used functions */\r
-void Autocorrelation( \r
-    SKP_float *results,                 /* o    result (length correlationCount)            */\r
-    const SKP_float *inputData,         /* i    input data to correlate                     */\r
-    SKP_int inputDataSize,              /* i    length of input                             */\r
-    SKP_int correlationCount            /* i    number of correlation taps to compute       */\r
-);\r
-\r
-/* inner product of two SKP_float arrays, with result as double */\r
-double Inner_product( \r
-    const SKP_float     *data1, \r
-    const SKP_float     *data2, \r
-    SKP_int             dataSize\r
-);\r
-/* Solve the normal equations using the Levinson-Durbin recursion */\r
-SKP_float Levinsondurbin(               /* O    prediction error energy                     */\r
-    SKP_float       A[],                /* O    prediction coefficients [order]             */\r
-    const SKP_float corr[],             /* I    input auto-correlations [order + 1]         */\r
-    const SKP_int   order               /* I    prediction order                            */\r
-);\r
-\r
-/* Chirp (bw expand) LP AR filter */\r
-void Bwexpander( \r
-    SKP_float *ar,                      /* io   AR filter to be expanded (without leading 1)    */\r
-    const SKP_int d,                    /* i    length of ar                                    */\r
-    const SKP_float chirp               /* i    chirp factor (typically in range (0..1) )       */\r
-);\r
-\r
-#ifdef  __cplusplus\r
-}\r
-#endif\r
-\r
-static void print_usage(char* argv[]) {\r
-    printf("\nusage: %s ref.pcm test.pcm [settings]\n", argv[ 0 ]);\r
-    printf("\nref.pcm       : Reference file");\r
-    printf("\ntest.pcm      : File to be tested, should be of same length as ref.pcm");\r
-    printf("\n   settings:");\r
-    printf("\n-diff         : Only determine bit-exactness");\r
-    printf("\n-fs <Hz>      : Sampling rate in Hz, max: %d; default: 48000", MAX_FS_KHZ * 1000 );\r
-    printf("\n");\r
-}\r
-\r
-\r
-int main(int argc, char* argv[])\r
-{\r
-    SKP_int   args, n, i, counterRef, counterTest;\r
-    char      testInFileName[150], refInFileName[150];\r
-    FILE      *refInFile, *testInFile;\r
-    SKP_int   nFrames = 0, isUnequal = 0;\r
-    SKP_int   diff = 0, Fs_kHz;\r
-    SKP_int32 Fs_Hz = 24000;\r
-    SKP_float c, refWhtnd, testWhtnd, refNrg, diffNrg;\r
-    double    SNR = 0.0;\r
-    SKP_int16 refIn[WIN_LENGTH_MS * MAX_FS_KHZ], testIn[WIN_LENGTH_MS * MAX_FS_KHZ];\r
-    SKP_float refWin[WIN_LENGTH_MS * MAX_FS_KHZ], testWin[WIN_LENGTH_MS * MAX_FS_KHZ];\r
-    SKP_float autoCorr[LPC_ORDER + 1], LPC_Coef[LPC_ORDER];\r
-\r
-    if (argc < 3) {\r
-        print_usage(argv);\r
-        exit(0);\r
-    } \r
-\r
-    /* get arguments */\r
-    args = 1;\r
-    strcpy(refInFileName, argv[args]);\r
-    args++;\r
-    strcpy(testInFileName, argv[args]);\r
-    args++;\r
-    while(args < argc ) {\r
-        if (SKP_STR_CASEINSENSITIVE_COMPARE(argv[args], "-diff") == 0) {\r
-            diff = 1;\r
-            args++;\r
-        }else if (SKP_STR_CASEINSENSITIVE_COMPARE(argv[args], "-fs") == 0) {\r
-            sscanf(argv[args+1], "%d", &Fs_Hz);\r
-            args += 2;\r
-        } else {\r
-            printf("Error: unrecognized setting: %s\n\n", argv[args]);\r
-            print_usage(argv);\r
-            exit(0);\r
-        }\r
-    }\r
-\r
-    Fs_kHz = SKP_DIV32_16( Fs_Hz, 1000 );\r
-\r
-    if( Fs_kHz > MAX_FS_KHZ ) {\r
-        printf("Error: sampling rate too high: %d\n\n", Fs_kHz);\r
-        print_usage(argv);\r
-        exit(0);\r
-    }\r
-\r
-    printf("Reference:  %s\n", refInFileName);\r
-    //printf("Test:       %s\n", testInFileName);\r
-\r
-    /* open files */\r
-    refInFile = fopen(refInFileName, "rb");\r
-    if (refInFile==NULL) {\r
-        printf("Error: could not open input file %s\n", refInFileName);\r
-        exit(0);\r
-    } \r
-    testInFile = fopen(testInFileName, "rb");\r
-    if (testInFile==NULL) {\r
-        printf("Error: could not open input file %s\n", testInFileName);\r
-        exit(0);\r
-    }\r
-\r
-    SKP_memset( refIn,  0, sizeof(refIn) );\r
-    SKP_memset( testIn, 0, sizeof(testIn) );\r
-\r
-    while(1) {\r
-        /* Read inputs */\r
-        counterRef  = (SKP_int)fread(&refIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz], \r
-            sizeof(SKP_int16), FRAME_LENGTH_MS * Fs_kHz, refInFile);\r
-        counterTest = (SKP_int)fread(&testIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz], \r
-            sizeof(SKP_int16), FRAME_LENGTH_MS * Fs_kHz, testInFile);\r
-        if(counterRef != FRAME_LENGTH_MS * Fs_kHz || counterTest != FRAME_LENGTH_MS * Fs_kHz){\r
-            break;\r
-        }\r
-\r
-        /* test for bit-exactness */\r
-        for( n = 0; n < FRAME_LENGTH_MS * Fs_kHz; n++ ) {\r
-            if( refIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz + n] != \r
-                testIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz + n] ) {\r
-                    isUnequal = 1;\r
-                    break;\r
-            }\r
-        }\r
-\r
-        /* apply sine window */\r
-        for( n = 0; n < WIN_LENGTH_MS * Fs_kHz; n++ ) {\r
-            c = (SKP_float)sin( 3.14159265 * (n + 1) / (WIN_LENGTH_MS * Fs_kHz + 1) );\r
-            refWin[n]  = refIn[n]  * c;\r
-            testWin[n] = testIn[n] * c;\r
-        }\r
-\r
-        /* LPC analysis on reference signal */\r
-\r
-        /* Calculate auto correlation */\r
-        Autocorrelation(autoCorr, refWin, WIN_LENGTH_MS * Fs_kHz, LPC_ORDER + 1);\r
-\r
-        /* Add white noise */\r
-        autoCorr[ 0 ] += autoCorr[ 0 ] * 1e-6f + 1.0f; \r
-\r
-        /* Convert correlations to prediction coefficients */\r
-        Levinsondurbin(LPC_Coef, autoCorr, LPC_ORDER);\r
-\r
-        /* Bandwdith expansion */\r
-        Bwexpander(LPC_Coef, LPC_ORDER, BW_EXPANSION);\r
-\r
-        /* Filter both signals */\r
-        refNrg = 1.0f;\r
-        diffNrg = 1e-10f;\r
-        for( n = (WIN_LENGTH_MS - FRAME_LENGTH_MS) / 2 * Fs_kHz; \r
-             n < (WIN_LENGTH_MS + FRAME_LENGTH_MS) / 2 * Fs_kHz; n++ ) {\r
-                refWhtnd = refIn[n];\r
-                testWhtnd = testIn[n];\r
-                for( i = 0; i < LPC_ORDER; i++ ) {\r
-                    refWhtnd  -= LPC_Coef[ i ] * refIn[n - i - 1];\r
-                    testWhtnd -= LPC_Coef[ i ] * testIn[n - i - 1];\r
-                }\r
-                refNrg += refWhtnd * refWhtnd;\r
-                diffNrg += (refWhtnd - testWhtnd) * (refWhtnd - testWhtnd);\r
-        }\r
-\r
-        /* weighted SNR */\r
-        if( refNrg > FRAME_LENGTH_MS * Fs_kHz ) {\r
-            SNR += 10.0 * log10( refNrg / diffNrg );\r
-            nFrames++;\r
-        }\r
-\r
-        /* Update Buffer */\r
-        SKP_memmove( refIn,  &refIn[FRAME_LENGTH_MS * Fs_kHz],  (WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz * sizeof(SKP_int16));\r
-        SKP_memmove( testIn, &testIn[FRAME_LENGTH_MS * Fs_kHz], (WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz * sizeof(SKP_int16));\r
-    }\r
-\r
-    if( diff ) {\r
-        if( isUnequal ) {\r
-            printf("Signals differ\n");\r
-        } else {\r
-            if(counterRef != counterTest){\r
-                printf("Warning: signals differ in length\n");\r
-            }\r
-            printf("Signals are bit-exact          PASS\n");\r
-        }\r
-    } else {\r
-        if( nFrames == 0 ) {\r
-            printf("At least one signal too short or not loud enough\n");\r
-            exit(0);\r
-        }\r
-        if(counterRef != counterTest){\r
-            printf("Warning: signals differ in length\n");\r
-        }\r
-        if( isUnequal == 0 ) {\r
-            printf("Signals are bit-exact          PASS\n");\r
-        } else {\r
-            printf("Average weighted SNR: %4.1f dB  ", SNR / nFrames);\r
-            if( SNR / nFrames < SNR_THRESHOLD ) {\r
-                printf("FAIL\n");\r
-            } else {\r
-                printf("PASS\n");\r
-            }\r
-        }\r
-    }\r
-    printf("\n");\r
-\r
-    /* Close Files */\r
-    fclose(refInFile);\r
-    fclose(testInFile);\r
-\r
-    return 0;\r
-}\r
-\r
-/* compute autocorrelation */\r
-void Autocorrelation( \r
-    SKP_float *results,                 /* o    result (length correlationCount)            */\r
-    const SKP_float *inputData,         /* i    input data to correlate                     */\r
-    SKP_int inputDataSize,              /* i    length of input                             */\r
-    SKP_int correlationCount            /* i    number of correlation taps to compute       */\r
-)\r
-{\r
-    SKP_int i;\r
-\r
-    if (correlationCount > inputDataSize) {\r
-        correlationCount = inputDataSize;\r
-    }\r
-\r
-    for( i = 0; i < correlationCount; i++ ) {\r
-        results[ i ] =  (SKP_float)Inner_product( inputData, inputData + i, inputDataSize - i );\r
-    }\r
-}\r
-\r
-/* inner product of two SKP_float arrays, with result as double */\r
-double Inner_product( \r
-    const SKP_float     *data1, \r
-    const SKP_float     *data2, \r
-    SKP_int             dataSize\r
-)\r
-{\r
-    SKP_int  i, dataSize4;\r
-    double   result;\r
-\r
-    /* 4x unrolled loop */\r
-    result = 0.0f;\r
-    dataSize4 = dataSize & 0xFFFC;\r
-    for( i = 0; i < dataSize4; i += 4 ) {\r
-        result += data1[ i + 0 ] * data2[ i + 0 ] + \r
-                  data1[ i + 1 ] * data2[ i + 1 ] +\r
-                  data1[ i + 2 ] * data2[ i + 2 ] +\r
-                  data1[ i + 3 ] * data2[ i + 3 ];\r
-    }\r
-\r
-    /* add any remaining products */\r
-    for( ; i < dataSize; i++ ) {\r
-        result += data1[ i ] * data2[ i ];\r
-    }\r
-\r
-    return result;\r
-}\r
-\r
-/* Solve the normal equations using the Levinson-Durbin recursion */\r
-SKP_float Levinsondurbin(               /* O    prediction error energy                     */\r
-    SKP_float       A[],                /* O    prediction coefficients [order]             */\r
-    const SKP_float corr[],             /* I    input auto-correlations [order + 1]         */\r
-    const SKP_int   order               /* I    prediction order                            */\r
-)\r
-{\r
-    SKP_int   i, mHalf, m;\r
-    SKP_float min_nrg, nrg, t, km, Atmp1, Atmp2;\r
-    \r
-    min_nrg = 1e-12f * corr[ 0 ] + 1e-9f;\r
-    nrg = corr[ 0 ];\r
-    nrg = SKP_max(min_nrg, nrg);\r
-    A[ 0 ] = corr[ 1 ] / nrg;\r
-    nrg -= A[ 0 ] * corr[ 1 ];\r
-    nrg = SKP_max(min_nrg, nrg);\r
-\r
-    for( m = 1; m < order; m++ )\r
-    {\r
-        t = corr[ m + 1 ];\r
-        for( i = 0; i < m; i++ ) {\r
-            t -= A[ i ] * corr[ m - i ];\r
-        }\r
-\r
-        /* reflection coefficient */\r
-        km = t / nrg;\r
-\r
-        /* residual energy */\r
-        nrg -= km * t;\r
-        nrg = SKP_max(min_nrg, nrg);\r
-\r
-        mHalf = m >> 1;\r
-        for( i = 0; i < mHalf; i++ ) {\r
-            Atmp1 = A[ i ];\r
-            Atmp2 = A[ m - i - 1 ];\r
-            A[ m - i - 1 ] -= km * Atmp1;\r
-            A[ i ]         -= km * Atmp2;\r
-        }\r
-        if( m & 1 ) {\r
-            A[ mHalf ]     -= km * A[ mHalf ];\r
-        }\r
-        A[ m ] = km;\r
-    }\r
-\r
-    /* return the residual energy */\r
-    return nrg;\r
-}\r
-\r
-/* Chirp (bw expand) LP AR filter */\r
-void Bwexpander( \r
-    SKP_float *ar,                      /* io   AR filter to be expanded (without leading 1)    */\r
-    const SKP_int d,                    /* i    length of ar                                    */\r
-    const SKP_float chirp               /* i    chirp factor (typically in range (0..1) )       */\r
-)\r
-{\r
-    SKP_int   i;\r
-    SKP_float cfac = chirp;\r
-\r
-    for( i = 0; i < d - 1; i++ ) {\r
-        ar[ i ] *=  cfac;\r
-        cfac    *=  chirp;\r
-    }\r
-    ar[ d - 1 ] *=  cfac;\r
-}\r
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. 
+Redistribution and use in source and binary forms, with or without 
+modification, (subject to the limitations in the disclaimer below) 
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in the 
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific 
+contributors, may be used to endorse or promote products derived from 
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/*
+* Compare two audio signals and compute weighted SNR difference
+*/
+
+#ifdef _WIN32
+#define _CRT_SECURE_NO_DEPRECATE    1
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "SKP_Silk_SigProc_FIX.h"
+
+#define FRAME_LENGTH_MS         10
+#define WIN_LENGTH_MS           20
+#define BW_EXPANSION            0.7f
+
+#define MAX_FS_KHZ              48
+#define LPC_ORDER               10
+#define SNR_THRESHOLD           15.0
+
+#ifdef  __cplusplus
+extern "C"
+{
+#endif
+/* Internally used functions */
+void Autocorrelation( 
+    SKP_float *results,                 /* o    result (length correlationCount)            */
+    const SKP_float *inputData,         /* i    input data to correlate                     */
+    SKP_int inputDataSize,              /* i    length of input                             */
+    SKP_int correlationCount            /* i    number of correlation taps to compute       */
+);
+
+/* inner product of two SKP_float arrays, with result as double */
+double Inner_product( 
+    const SKP_float     *data1, 
+    const SKP_float     *data2, 
+    SKP_int             dataSize
+);
+/* Solve the normal equations using the Levinson-Durbin recursion */
+SKP_float Levinsondurbin(               /* O    prediction error energy                     */
+    SKP_float       A[],                /* O    prediction coefficients [order]             */
+    const SKP_float corr[],             /* I    input auto-correlations [order + 1]         */
+    const SKP_int   order               /* I    prediction order                            */
+);
+
+/* Chirp (bw expand) LP AR filter */
+void Bwexpander( 
+    SKP_float *ar,                      /* io   AR filter to be expanded (without leading 1)    */
+    const SKP_int d,                    /* i    length of ar                                    */
+    const SKP_float chirp               /* i    chirp factor (typically in range (0..1) )       */
+);
+
+#ifdef  __cplusplus
+}
+#endif
+
+static void print_usage(char* argv[]) {
+    printf("\nusage: %s ref.pcm test.pcm [settings]\n", argv[ 0 ]);
+    printf("\nref.pcm       : Reference file");
+    printf("\ntest.pcm      : File to be tested, should be of same length as ref.pcm");
+    printf("\n   settings:");
+    printf("\n-diff         : Only determine bit-exactness");
+    printf("\n-fs <Hz>      : Sampling rate in Hz, max: %d; default: 48000", MAX_FS_KHZ * 1000 );
+    printf("\n");
+}
+
+
+int main(int argc, char* argv[])
+{
+    SKP_int   args, n, i, counterRef, counterTest;
+    char      testInFileName[150], refInFileName[150];
+    FILE      *refInFile, *testInFile;
+    SKP_int   nFrames = 0, isUnequal = 0;
+    SKP_int   diff = 0, Fs_kHz;
+    SKP_int32 Fs_Hz = 24000;
+    SKP_float c, refWhtnd, testWhtnd, refNrg, diffNrg;
+    double    SNR = 0.0;
+    SKP_int16 refIn[WIN_LENGTH_MS * MAX_FS_KHZ], testIn[WIN_LENGTH_MS * MAX_FS_KHZ];
+    SKP_float refWin[WIN_LENGTH_MS * MAX_FS_KHZ], testWin[WIN_LENGTH_MS * MAX_FS_KHZ];
+    SKP_float autoCorr[LPC_ORDER + 1], LPC_Coef[LPC_ORDER];
+
+    if (argc < 3) {
+        print_usage(argv);
+        exit(0);
+    } 
+
+    /* get arguments */
+    args = 1;
+    strcpy(refInFileName, argv[args]);
+    args++;
+    strcpy(testInFileName, argv[args]);
+    args++;
+    while(args < argc ) {
+        if (SKP_STR_CASEINSENSITIVE_COMPARE(argv[args], "-diff") == 0) {
+            diff = 1;
+            args++;
+        }else if (SKP_STR_CASEINSENSITIVE_COMPARE(argv[args], "-fs") == 0) {
+            sscanf(argv[args+1], "%d", &Fs_Hz);
+            args += 2;
+        } else {
+            printf("Error: unrecognized setting: %s\n\n", argv[args]);
+            print_usage(argv);
+            exit(0);
+        }
+    }
+
+    Fs_kHz = SKP_DIV32_16( Fs_Hz, 1000 );
+
+    if( Fs_kHz > MAX_FS_KHZ ) {
+        printf("Error: sampling rate too high: %d\n\n", Fs_kHz);
+        print_usage(argv);
+        exit(0);
+    }
+
+    printf("Reference:  %s\n", refInFileName);
+    //printf("Test:       %s\n", testInFileName);
+
+    /* open files */
+    refInFile = fopen(refInFileName, "rb");
+    if (refInFile==NULL) {
+        printf("Error: could not open input file %s\n", refInFileName);
+        exit(0);
+    } 
+    testInFile = fopen(testInFileName, "rb");
+    if (testInFile==NULL) {
+        printf("Error: could not open input file %s\n", testInFileName);
+        exit(0);
+    }
+
+    SKP_memset( refIn,  0, sizeof(refIn) );
+    SKP_memset( testIn, 0, sizeof(testIn) );
+
+    while(1) {
+        /* Read inputs */
+        counterRef  = (SKP_int)fread(&refIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz], 
+            sizeof(SKP_int16), FRAME_LENGTH_MS * Fs_kHz, refInFile);
+        counterTest = (SKP_int)fread(&testIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz], 
+            sizeof(SKP_int16), FRAME_LENGTH_MS * Fs_kHz, testInFile);
+        if(counterRef != FRAME_LENGTH_MS * Fs_kHz || counterTest != FRAME_LENGTH_MS * Fs_kHz){
+            break;
+        }
+
+        /* test for bit-exactness */
+        for( n = 0; n < FRAME_LENGTH_MS * Fs_kHz; n++ ) {
+            if( refIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz + n] != 
+                testIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz + n] ) {
+                    isUnequal = 1;
+                    break;
+            }
+        }
+
+        /* apply sine window */
+        for( n = 0; n < WIN_LENGTH_MS * Fs_kHz; n++ ) {
+            c = (SKP_float)sin( 3.14159265 * (n + 1) / (WIN_LENGTH_MS * Fs_kHz + 1) );
+            refWin[n]  = refIn[n]  * c;
+            testWin[n] = testIn[n] * c;
+        }
+
+        /* LPC analysis on reference signal */
+
+        /* Calculate auto correlation */
+        Autocorrelation(autoCorr, refWin, WIN_LENGTH_MS * Fs_kHz, LPC_ORDER + 1);
+
+        /* Add white noise */
+        autoCorr[ 0 ] += autoCorr[ 0 ] * 1e-6f + 1.0f; 
+
+        /* Convert correlations to prediction coefficients */
+        Levinsondurbin(LPC_Coef, autoCorr, LPC_ORDER);
+
+        /* Bandwdith expansion */
+        Bwexpander(LPC_Coef, LPC_ORDER, BW_EXPANSION);
+
+        /* Filter both signals */
+        refNrg = 1.0f;
+        diffNrg = 1e-10f;
+        for( n = (WIN_LENGTH_MS - FRAME_LENGTH_MS) / 2 * Fs_kHz; 
+             n < (WIN_LENGTH_MS + FRAME_LENGTH_MS) / 2 * Fs_kHz; n++ ) {
+                refWhtnd = refIn[n];
+                testWhtnd = testIn[n];
+                for( i = 0; i < LPC_ORDER; i++ ) {
+                    refWhtnd  -= LPC_Coef[ i ] * refIn[n - i - 1];
+                    testWhtnd -= LPC_Coef[ i ] * testIn[n - i - 1];
+                }
+                refNrg += refWhtnd * refWhtnd;
+                diffNrg += (refWhtnd - testWhtnd) * (refWhtnd - testWhtnd);
+        }
+
+        /* weighted SNR */
+        if( refNrg > FRAME_LENGTH_MS * Fs_kHz ) {
+            SNR += 10.0 * log10( refNrg / diffNrg );
+            nFrames++;
+        }
+
+        /* Update Buffer */
+        SKP_memmove( refIn,  &refIn[FRAME_LENGTH_MS * Fs_kHz],  (WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz * sizeof(SKP_int16));
+        SKP_memmove( testIn, &testIn[FRAME_LENGTH_MS * Fs_kHz], (WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz * sizeof(SKP_int16));
+    }
+
+    if( diff ) {
+        if( isUnequal ) {
+            printf("Signals differ\n");
+        } else {
+            if(counterRef != counterTest){
+                printf("Warning: signals differ in length\n");
+            }
+            printf("Signals are bit-exact          PASS\n");
+        }
+    } else {
+        if( nFrames == 0 ) {
+            printf("At least one signal too short or not loud enough\n");
+            exit(0);
+        }
+        if(counterRef != counterTest){
+            printf("Warning: signals differ in length\n");
+        }
+        if( isUnequal == 0 ) {
+            printf("Signals are bit-exact          PASS\n");
+        } else {
+            printf("Average weighted SNR: %4.1f dB  ", SNR / nFrames);
+            if( SNR / nFrames < SNR_THRESHOLD ) {
+                printf("FAIL\n");
+            } else {
+                printf("PASS\n");
+            }
+        }
+    }
+    printf("\n");
+
+    /* Close Files */
+    fclose(refInFile);
+    fclose(testInFile);
+
+    return 0;
+}
+
+/* compute autocorrelation */
+void Autocorrelation( 
+    SKP_float *results,                 /* o    result (length correlationCount)            */
+    const SKP_float *inputData,         /* i    input data to correlate                     */
+    SKP_int inputDataSize,              /* i    length of input                             */
+    SKP_int correlationCount            /* i    number of correlation taps to compute       */
+)
+{
+    SKP_int i;
+
+    if (correlationCount > inputDataSize) {
+        correlationCount = inputDataSize;
+    }
+
+    for( i = 0; i < correlationCount; i++ ) {
+        results[ i ] =  (SKP_float)Inner_product( inputData, inputData + i, inputDataSize - i );
+    }
+}
+
+/* inner product of two SKP_float arrays, with result as double */
+double Inner_product( 
+    const SKP_float     *data1, 
+    const SKP_float     *data2, 
+    SKP_int             dataSize
+)
+{
+    SKP_int  i, dataSize4;
+    double   result;
+
+    /* 4x unrolled loop */
+    result = 0.0f;
+    dataSize4 = dataSize & 0xFFFC;
+    for( i = 0; i < dataSize4; i += 4 ) {
+        result += data1[ i + 0 ] * data2[ i + 0 ] + 
+                  data1[ i + 1 ] * data2[ i + 1 ] +
+                  data1[ i + 2 ] * data2[ i + 2 ] +
+                  data1[ i + 3 ] * data2[ i + 3 ];
+    }
+
+    /* add any remaining products */
+    for( ; i < dataSize; i++ ) {
+        result += data1[ i ] * data2[ i ];
+    }
+
+    return result;
+}
+
+/* Solve the normal equations using the Levinson-Durbin recursion */
+SKP_float Levinsondurbin(               /* O    prediction error energy                     */
+    SKP_float       A[],                /* O    prediction coefficients [order]             */
+    const SKP_float corr[],             /* I    input auto-correlations [order + 1]         */
+    const SKP_int   order               /* I    prediction order                            */
+)
+{
+    SKP_int   i, mHalf, m;
+    SKP_float min_nrg, nrg, t, km, Atmp1, Atmp2;
+    
+    min_nrg = 1e-12f * corr[ 0 ] + 1e-9f;
+    nrg = corr[ 0 ];
+    nrg = SKP_max(min_nrg, nrg);
+    A[ 0 ] = corr[ 1 ] / nrg;
+    nrg -= A[ 0 ] * corr[ 1 ];
+    nrg = SKP_max(min_nrg, nrg);
+
+    for( m = 1; m < order; m++ )
+    {
+        t = corr[ m + 1 ];
+        for( i = 0; i < m; i++ ) {
+            t -= A[ i ] * corr[ m - i ];
+        }
+
+        /* reflection coefficient */
+        km = t / nrg;
+
+        /* residual energy */
+        nrg -= km * t;
+        nrg = SKP_max(min_nrg, nrg);
+
+        mHalf = m >> 1;
+        for( i = 0; i < mHalf; i++ ) {
+            Atmp1 = A[ i ];
+            Atmp2 = A[ m - i - 1 ];
+            A[ m - i - 1 ] -= km * Atmp1;
+            A[ i ]         -= km * Atmp2;
+        }
+        if( m & 1 ) {
+            A[ mHalf ]     -= km * A[ mHalf ];
+        }
+        A[ m ] = km;
+    }
+
+    /* return the residual energy */
+    return nrg;
+}
+
+/* Chirp (bw expand) LP AR filter */
+void Bwexpander( 
+    SKP_float *ar,                      /* io   AR filter to be expanded (without leading 1)    */
+    const SKP_int d,                    /* i    length of ar                                    */
+    const SKP_float chirp               /* i    chirp factor (typically in range (0..1) )       */
+)
+{
+    SKP_int   i;
+    SKP_float cfac = chirp;
+
+    for( i = 0; i < d - 1; i++ ) {
+        ar[ i ] *=  cfac;
+        cfac    *=  chirp;
+    }
+    ar[ d - 1 ] *=  cfac;
+}
index 8abf1ca7f0f24c2e9ca25fe22a038ddc73e868c3..141531b96a0ce23047f6e22e9b7b4cd3614b311d 100644 (file)
@@ -1,24 +1,24 @@
-Use the following scripts to verify the decoder implementation:\r
-\r
-o test_encoder.bat / test_encoder.sh\r
-\r
-  Make sure the encoder executable to be tested exists in the parent directory, and run \r
-  test_encoder.bat (win) or test_encoder.sh (linux/mac). This will run the encoder \r
-  and compare the output bitstream with the reference bitstream files. The result is \r
-  written to test_encoder_report.txt.\r
-  For each file, the bitstreams are either bit-exact or they differ. The compatibility \r
-  test is passed if each file is reported as "PASS".\r
-\r
-o test_decoder.bat / test_decoder.sh\r
-\r
-  Make sure the decoder executable to be tested exists in the parent directory, and run \r
-  test_decoder.bat (win) or test_decoder.sh (linux/mac). This will run the decoder \r
-  and compare the output audio file with the reference audio files. The result is \r
-  written to test_decoder_report.txt.\r
-  For each file, the bitstreams are either bit-exact or they match up to a certain\r
-  average weighted SNR. The compatibility test is passed if each file is reported as \r
-  "PASS".\r
-\r
-\r
-NOTE: When using the shell script, make sure it is marked as executable.\r
-      This can be done by: chmod +x *.sh\r
+Use the following scripts to verify the decoder implementation:
+
+o test_encoder.bat / test_encoder.sh
+
+  Make sure the encoder executable to be tested exists in the parent directory, and run 
+  test_encoder.bat (win) or test_encoder.sh (linux/mac). This will run the encoder 
+  and compare the output bitstream with the reference bitstream files. The result is 
+  written to test_encoder_report.txt.
+  For each file, the bitstreams are either bit-exact or they differ. The compatibility 
+  test is passed if each file is reported as "PASS".
+
+o test_decoder.bat / test_decoder.sh
+
+  Make sure the decoder executable to be tested exists in the parent directory, and run 
+  test_decoder.bat (win) or test_decoder.sh (linux/mac). This will run the decoder 
+  and compare the output audio file with the reference audio files. The result is 
+  written to test_decoder_report.txt.
+  For each file, the bitstreams are either bit-exact or they match up to a certain
+  average weighted SNR. The compatibility test is passed if each file is reported as 
+  "PASS".
+
+
+NOTE: When using the shell script, make sure it is marked as executable.
+      This can be done by: chmod +x *.sh
index 5d0c4a421337a006baa762448a9f2d3b443aec9a..1d9708a4141b2e3672686a578571aa5a8faae2fd 100644 (file)
@@ -1,20 +1,20 @@
-INVITE sip:1234@10.50.71.28 SIP/2.0\r
-To: <sip:1234@10.50.71.28>\r
-From: "Displayname" <sip:1234@testaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.example.local:5060>;tag=10052\r
-Via: SIP/2.0/UDP 10.50.71.29:5060;branch=z9hG4bK10052t1174659568681\r
-Call-ID: s0c00010052i0t1174659568681@10.50.71.29\r
-Contact: "999" <sip:999@10.50.71.29;transport=udp>\r
-Content-Length: 180\r
-Content-Type: application/sdp\r
-CSeq: 1 INVITE\r
-Max-Forwards: 70\r
-\r
-v=0\r
-o=999 1 1 IN IP4 10.50.71.29\r
-s=Codenomicon SIP UAS Test Tool 3.0.2 (http://www.codenomicon.com/)\r
-c=IN IP4 10.50.71.29\r
-t=0 0\r
-m=audio 49152 RTP/AVP 0\r
+INVITE sip:1234@10.50.71.28 SIP/2.0
+To: <sip:1234@10.50.71.28>
+From: "Displayname" <sip:1234@testaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.example.local:5060>;tag=10052
+Via: SIP/2.0/UDP 10.50.71.29:5060;branch=z9hG4bK10052t1174659568681
+Call-ID: s0c00010052i0t1174659568681@10.50.71.29
+Contact: "999" <sip:999@10.50.71.29;transport=udp>
+Content-Length: 180
+Content-Type: application/sdp
+CSeq: 1 INVITE
+Max-Forwards: 70
+
+v=0
+o=999 1 1 IN IP4 10.50.71.29
+s=Codenomicon SIP UAS Test Tool 3.0.2 (http://www.codenomicon.com/)
+c=IN IP4 10.50.71.29
+t=0 0
+m=audio 49152 RTP/AVP 0
 a=rtpmap:0 PCMU/8000
\ No newline at end of file
index b81fb9744408443e4530bf6b58c716a4b0598675..bc64fdfd641dfa646aac1f62f32b0720cbfd8cbe 100644 (file)
@@ -1,45 +1,45 @@
-REGISTER sip:garage.sr.ntc.nokia.com SIP/2.0\r
-Via: SIP/2.0/UDP srlab.sr.ntc.nokia.com:5060;maddr=192.168.102.5\r
-Via: SIP/2.0/TCP srlab.sr.ntc.nokia.com:5060;maddr=192.168.102.5 (NTA 1.0)\r
-Via: SIP/2.0/UDP 192.2.2.1:5060;received=[ffe0::FAB1]\r
-Route: <sip:garage.sr.ntc.nokia.com:5060;maddr=srlab.sr.ntc.nokia.com>;foo=bar\r
-Record-Route: <sip:garage.sr.ntc.nokia.com:5060;maddr=srlab.sr.ntc.nokia.com>\r
-Hide: route\r
-Max-Forwards: 15\r
-From: sip:digest@garage.sr.ntc.nokia.com\r
-To: sip:digest@garage.sr.ntc.nokia.com\r
-Contact: sip:digest@172.21.9.155\r
-Call-ID: 982773899-reg@172.21.9.155\r
-CSeq: 2 REGISTER\r
-Subject: Barfoo\r
-Priority: emergency\r
-Date: Wed, 04 Apr 2001 17:38:38 GMT\r
-Retry-After: Wed, 04 Apr 2001 19:00:00 GMT (wake-up) ;duration=1800\r
-Timestamp: 986395257.13924321 3\r
-Expires: 180\r
-Also: sip:digestify@garage.sr.ntc.nokia.com\r
-Call-Info: <http://garage.sr.ntc.nokia.com/images/face.jpg>;purpose=icon\r
-Organization: Fuzzy Felines, Inc.\r
-Server: please\r
-User-Agent: Nokia Universal Killer Internet Application/2.0 (NUUKIA)\r
-In-Reply-To: 982773898-reg@172.21.9.155\r
-Accept: text/plain\r
-Accept-Encoding: identity, deflate (???)\r
-Accept-Language: en\r
-Allow: any\r
-Require: all\r
-Proxy-Require: kinky, things\r
-Supported: sip-cc, sip-cc-01, timer\r
-Unsupported: everything\r
-Error-Info: <http://garage.sr.ntc.nokia.com/figure-1.jpg>\r
-Warning: 300 garage.sr.ntc.nokia.com IPv6 global addresses not available\r
-Warning: 330 garage.sr.ntc.nokia.com No IPv6 multicast, 330 garage.sr.ntc.nokia.com Only local IPv4 multicast available\r
-Authorization: Digest USERNAME="digest", REALM="garage.sr.ntc.nokia.com", NONCE="MjAwMS0wMS0yMSAxNTowODo1OA==", RESPONSE="d9d7f1ae99a013cb05f319f0f678251d", URI="sip:garage.sr.ntc.nokia.com"\r
-Via: SIP/2.0/UDP 172.21.9.155\r
-MIME-Version: 1.0\r
-Content-Type: text/plain;charset=US-ASCII\r
-Content-Encoding: identity\r
-Content-Disposition: render;handling=optional\r
-Content-Length: 31\r
-\r
-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r
+REGISTER sip:garage.sr.ntc.nokia.com SIP/2.0
+Via: SIP/2.0/UDP srlab.sr.ntc.nokia.com:5060;maddr=192.168.102.5
+Via: SIP/2.0/TCP srlab.sr.ntc.nokia.com:5060;maddr=192.168.102.5 (NTA 1.0)
+Via: SIP/2.0/UDP 192.2.2.1:5060;received=[ffe0::FAB1]
+Route: <sip:garage.sr.ntc.nokia.com:5060;maddr=srlab.sr.ntc.nokia.com>;foo=bar
+Record-Route: <sip:garage.sr.ntc.nokia.com:5060;maddr=srlab.sr.ntc.nokia.com>
+Hide: route
+Max-Forwards: 15
+From: sip:digest@garage.sr.ntc.nokia.com
+To: sip:digest@garage.sr.ntc.nokia.com
+Contact: sip:digest@172.21.9.155
+Call-ID: 982773899-reg@172.21.9.155
+CSeq: 2 REGISTER
+Subject: Barfoo
+Priority: emergency
+Date: Wed, 04 Apr 2001 17:38:38 GMT
+Retry-After: Wed, 04 Apr 2001 19:00:00 GMT (wake-up) ;duration=1800
+Timestamp: 986395257.13924321 3
+Expires: 180
+Also: sip:digestify@garage.sr.ntc.nokia.com
+Call-Info: <http://garage.sr.ntc.nokia.com/images/face.jpg>;purpose=icon
+Organization: Fuzzy Felines, Inc.
+Server: please
+User-Agent: Nokia Universal Killer Internet Application/2.0 (NUUKIA)
+In-Reply-To: 982773898-reg@172.21.9.155
+Accept: text/plain
+Accept-Encoding: identity, deflate (???)
+Accept-Language: en
+Allow: any
+Require: all
+Proxy-Require: kinky, things
+Supported: sip-cc, sip-cc-01, timer
+Unsupported: everything
+Error-Info: <http://garage.sr.ntc.nokia.com/figure-1.jpg>
+Warning: 300 garage.sr.ntc.nokia.com IPv6 global addresses not available
+Warning: 330 garage.sr.ntc.nokia.com No IPv6 multicast, 330 garage.sr.ntc.nokia.com Only local IPv4 multicast available
+Authorization: Digest USERNAME="digest", REALM="garage.sr.ntc.nokia.com", NONCE="MjAwMS0wMS0yMSAxNTowODo1OA==", RESPONSE="d9d7f1ae99a013cb05f319f0f678251d", URI="sip:garage.sr.ntc.nokia.com"
+Via: SIP/2.0/UDP 172.21.9.155
+MIME-Version: 1.0
+Content-Type: text/plain;charset=US-ASCII
+Content-Encoding: identity
+Content-Disposition: render;handling=optional
+Content-Length: 31
+
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
index 7c9e160dffe0464cb75bf803bcca53f971f0a66e..a1f5a5fe018545ebcf33d77be11e666c5d5af687 100644 (file)
@@ -1,27 +1,27 @@
-INVITE sip:bob@[3ffe:1200:3012:c006:206:5bff:fe55:462f] SIP/2.0\r
-Via: SIP/2.0/UDP [3ffe:1200:3012:c000:0030:e0ff:fe40:6297]:5062\r
-     ;branch=z9hG4bKuNCTHs8Lumv\r
-     ;received=3ffe:1200:3012:c006:0030:e0ff:fe40:6297\r
-Via: SIP/2.0/UDP [3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]:5062\r
-     ;branch=z9hG4bKuNCTHs8Lumv\r
-     ;received=[3ffe:1200:3012:c006:210:a4ff:fe8d:6a46]\r
-From: <sip:alice@[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]>\r
-     ;tag=ud6a29947\r
-To: <sip:bob@example.com;maddr=[3ffe:1200:3012:c006:206:5bff:fe55:462f]>\r
-Call-ID: f89fa68e-5109-11d6-0581-0010A48D6A46\r
-CSeq: 2 INVITE\r
-Contact: <sip:[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]:5062>\r
-Call-Info: <http://[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]/alice.gif>\r
-     ;purpose=icon;g-param=[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]\r
-Content-Type: application/sdp\r
-Content-Length: 239\r
-\r
-v=0\r
-o=alice 1804289383 2 IN IP6 3ffe:1200:3012:c000:210:a4ff:fe8d:6a46\r
-s=-\r
-c=IN IP6 3ffe:1200:3012:c000:210:a4ff:fe8d:6a46\r
-t=0 0\r
-m=audio 5004 RTP/AVP 96 97 98\r
-a=rtpmap:96 AMR/8000\r
-a=rtpmap:97 AMR-WB/16000\r
-a=rtpmap:98 GSM-EFR/8000\r
+INVITE sip:bob@[3ffe:1200:3012:c006:206:5bff:fe55:462f] SIP/2.0
+Via: SIP/2.0/UDP [3ffe:1200:3012:c000:0030:e0ff:fe40:6297]:5062
+     ;branch=z9hG4bKuNCTHs8Lumv
+     ;received=3ffe:1200:3012:c006:0030:e0ff:fe40:6297
+Via: SIP/2.0/UDP [3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]:5062
+     ;branch=z9hG4bKuNCTHs8Lumv
+     ;received=[3ffe:1200:3012:c006:210:a4ff:fe8d:6a46]
+From: <sip:alice@[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]>
+     ;tag=ud6a29947
+To: <sip:bob@example.com;maddr=[3ffe:1200:3012:c006:206:5bff:fe55:462f]>
+Call-ID: f89fa68e-5109-11d6-0581-0010A48D6A46
+CSeq: 2 INVITE
+Contact: <sip:[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]:5062>
+Call-Info: <http://[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]/alice.gif>
+     ;purpose=icon;g-param=[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]
+Content-Type: application/sdp
+Content-Length: 239
+
+v=0
+o=alice 1804289383 2 IN IP6 3ffe:1200:3012:c000:210:a4ff:fe8d:6a46
+s=-
+c=IN IP6 3ffe:1200:3012:c000:210:a4ff:fe8d:6a46
+t=0 0
+m=audio 5004 RTP/AVP 96 97 98
+a=rtpmap:96 AMR/8000
+a=rtpmap:97 AMR-WB/16000
+a=rtpmap:98 GSM-EFR/8000
index 78750c6b93411d1d0a8c3012f8986469a9912cae..de5eec558dad4abe92f4e4a4a0ccf3114cb30445 100644 (file)
@@ -1,17 +1,17 @@
-OPTIONS sip:bob@example.com SIP/2.0\r
-Via: SIP/2.0/UDP 172.21.40.44;branch=z9hG4bKitIIzAialKS\r
-Via: SIP/2.0/UDP [3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]:5062\r
-     ;branch=z9hG4bKJv+PsUQdfOb\r
-     ;received=172.21.40.24\r
-Record-Route: <sip:bob@example.com;maddr=172.21.40.44>\r
-Record-Route: <sip:bob@example.com\r
-     ;maddr=[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]>\r
-From: <sip:alice@example.com>;tag=ud6a29947\r
-To: <sip:bob@example.com>\r
-Call-ID: f3359e42-5109-11d6-998d-0010a47e1c0f\r
-CSeq: 1 OPTIONS\r
-Contact: <sip:[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]:5062>\r
-Content-Length: 0\r
-Accept: \r
-Allow: \r
-\r
+OPTIONS sip:bob@example.com SIP/2.0
+Via: SIP/2.0/UDP 172.21.40.44;branch=z9hG4bKitIIzAialKS
+Via: SIP/2.0/UDP [3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]:5062
+     ;branch=z9hG4bKJv+PsUQdfOb
+     ;received=172.21.40.24
+Record-Route: <sip:bob@example.com;maddr=172.21.40.44>
+Record-Route: <sip:bob@example.com
+     ;maddr=[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]>
+From: <sip:alice@example.com>;tag=ud6a29947
+To: <sip:bob@example.com>
+Call-ID: f3359e42-5109-11d6-998d-0010a47e1c0f
+CSeq: 1 OPTIONS
+Contact: <sip:[3ffe:1200:3012:c000:210:a4ff:fe8d:6a46]:5062>
+Content-Length: 0
+Accept: 
+Allow: 
+
index cda44776e6f97ce2bf1347571576fd75fab5420a..ac5af8ae8653b96eea2c53617ae4b0b540540214 100644 (file)
@@ -1,2 +1,2 @@
-JUNK * SIP/1.0\r
+JUNK * SIP/1.0
   
\ No newline at end of file
index ca3fec58258f8434e269c4def21d665df8d9e337..22bf3dabc9f683a22bbadd3eda6a4a25333b5781 100644 (file)
@@ -1,22 +1,22 @@
-INVITE sip:vivekg@chair.dnrc.bell-labs.com SIP/2.0\r
-  To :\r
-  sip:vivekg@chair.dnrc.bell-labs.com ;    tag    = 1a1b1f1H33n\r
-From   : "J Rosenberg \\\"" <sip:jdrosen@lucent.com>\r
-  ;\r
- tag = 98asjd8\r
-CaLl-Id\r
- : 0ha0isndaksdj@10.1.1.1\r
-cseq: 8 INVITE\r
-Via  : SIP   /  2.0/  UDP \r
-  135.180.130.133\r
-Subject :\r
-NewFangledHeader:   newfangled value\r
- more newfangled value\r
-Content-Type: application/sdp\r
-v:  SIP  / 2.0  / TCP     12.3.4.5   ;\r
-  branch  =   9ikj8  ,\r
-  SIP  /    2.0   / UDP  1.2.3.4   ; hidden   \r
-m:"Quoted string \"\"" <sip:jdrosen@bell-labs.com> ; newparam = newvalue ;\r
-  secondparam = secondvalue  ; q = 0.33\r
-  (((nested comments) and (more)))   ,\r
- tel:4443322\r
+INVITE sip:vivekg@chair.dnrc.bell-labs.com SIP/2.0
+  To :
+  sip:vivekg@chair.dnrc.bell-labs.com ;    tag    = 1a1b1f1H33n
+From   : "J Rosenberg \\\"" <sip:jdrosen@lucent.com>
+  ;
+ tag = 98asjd8
+CaLl-Id
+ : 0ha0isndaksdj@10.1.1.1
+cseq: 8 INVITE
+Via  : SIP   /  2.0/  UDP 
+  135.180.130.133
+Subject :
+NewFangledHeader:   newfangled value
+ more newfangled value
+Content-Type: application/sdp
+v:  SIP  / 2.0  / TCP     12.3.4.5   ;
+  branch  =   9ikj8  ,
+  SIP  /    2.0   / UDP  1.2.3.4   ; hidden   
+m:"Quoted string \"\"" <sip:jdrosen@bell-labs.com> ; newparam = newvalue ;
+  secondparam = secondvalue  ; q = 0.33
+  (((nested comments) and (more)))   ,
+ tel:4443322
index b929575afac7f81aef050e255b0893ce19bd0af4..4a302ce5c445644e2d125b7ecf9ffa60fe950011 100644 (file)
@@ -12,7 +12,7 @@ v=0
 o=mhandley 29739 7272939 IN IP4 126.5.4.3
 c=IN IP4 135.180.130.88
 m=audio 492170 RTP/AVP 0 12
-m=video 3227 RTP/AVP 31\r
-s=My sesion\r
+m=video 3227 RTP/AVP 31
+s=My sesion
 t=2873397496 2873404696
 a=rtpmap:31 LPC
index 96efa34689cabaa47228b405f399e117b1e67650..8ff032c137786464b02b21bf993b5dd3ac141a29 100644 (file)
@@ -1,21 +1,21 @@
-INVITE sip:vivekg@chair.dnrc.bell-labs.com SIP/2.0\r
- To :\r
-  sip:vivekg@chair.dnrc.bell-labs.com ;    tag    = 1a1b1f1H33n\r
-From   : "J Rosenberg \\\"" <sip:jdrosen@lucent.com>\r
-  ;\r
- tag = 98asjd8\r
-CaLl-Id\r
- : 0ha0isndaksdj@10.1.1.1\r
-cseq: 8 INVITE\r
-Via  : SIP   /  2.0/  UDP \r
-  135.180.130.133\r
-Subject :\r
-Content-Type: application/sdp\r
-\r
-v:  SIP  / 2.0  / TCP     12.3.4.5   ;\r
-  branch  =   9ikj8  ,\r
-  SIP  /    2.0   / UDP  1.2.3.4   ; hidden   \r
-m:"Quoted string \"\"" <sip:jdrosen@bell-labs.com> ; newparam = newvalue ;\r
-  secondparam = secondvalue  ; q = 0.33\r
-  (((nested comments) and (more)))   ,\r
- tel:4443322\r
+INVITE sip:vivekg@chair.dnrc.bell-labs.com SIP/2.0
+ To :
+  sip:vivekg@chair.dnrc.bell-labs.com ;    tag    = 1a1b1f1H33n
+From   : "J Rosenberg \\\"" <sip:jdrosen@lucent.com>
+  ;
+ tag = 98asjd8
+CaLl-Id
+ : 0ha0isndaksdj@10.1.1.1
+cseq: 8 INVITE
+Via  : SIP   /  2.0/  UDP 
+  135.180.130.133
+Subject :
+Content-Type: application/sdp
+
+v:  SIP  / 2.0  / TCP     12.3.4.5   ;
+  branch  =   9ikj8  ,
+  SIP  /    2.0   / UDP  1.2.3.4   ; hidden   
+m:"Quoted string \"\"" <sip:jdrosen@bell-labs.com> ; newparam = newvalue ;
+  secondparam = secondvalue  ; q = 0.33
+  (((nested comments) and (more)))   ,
+ tel:4443322
index efc389a3f3daaa290a360e0d62f5e04d37536397..82abf35069a1290728075e4a5fc583589f1f0b0d 100644 (file)
@@ -1,17 +1,17 @@
-INVITE <sip:user@company.com> SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:caller@university.edu\r
-Call-ID: 1@10.0.0.1\r
-CSeq: 1 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Content-Type: application/sdp\r
-Content-Length: 163\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-s=SIP Call\r
-t=0 0\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
+INVITE <sip:user@company.com> SIP/2.0
+To: sip:user@company.com
+From: sip:caller@university.edu
+Call-ID: 1@10.0.0.1
+CSeq: 1 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Content-Type: application/sdp
+Content-Length: 163
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+s=SIP Call
+t=0 0
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
index e8e2c4abd5ff928b450fa56d28cdc4f703d02385..ef9fe4694fa81ec491c7b52de0b21c34aa7acd5d 100644 (file)
@@ -1,17 +1,17 @@
-INVITE sip:user@company.com; transport=udp SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:caller@university.edu\r
-Call-ID: 2@10.0.0.1\r
-CSeq: 1 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Content-Type: application/sdp\r
-Content-Length: 163\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-s=SIP Call\r
-t=0 0\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
+INVITE sip:user@company.com; transport=udp SIP/2.0
+To: sip:user@company.com
+From: sip:caller@university.edu
+Call-ID: 2@10.0.0.1
+CSeq: 1 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Content-Type: application/sdp
+Content-Length: 163
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+s=SIP Call
+t=0 0
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
index 1f3632fa600f4edb3798ca3a7108d2f7da10e2cf..f119d1f023fd1911d385f879d1e78813d50e6499 100644 (file)
@@ -1,17 +1,17 @@
-INVITE sip:user@company.com  SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:caller@university.edu\r
-Call-ID: 3@10.0.0.1\r
-CSeq: 1 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Content-Type: application/sdp\r
-Content-Length: 163\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-s=SIP Call\r
-t=0 0\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
+INVITE sip:user@company.com  SIP/2.0
+To: sip:user@company.com
+From: sip:caller@university.edu
+Call-ID: 3@10.0.0.1
+CSeq: 1 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Content-Type: application/sdp
+Content-Length: 163
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+s=SIP Call
+t=0 0
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
index 29033f6071ce71028b11085daf49335eef0a08ab..12244cce6ba4b0e09b05f948a0b20f3bf91736c0 100644 (file)
@@ -1,17 +1,17 @@
-INVITE sip:sip%3Auser%40example.com@company.com;other-param=summit SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:caller@university.edu\r
-Call-ID: 4@10.0.0.1\r
-CSeq: 1 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Content-Type: application/sdp\r
-Content-Length: 163\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-s=SIP Call\r
-t=0 0\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
+INVITE sip:sip%3Auser%40example.com@company.com;other-param=summit SIP/2.0
+To: sip:user@company.com
+From: sip:caller@university.edu
+Call-ID: 4@10.0.0.1
+CSeq: 1 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Content-Type: application/sdp
+Content-Length: 163
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+s=SIP Call
+t=0 0
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
index 26eacb8cee7ad1db6c69607555a4df60cb9b5cbd..6f80e96c1a4852011f5cfa6c4bce574c02874537 100644 (file)
@@ -1,17 +1,17 @@
-INVITE sip:user@company.com?Route=%3Csip:sip.example.com%3E SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:caller@university.edu\r
-Call-ID: 5@10.0.0.1\r
-CSeq: 1 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Content-Type: application/sdp\r
-Content-Length: 163\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-s=SIP Call\r
-t=0 0\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
+INVITE sip:user@company.com?Route=%3Csip:sip.example.com%3E SIP/2.0
+To: sip:user@company.com
+From: sip:caller@university.edu
+Call-ID: 5@10.0.0.1
+CSeq: 1 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Content-Type: application/sdp
+Content-Length: 163
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+s=SIP Call
+t=0 0
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
index 214b47c42c7776252b91fb0ff6a912df459a31e6..aeaa09770fa311fa3fc9d33569009e700cc5705a 100644 (file)
@@ -1,17 +1,17 @@
-INVITE name:user SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:caller@university.edu\r
-Call-ID: 6@10.0.0.1\r
-CSeq: 1 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Content-Type: application/sdp\r
-Content-Length: 163\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-s=SIP Call\r
-t=0 0\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
+INVITE name:user SIP/2.0
+To: sip:user@company.com
+From: sip:caller@university.edu
+Call-ID: 6@10.0.0.1
+CSeq: 1 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Content-Type: application/sdp
+Content-Length: 163
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+s=SIP Call
+t=0 0
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
index f4624a8c4324735aa484dd4dbf8d1f1c9a6ea761..fecca76d279d225554b30e0e22045eff208d71ae 100644 (file)
@@ -1,8 +1,8 @@
-OPTIONS sip:user@company.com SIP/2.0\r
-To: sip:user@company.com\r
-From: "caller"<sip:caller@example.com>\r
-Call-ID: 1234abcd@10.0.0.1\r
-CSeq: 1 OPTIONS\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-\r
-\r
+OPTIONS sip:user@company.com SIP/2.0
+To: sip:user@company.com
+From: "caller"<sip:caller@example.com>
+Call-ID: 1234abcd@10.0.0.1
+CSeq: 1 OPTIONS
+Via: SIP/2.0/UDP 135.180.130.133
+
+
index 24b4cb423119302c7046e79620e3794cb0e0d3c2..7709777e92792296ab758c69dd82160805038da7 100644 (file)
@@ -1,8 +1,8 @@
-OPTIONS sip:user@company.com SIP/2.0\r
-To: sip:user@company.com\r
-From: "caller"    <sip:caller@example.com>\r
-Call-ID: 1234abcd@10.0.0.1\r
-CSeq: 2 OPTIONS\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-\r
-\r
+OPTIONS sip:user@company.com SIP/2.0
+To: sip:user@company.com
+From: "caller"    <sip:caller@example.com>
+Call-ID: 1234abcd@10.0.0.1
+CSeq: 2 OPTIONS
+Via: SIP/2.0/UDP 135.180.130.133
+
+
index 3e740ceeb66feedf9d33eb8d861bc12a89dee873..50b62ad8fadb6f31a51661f3631af12547d28b9c 100644 (file)
@@ -1,18 +1,18 @@
-INVITE sip:user@company.com SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:caller@university.edu\r
-Call-ID: 7@10.0.0.1\r
-CSeq: 1 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Expires: Fri, 01 Jan 2010 16:00:00 EST\r
-Content-Type: application/sdp\r
-Content-Length: 163\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-s=SIP Call\r
-t=0 0\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
+INVITE sip:user@company.com SIP/2.0
+To: sip:user@company.com
+From: sip:caller@university.edu
+Call-ID: 7@10.0.0.1
+CSeq: 1 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Expires: Fri, 01 Jan 2010 16:00:00 EST
+Content-Type: application/sdp
+Content-Length: 163
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+s=SIP Call
+t=0 0
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
index 84fbd9450c157631739c8e06d5547c40290f0aa1..384d5dd8164a283998f079f2b8f8465d44c85ee5 100644 (file)
@@ -1,12 +1,12 @@
-INVITE sip:John_Smith@tct.hut.fi SIP/2.0\r
-To: isbn:2983792873\r
-From: http://www.cs.columbia.edu\r
-Call-ID: 0ha0isndaksdj@10.1.2.3\r
-CSeq : 8 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Content-Type: application/sdp\r
-Contact: Joe Bob Briggs <urn:ipaddr:122.1.2.3>\r
-Content-Length: 138\r
+INVITE sip:John_Smith@tct.hut.fi SIP/2.0
+To: isbn:2983792873
+From: http://www.cs.columbia.edu
+Call-ID: 0ha0isndaksdj@10.1.2.3
+CSeq : 8 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Content-Type: application/sdp
+Contact: Joe Bob Briggs <urn:ipaddr:122.1.2.3>
+Content-Length: 138
 
 v=0
 o=mhandley 29739 7272939 IN IP4 126.5.4.3
index d27479408a071bd6b5c512548713a5613b7074c0..df007b2b170873787b5c6e4052b44f57c4ecebc4 100644 (file)
@@ -1,18 +1,18 @@
-INVITE sip:user@company.com SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:caller@university.edu\r
-Call-ID: 8@10.0.0.1\r
-CSeq: 1 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Expires: Thu, 01 Dec 1994 16:00:00 GMT\r
-Content-Type: application/sdp\r
-Content-Length: 163\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-s=SIP Call\r
-t=0 0\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
+INVITE sip:user@company.com SIP/2.0
+To: sip:user@company.com
+From: sip:caller@university.edu
+Call-ID: 8@10.0.0.1
+CSeq: 1 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Expires: Thu, 01 Dec 1994 16:00:00 GMT
+Content-Type: application/sdp
+Content-Length: 163
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+s=SIP Call
+t=0 0
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
index 65095ca93ef75cdc394c0b0c6ebb8ba7dfd6368f..ee5413d60115107c91b2f35a3c5352f90ba41d50 100644 (file)
@@ -1,18 +1,18 @@
-INVITE sip:user@company.com SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:caller@university.edu\r
-Call-ID: 9@10.0.0.1\r
-CSeq: 1 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Max-Forwards: 0\r
-Content-Type: application/sdp\r
-Content-Length: 163\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-s=SIP Call\r
-t=0 0\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
+INVITE sip:user@company.com SIP/2.0
+To: sip:user@company.com
+From: sip:caller@university.edu
+Call-ID: 9@10.0.0.1
+CSeq: 1 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Max-Forwards: 0
+Content-Type: application/sdp
+Content-Length: 163
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+s=SIP Call
+t=0 0
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
index c06b71b6b98e9003299c195459b665f5d016bdd8..d3e4a1f8cbdf6c2971925c8abf5fd5c946055c0a 100644 (file)
@@ -1,10 +1,10 @@
-REGISTER sip:company.com SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:user@company.com\r
-Contact: sip:user@host.company.com\r
-Call-ID: k345asrl3fdbv@10.0.0.1\r
-CSeq: 1 REGISTER\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Contact: <sip:user@example.com?Route=%3Csip:sip.example.com%3E>\r
-\r
-\r
+REGISTER sip:company.com SIP/2.0
+To: sip:user@company.com
+From: sip:user@company.com
+Contact: sip:user@host.company.com
+Call-ID: k345asrl3fdbv@10.0.0.1
+CSeq: 1 REGISTER
+Via: SIP/2.0/UDP 135.180.130.133
+Contact: <sip:user@example.com?Route=%3Csip:sip.example.com%3E>
+
+
index 6168d76aae3b03120c6ebb6b4083eaa8624b9bd6..be0ea6a68f0b2c9eb22aa92e93983800e48bb26b 100644 (file)
@@ -1,10 +1,10 @@
-REGISTER sip:company.com SIP/2.0\r
-To: sip:user@company.com\r
-From: sip:user@company.com\r
-Contact: sip:user@host.company.com\r
-Call-ID: k345asrl3fdbv@10.0.0.1\r
-CSeq: 1 REGISTER\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Contact: sip:user@example.com?Route=%3Csip:sip.example.com%3E\r
-\r
-\r
+REGISTER sip:company.com SIP/2.0
+To: sip:user@company.com
+From: sip:user@company.com
+Contact: sip:user@host.company.com
+Call-ID: k345asrl3fdbv@10.0.0.1
+CSeq: 1 REGISTER
+Via: SIP/2.0/UDP 135.180.130.133
+Contact: sip:user@example.com?Route=%3Csip:sip.example.com%3E
+
+
index 087df160da8cced48c24c9a0e47e870e632a3067..4c2af44a860aa38cb409ab6c1b6df42cd25d7322 100644 (file)
@@ -1,52 +1,52 @@
-INVITE sip:user@company.com SIP/2.0\r
-To: "I have a user name of extreme proportion" <sip:user@company.com:6000;other-param=1234567890somethingelselong1234567890>\r
-From: sip:caller@university.edu\r
-Call-ID: kl24ahsd546folnyt2vbak9sad98u23naodiunzds09a3bqw0sdfbsk34poouymnae0043nsed09mfkvc74bd0cuwnms05dknw87hjpobd76f\r
-CSeq: 1 INVITE\r
-My-State: sldkjflzdsfaret0803adgaasd0afds0asdaasd\r
-Via: SIP/2.0/UDP sip33.example.com\r
-Via: SIP/2.0/UDP sip32.example.com\r
-Via: SIP/2.0/UDP sip31.example.com\r
-Via: SIP/2.0/UDP sip30.example.com\r
-Via: SIP/2.0/UDP sip29.example.com\r
-Via: SIP/2.0/UDP sip28.example.com\r
-Via: SIP/2.0/UDP sip27.example.com\r
-Via: SIP/2.0/UDP sip26.example.com\r
-Via: SIP/2.0/UDP sip25.example.com\r
-Via: SIP/2.0/UDP sip24.example.com\r
-Via: SIP/2.0/UDP sip23.example.com\r
-Via: SIP/2.0/UDP sip22.example.com\r
-Via: SIP/2.0/UDP sip21.example.com\r
-Via: SIP/2.0/UDP sip20.example.com\r
-Via: SIP/2.0/UDP sip19.example.com\r
-Via: SIP/2.0/UDP sip18.example.com\r
-Via: SIP/2.0/UDP sip17.example.com\r
-Via: SIP/2.0/UDP sip16.example.com\r
-Via: SIP/2.0/UDP sip15.example.com\r
-Via: SIP/2.0/UDP sip14.example.com\r
-Via: SIP/2.0/UDP sip13.example.com\r
-Via: SIP/2.0/UDP sip12.example.com\r
-Via: SIP/2.0/UDP sip11.example.com\r
-Via: SIP/2.0/UDP sip10.example.com\r
-Via: SIP/2.0/UDP sip9.example.com\r
-Via: SIP/2.0/UDP sip8.example.com\r
-Via: SIP/2.0/UDP sip7.example.com\r
-Via: SIP/2.0/UDP sip6.example.com\r
-Via: SIP/2.0/UDP sip5.example.com\r
-Via: SIP/2.0/UDP sip4.example.com\r
-Via: SIP/2.0/UDP sip3.example.com\r
-Via: SIP/2.0/UDP sip2.example.com\r
-Via: SIP/2.0/UDP sip1.example.com\r
-Via: SIP/2.0/UDP host.example.com;received=135.180.130.133;branch=C1C3344E2710000000E299E568E7potato10potato0potato0\r
-Content-Type: application/sdp\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-s=SIP Call\r
-t=3149328700 0\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
-\r
-\r
+INVITE sip:user@company.com SIP/2.0
+To: "I have a user name of extreme proportion" <sip:user@company.com:6000;other-param=1234567890somethingelselong1234567890>
+From: sip:caller@university.edu
+Call-ID: kl24ahsd546folnyt2vbak9sad98u23naodiunzds09a3bqw0sdfbsk34poouymnae0043nsed09mfkvc74bd0cuwnms05dknw87hjpobd76f
+CSeq: 1 INVITE
+My-State: sldkjflzdsfaret0803adgaasd0afds0asdaasd
+Via: SIP/2.0/UDP sip33.example.com
+Via: SIP/2.0/UDP sip32.example.com
+Via: SIP/2.0/UDP sip31.example.com
+Via: SIP/2.0/UDP sip30.example.com
+Via: SIP/2.0/UDP sip29.example.com
+Via: SIP/2.0/UDP sip28.example.com
+Via: SIP/2.0/UDP sip27.example.com
+Via: SIP/2.0/UDP sip26.example.com
+Via: SIP/2.0/UDP sip25.example.com
+Via: SIP/2.0/UDP sip24.example.com
+Via: SIP/2.0/UDP sip23.example.com
+Via: SIP/2.0/UDP sip22.example.com
+Via: SIP/2.0/UDP sip21.example.com
+Via: SIP/2.0/UDP sip20.example.com
+Via: SIP/2.0/UDP sip19.example.com
+Via: SIP/2.0/UDP sip18.example.com
+Via: SIP/2.0/UDP sip17.example.com
+Via: SIP/2.0/UDP sip16.example.com
+Via: SIP/2.0/UDP sip15.example.com
+Via: SIP/2.0/UDP sip14.example.com
+Via: SIP/2.0/UDP sip13.example.com
+Via: SIP/2.0/UDP sip12.example.com
+Via: SIP/2.0/UDP sip11.example.com
+Via: SIP/2.0/UDP sip10.example.com
+Via: SIP/2.0/UDP sip9.example.com
+Via: SIP/2.0/UDP sip8.example.com
+Via: SIP/2.0/UDP sip7.example.com
+Via: SIP/2.0/UDP sip6.example.com
+Via: SIP/2.0/UDP sip5.example.com
+Via: SIP/2.0/UDP sip4.example.com
+Via: SIP/2.0/UDP sip3.example.com
+Via: SIP/2.0/UDP sip2.example.com
+Via: SIP/2.0/UDP sip1.example.com
+Via: SIP/2.0/UDP host.example.com;received=135.180.130.133;branch=C1C3344E2710000000E299E568E7potato10potato0potato0
+Content-Type: application/sdp
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+s=SIP Call
+t=3149328700 0
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
+
+
index bbc6b3ad9a0674bfa6724014b67f89c35a939181..ff3c07dde0265911e67fadf2055ef1fd98851e2c 100644 (file)
@@ -1,16 +1,16 @@
-OPTIONS sip:135.180.130.133 SIP/2.0\r
-Via: SIP/2.0/UDP company.com:5604\r
-From: sip:iuser@company.com\r
-To: sip:user@135.180.130.133\r
-Call-ID: 1804928587@company.com\r
-CSeq: 1 OPTIONS\r
-Expires: 0 0l@company.com\r
-To: sip:user@135.180.130.133\r
-Call-ID: 1804928587@company.com\r
-CSeq: 1 OPTIONS\r
-Contact: sip:host.company.com\r
-Expires: 0xpires: 0sip:host.company.com\r
-Expires: 0\r
-Contact: sip:host.company.com\r
-\r
-\r
+OPTIONS sip:135.180.130.133 SIP/2.0
+Via: SIP/2.0/UDP company.com:5604
+From: sip:iuser@company.com
+To: sip:user@135.180.130.133
+Call-ID: 1804928587@company.com
+CSeq: 1 OPTIONS
+Expires: 0 0l@company.com
+To: sip:user@135.180.130.133
+Call-ID: 1804928587@company.com
+CSeq: 1 OPTIONS
+Contact: sip:host.company.com
+Expires: 0xpires: 0sip:host.company.com
+Expires: 0
+Contact: sip:host.company.com
+
+
index a5f13a242f2665770de566a1839a5878ef8a410d..34c63f84b2c483958fee372f224e9ad7e7df4527 100644 (file)
@@ -1,23 +1,23 @@
-INVITE sip:+1-972-555-2222;phone-context=name%40domain;new=user?%22Route%3a%20X%40Y%3bZ=W%22@gw1.wcom.com;user=phone SIP/2.0\r
-Via: SIP/2.0/UDP iftgw.there.com:5060\r
-From: sip:+1-303-555-1111@ift.here.com;user=phone\r
-To: sip:+1-650-555-2222@ss1.wcom.com;user=phone\r
-Call-ID: 1717@ift.here.com\r
-CSeq: 56 INVITE\r
-Content-Type: application/sdp\r
-Content-Length: 348\r
-\r
-v=0\r
-o=faxgw1 2890844527 2890844527 IN IP4 iftgw.there.com\r
-s=Session SDP\r
-c=IN IP4 iftmg.there.com\r
-t=0 0\r
-m=image 49172 udptl t38\r
-a=T38FaxVersion:0\r
-a=T38maxBitRate:14400\r
-a=T38FaxFillBitRemoval:0\r
-a=T38FaxTranscodingMMR:0\r
-a=T38FaxTranscodingJBIG:0\r
-a=T38FaxRateManagement:transferredTCF\r
-a=T38FaxMaxBuffer:260\r
-a=T38FaxUdpEC:t38UDPRedundancy\r
+INVITE sip:+1-972-555-2222;phone-context=name%40domain;new=user?%22Route%3a%20X%40Y%3bZ=W%22@gw1.wcom.com;user=phone SIP/2.0
+Via: SIP/2.0/UDP iftgw.there.com:5060
+From: sip:+1-303-555-1111@ift.here.com;user=phone
+To: sip:+1-650-555-2222@ss1.wcom.com;user=phone
+Call-ID: 1717@ift.here.com
+CSeq: 56 INVITE
+Content-Type: application/sdp
+Content-Length: 348
+
+v=0
+o=faxgw1 2890844527 2890844527 IN IP4 iftgw.there.com
+s=Session SDP
+c=IN IP4 iftmg.there.com
+t=0 0
+m=image 49172 udptl t38
+a=T38FaxVersion:0
+a=T38maxBitRate:14400
+a=T38FaxFillBitRemoval:0
+a=T38FaxTranscodingMMR:0
+a=T38FaxTranscodingJBIG:0
+a=T38FaxRateManagement:transferredTCF
+a=T38FaxMaxBuffer:260
+a=T38FaxUdpEC:t38UDPRedundancy
index 70f69fc03720b6ad304fa1d1e29e3d4a5e81b246..821e4004a0c9f0cd442b37c176fd2d3928b816ef 100644 (file)
@@ -1,9 +1,9 @@
-REGISTER sip:bell-tel.com SIP/2.0\r
-Via: SIP/2.0/UDP saturn.bell-tel.com\r
-From: sip:watson@bell-tel.com\r
-To: sip:watson@bell-tel.com\r
-Call-ID: 70710@saturn.bell-tel.com\r
-CSeq: 2 REGISTER\r
-Contact: sip:+1-972-555-2222@gw1.wcom.com;user=phone\r
-\r
-\r
+REGISTER sip:bell-tel.com SIP/2.0
+Via: SIP/2.0/UDP saturn.bell-tel.com
+From: sip:watson@bell-tel.com
+To: sip:watson@bell-tel.com
+Call-ID: 70710@saturn.bell-tel.com
+CSeq: 2 REGISTER
+Contact: sip:+1-972-555-2222@gw1.wcom.com;user=phone
+
+
index a15705bf4d0d8077413f5b6f16f25f70ce8daaaa..b80c18f507f1dbd68e250ba5f53a20334af45b79 100644 (file)
@@ -1,9 +1,9 @@
-REGISTER sip:bell-tel.com SIP/2.0\r
-Via: SIP/2.0/UDP saturn.bell-tel.com\r
-From: sip:watson@bell-tel.com\r
-To: sip:watson@bell-tel.com\r
-Call-ID: 70710@saturn.bell-tel.com\r
-CSeq: 3 REGISTER\r
-Contact: <sip:+1-972-555-2222@gw1.wcom.com;user=phone>\r
-\r
-\r
+REGISTER sip:bell-tel.com SIP/2.0
+Via: SIP/2.0/UDP saturn.bell-tel.com
+From: sip:watson@bell-tel.com
+To: sip:watson@bell-tel.com
+Call-ID: 70710@saturn.bell-tel.com
+CSeq: 3 REGISTER
+Contact: <sip:+1-972-555-2222@gw1.wcom.com;user=phone>
+
+
index 882c6690a59a59eab75884f60103866bfde17aca..3214684f0e5ff336b1dd43e4314ce5115c197ea5 100644 (file)
@@ -1,8 +1,8 @@
-INVITE sip:t.watson@ieee.org SIP/2.0\r
-Via:     SIP/2.0/UDP c.bell-tel.com\r
-From:    A. Bell <sip:a.g.bell@bell-tel.com>\r
-To:      T. Watson <sip:t.watson@ieee.org>\r
-Call-ID: 31414@c.bell-tel.com\r
-CSeq:    1 INVITE\r
-\r
-\r
+INVITE sip:t.watson@ieee.org SIP/2.0
+Via:     SIP/2.0/UDP c.bell-tel.com
+From:    A. Bell <sip:a.g.bell@bell-tel.com>
+To:      T. Watson <sip:t.watson@ieee.org>
+Call-ID: 31414@c.bell-tel.com
+CSeq:    1 INVITE
+
+
index 08ddecc21ffd2a5bc4cd85491236d06ebd5e894f..7a8d0ecda60d8abba529fa74fcdac9b5bab3220e 100644 (file)
@@ -1,8 +1,8 @@
-INVITE sip:t.watson@ieee.org SIP/2.0\r
-Via:     SIP/2.0/UDP c.bell-tel.com\r
-From:    Bell, Alexander <sip:a.g.bell@bell-tel.com>\r
-To:      Watson, Thomas <sip:t.watson@ieee.org>\r
-Call-ID: 31415@c.bell-tel.com\r
-CSeq:    1 INVITE\r
-\r
-\r
+INVITE sip:t.watson@ieee.org SIP/2.0
+Via:     SIP/2.0/UDP c.bell-tel.com
+From:    Bell, Alexander <sip:a.g.bell@bell-tel.com>
+To:      Watson, Thomas <sip:t.watson@ieee.org>
+Call-ID: 31415@c.bell-tel.com
+CSeq:    1 INVITE
+
+
index a9f9f17e16db497c93c4c654d7feafb227ec1d16..c54c9933fe1d839a4158d4f2ac7c2a9e3256e65c 100644 (file)
@@ -1,8 +1,8 @@
-INVITE sip:t.watson@ieee.org SIP/7.0\r
-Max-Forwards:     70\r
-Via:     SIP/2.0/UDP c.bell-tel.com\r
-From:    A. Bell <sip:a.g.bell@bell-tel.com>\r
-To:      T. Watson <sip:t.watson@ieee.org>\r
-Call-ID: 31416@c.bell-tel.com\r
-CSeq:    1 INVITE\r
-\r
+INVITE sip:t.watson@ieee.org SIP/7.0
+Max-Forwards:     70
+Via:     SIP/2.0/UDP c.bell-tel.com
+From:    A. Bell <sip:a.g.bell@bell-tel.com>
+To:      T. Watson <sip:t.watson@ieee.org>
+Call-ID: 31416@c.bell-tel.com
+CSeq:    1 INVITE
+
index d6bd86cbc720c5ed77a6ef8482f232b18ff69860..5aa080b046d8b2298c0784b7e3c34e7faa3753e9 100644 (file)
@@ -1,11 +1,11 @@
-INVITE sip:t.watson@ieee.org SIP/7.0\r
-Via:     SIP/2.0/UDP c.bell-tel.com\r
-From:    A. Bell <sip:a.g.bell@bell-tel.com>\r
-To:      T. Watson <sip:t.watson@ieee.org>\r
-Call-ID: 31417@c.bell-tel.com\r
-CSeq:    1 INVITE\r
-\r
-\r
-\r
-\r
-\r
+INVITE sip:t.watson@ieee.org SIP/7.0
+Via:     SIP/2.0/UDP c.bell-tel.com
+From:    A. Bell <sip:a.g.bell@bell-tel.com>
+To:      T. Watson <sip:t.watson@ieee.org>
+Call-ID: 31417@c.bell-tel.com
+CSeq:    1 INVITE
+
+
+
+
+
index 32dd234c9c40907720160786b7ae55110ebc1e83..bd957cbfeb4f1328e3e68186d1a9eeb282d4fa37 100644 (file)
@@ -1,16 +1,16 @@
-INVITE sip:user@company.com SIP/2.0\r
-To: sip:j_user@company.com\r
-From: sip:caller@university.edu\r
-Call-ID: 0ha0isndaksdj@10.0.0.1\r
-Accept: text/newformat\r
-CSeq: 8 INVITE\r
-Via: SIP/2.0/UDP 135.180.130.133\r
-Content-Type: application/sdp\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-c=IN IP4 135.180.130.88/127\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-b=CT:3455\r
-a=rtpmap:31 LPC\r
+INVITE sip:user@company.com SIP/2.0
+To: sip:j_user@company.com
+From: sip:caller@university.edu
+Call-ID: 0ha0isndaksdj@10.0.0.1
+Accept: text/newformat
+CSeq: 8 INVITE
+Via: SIP/2.0/UDP 135.180.130.133
+Content-Type: application/sdp
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+c=IN IP4 135.180.130.88/127
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+b=CT:3455
+a=rtpmap:31 LPC
index 881cb11792c0efc02a8f0ea286638c5b97b974e2..2c54bdf02f9f6220a1b5530adbc8dcbce5c9e82b 100644 (file)
@@ -1,15 +1,15 @@
-NEWMETHOD sip:user@comapny.com SIP/2.0\r
-To: sip:j.user@company.com\r
-From: sip:caller@university.edu;tag=34525\r
-Max-Forwards: 6\r
-Call-ID: 0ha0isndaksdj@10.0.1.1\r
-CSeq: 8 NEWMETHOD\r
-Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r
-Content-Type: application/sdp\r
-\r
-v=0\r
-o=mhandley 29739 7272939 IN IP4 126.5.4.3\r
-c=IN IP4 135.180.130.88\r
-m=audio 492170 RTP/AVP 0 12\r
-m=video 3227 RTP/AVP 31\r
-a=rtpmap:31 LPC\r
+NEWMETHOD sip:user@comapny.com SIP/2.0
+To: sip:j.user@company.com
+From: sip:caller@university.edu;tag=34525
+Max-Forwards: 6
+Call-ID: 0ha0isndaksdj@10.0.1.1
+CSeq: 8 NEWMETHOD
+Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw
+Content-Type: application/sdp
+
+v=0
+o=mhandley 29739 7272939 IN IP4 126.5.4.3
+c=IN IP4 135.180.130.88
+m=audio 492170 RTP/AVP 0 12
+m=video 3227 RTP/AVP 31
+a=rtpmap:31 LPC
index 223f7cf018f6dca71fc672ba258edca505cbc417..6396278ef7d09fb5ad5555ec03ea3e9bac0466df 100644 (file)
@@ -67,7 +67,7 @@ SOFIAPUBFUN int su_seterrno(int);
 
 #if defined(_WIN32)
 /* VS 2010 defines these for POSIX but we cant have that */
-#if (_MSC_VER > 1500)\r
+#if (_MSC_VER > 1500)
 #undef EWOULDBLOCK
 #undef EINPROGRESS
 #undef EALREADY
index 4647b0fd1abb87b92ffc4ebb257b3ff7105a2c38..6e9fe1c03bdaf1717a0b8d9548c816d3fd12fc36 100644 (file)
-/* config.h.in.  Template for Open C  */\r
-\r
-/* Define to 1 if using `alloca.c'. */\r
-/* #undef C_ALLOCA */\r
-\r
-/* Define to the random number source name. */\r
-/* #undef DEV_URANDOM */\r
-\r
-/* Define to 1 if you have addrinfo structure. */\r
-#define HAVE_ADDRINFO 1\r
-\r
-/* Define to 1 if you have the `alarm' function. */\r
-/* #undef HAVE_ALARM */\r
-\r
-/* Define to 1 if you have `alloca', as a function or macro. */\r
-/* #undef HAVE_ALLOCA */\r
-\r
-/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).\r
-   */\r
-/* #undef HAVE_ALLOCA_H 1 */\r
-\r
-/* Define to 1 if you have the <arpa/inet.h> header file. */\r
-#define HAVE_ARPA_INET_H 1\r
-\r
-/* Define to 1 if you have the `clock_getcpuclockid' function. */\r
-/* #undef HAVE_CLOCK_GETCPUCLOCKID */\r
-\r
-/* Define to 1 if you have the `clock_gettime' function. */\r
-/* #undef HAVE_CLOCK_GETTIME */\r
-\r
-/* Define to 1 if you have /dev/urandom. */\r
-/* #undef HAVE_DEV_URANDOM */\r
-\r
-/* Define to 1 if you have the <dirent.h> header file. */\r
-#define HAVE_DIRENT_H 1\r
-\r
-/* Define to 1 if you have the <dlfcn.h> header file. */\r
-#define HAVE_DLFCN_H 1\r
-\r
-/* Define to 1 if you have epoll interface. */\r
-/* #undef HAVE_EPOLL */\r
-\r
-/* Define to 1 if you have the `epoll_create' function. */\r
-/* #undef HAVE_EPOLL_CREATE */\r
-\r
-/* Define to 1 if you have the <fcntl.h> header file. */\r
-#define HAVE_FCNTL_H 1\r
-\r
-/* Define to 1 if you have WIN32 FILETIME type and GetSystemTimeAsFileTime().\r
-   */\r
-/* #undef HAVE_FILETIME */\r
-\r
-/* Define to 1 if you have the `flock' function. */\r
-/* #undef HAVE_FLOCK */\r
-\r
-/* Define to 1 if you have the `freeaddrinfo' function. */\r
-#define HAVE_FREEADDRINFO 1\r
-\r
-/* Define to 1 if the C compiler supports __func__ */\r
-#define HAVE_FUNC 1\r
-\r
-/* Define to 1 if the C compiler supports __FUNCTION__ */\r
-#define HAVE_FUNCTION 1\r
-\r
-/* Define to 1 if you have the `gai_strerror' function. */\r
-#define HAVE_GAI_STRERROR 1\r
-\r
-/* Define to 1 if you have the `getaddrinfo' function. */\r
-#define HAVE_GETADDRINFO 1\r
-\r
-/* Define to 1 if you have the `getdelim' function. */\r
-/* #undef HAVE_GETDELIM */\r
-\r
-/* Define to 1 if you have the `gethostbyname' function. */\r
-#define HAVE_GETHOSTBYNAME 1\r
-\r
-/* Define to 1 if you have the `gethostname' function. */\r
-#define HAVE_GETHOSTNAME 1\r
-\r
-/* Define to 1 if you have the `getifaddrs' function. */\r
-/* #undef HAVE_GETIFADDRS 1 */\r
-\r
-/* Define to 1 if you have the `getipnodebyname' function. */\r
-#define HAVE_GETIPNODEBYNAME 1\r
-\r
-/* Define to 1 if you have the `getline' function. */\r
-/* #undef HAVE_GETLINE */\r
-\r
-/* Define to 1 if you have the `getnameinfo' function. */\r
-#define HAVE_GETNAMEINFO 1\r
-\r
-/* Define to 1 if you have the `getpass' function. */\r
-#define HAVE_GETPASS 1\r
-\r
-/* Define to 1 if you have the `gettimeofday' function. */\r
-#define HAVE_GETTIMEOFDAY 1\r
-\r
-/* Define to 1 if you have the <ifaddr.h> header file. */\r
-/* #undef HAVE_IFADDR_H */\r
-\r
-/* Define to 1 if you have SIOCGIFCONF */\r
-#define HAVE_IFCONF 1\r
-\r
-/* Define to 1 if you have SIOCGIFNUM ioctl */\r
-/* #undef HAVE_IFNUM */\r
-\r
-/* Define to 1 if you have ifr_ifindex in <net/if.h> */\r
-/* #undef HAVE_IFR_IFINDEX */\r
-\r
-/* Define to 1 if you have ifr_index in <net/if.h> */\r
-#define HAVE_IFR_INDEX 1\r
-\r
-/* Define to 1 if you have the `if_nameindex' function. */\r
-#define HAVE_IF_NAMEINDEX 1\r
-\r
-/* Define to 1 if you have the `inet_ntop' function. */\r
-#define HAVE_INET_NTOP 1\r
-\r
-/* Define to 1 if you have the `inet_pton' function. */\r
-#define HAVE_INET_PTON 1\r
-\r
-/* Define to 1 if you have the `initstate' function. */\r
-#define HAVE_INITSTATE 1\r
-\r
-/* Define to 1 if you have inlining compiler */\r
-#define HAVE_INLINE 1\r
-\r
-/* Define to 1 if you have WIN32 INTERFACE_INFO_EX type. */\r
-/* #undef HAVE_INTERFACE_INFO_EX */\r
-\r
-/* Define to 1 if you have the <inttypes.h> header file. */\r
-#define HAVE_INTTYPES_H 1\r
-\r
-/* Define to 1 if you have the <iphlpapi.h> header file. */\r
-/* #undef HAVE_IPHLPAPI_H */\r
-\r
-/* Define to 1 if you have IPV6_RECVERR in <netinet/in6.h> */\r
-/* #undef HAVE_IPV6_RECVERR */\r
-\r
-/* Define to 1 if you have IP_RECVERR in <netinet/in.h> */\r
-/* #undef HAVE_IP_RECVERR */\r
-\r
-/* Define to 1 if you have the `kqueue' function. */\r
-/* #undef HAVE_KQUEUE 1 */\r
-\r
-/* Define to 1 if you use kqueue in su_port. */\r
-/* #undef HAVE_KQUEUE_PORT 1 */\r
-\r
-/* Define to 1 if you have the `crypto' library (-lcrypto). */\r
-#define HAVE_LIBCRYPTO 1\r
-\r
-/* Define to 1 if you have the `pthread' library (-lpthread). */\r
-#define HAVE_LIBPTHREAD 1\r
-\r
-/* Define to 1 if you have the `socket' library (-lsocket). */\r
-/* #undef HAVE_LIBSOCKET */\r
-\r
-/* Define to 1 if you have the `ssl' library (-lssl). */\r
-#define HAVE_LIBSSL 1\r
-\r
-/* Define to 1 if you have the `memccpy' function. */\r
-#define HAVE_MEMCCPY 1\r
-\r
-/* Define to 1 if you have the `memcspn' function. */\r
-/* #undef HAVE_MEMCSPN */\r
-\r
-/* Define to 1 if you have the `memmem' function. */\r
-/* #undef HAVE_MEMMEM */\r
-\r
-/* Define to 1 if you have the <memory.h> header file. */\r
-#define HAVE_MEMORY_H 1\r
-\r
-/* Define to 1 if you have the `memspn' function. */\r
-/* #undef HAVE_MEMSPN */\r
-\r
-/* Define to 1 if you are compiling in MinGW environment */\r
-/* #undef HAVE_MINGW */\r
-\r
-/* Define to 1 if you have MSG_TRUNC flag */\r
-#define HAVE_MSG_TRUNC 1\r
-\r
-/* Define to 1 if you have the <netdb.h> header file. */\r
-#define HAVE_NETDB_H 1\r
-\r
-/* Define to 1 if you have the <netinet/in.h> header file. */\r
-#define HAVE_NETINET_IN_H 1\r
-\r
-/* Define to 1 if you have the <netinet/sctp.h> header file. */\r
-/* #undef HAVE_NETINET_SCTP_H */\r
-\r
-/* Define to 1 if you have the <netinet/tcp.h> header file. */\r
-/* #undef HAVE_NETINET_TCP_H */\r
-\r
-/* Define to 1 if you have the <netpacket/packet.h> header file. */\r
-/* #undef HAVE_NETPACKET_PACKET_H */\r
-\r
-/* Define to 1 if you have the <net/if.h> header file. */\r
-#define HAVE_NET_IF_H 1\r
-\r
-/* Define to 1 if you have the <net/if_types.h> header file. */\r
-/* #undef HAVE_NET_IF_TYPES_H 1 */\r
-\r
-/* Define to 1 if you have OpenSSL */\r
-#define HAVE_OPENSSL 1\r
-\r
-/* Define to 1 if you have the <openssl/tls1.h> header file. */\r
-#define HAVE_OPENSSL_TLS1_H 1\r
-\r
-/* Define to 1 if you have the `poll' function. */\r
-/* #undef HAVE_POLL 1 */\r
-\r
-/* Define to 1 if you use poll in su_port. */\r
-#define HAVE_POLL_PORT 1\r
-\r
-/* Define to 1 if you have /proc/net/if_inet6 control file */\r
-/* #undef HAVE_PROC_NET_IF_INET6 */\r
-\r
-/* Define to 1 if you have working pthread_rwlock_t implementation. A thread\r
-   may hold multiple concurrent read locks on rwlock - that is, successfully\r
-   call the pthread_rwlock_rdlock() function n times. If so, the application\r
-   shall ensure that the thread performs matching unlocks - that is, it calls\r
-   the pthread_rwlock_unlock() function n times. */\r
-#define HAVE_PTHREAD_RWLOCK 1\r
-\r
-/* Define to 1 if you have the `random' function. */\r
-#define HAVE_RANDOM 1\r
-\r
-/* Define to 1 if you have sa_len in struct sockaddr */\r
-/* #undef HAVE_SA_LEN */\r
-\r
-/* Define to 1 if you have SCTP */\r
-/* #undef HAVE_SCTP */\r
-\r
-/* Define to 1 if you have the `select' function. */\r
-#define HAVE_SELECT 1\r
-\r
-/* Define to 1 if you have Sofia sigcomp >= 2.5 */\r
-/* #undef HAVE_SIGCOMP */\r
-\r
-/* Define to 1 if you have the <sigcomp.h> header file. */\r
-/* #undef HAVE_SIGCOMP_H */\r
-\r
-/* Define to 1 if you have the `signal' function. */\r
-/* #undef HAVE_SIGNAL */\r
-\r
-/* Define to 1 if you have SIGPIPE */\r
-/* #undef HAVE_SIGPIPE */\r
-\r
-/* Define to 1 if you have IPv6 structures and constants */\r
-/* #undef HAVE_SIN6 */\r
-\r
-/* Define to 1 if you have WIN32 WSAIoctl SIO_ADDRESS_LIST_QUERY. */\r
-/* #undef HAVE_SIO_ADDRESS_LIST_QUERY */\r
-\r
-/* Define to 1 if you have the `socketpair' function. */\r
-/* #undef HAVE_SOCKETPAIR */\r
-\r
-/* Define to 1 if we use NTH library */\r
-/* #undef HAVE_SOFIA_NTH */\r
-\r
-/* Define to 1 if we use NTLM library */\r
-/* #undef HAVE_SOFIA_NTLM */\r
-\r
-/* Define to 1 if you have Sofia sigcomp >= 2.5 */\r
-/* #undef HAVE_SOFIA_SIGCOMP */\r
-\r
-/* Define to 1 always */\r
-#define HAVE_SOFIA_SIP 1\r
-\r
-/* Define to 1 if we use S/MIME library */\r
-#define HAVE_SOFIA_SMIME 0\r
-\r
-/* Define to 1 if we use DNS library */\r
-#define HAVE_SOFIA_SRESOLV 1\r
-\r
-/* Define to 1 if we use STUN library */\r
-#define HAVE_SOFIA_STUN 1\r
-\r
-/* Define to 1 if we use SRTP */\r
-#define HAVE_SRTP 0\r
-\r
-/* Define to 1 if you have the <stdint.h> header file. */\r
-#define HAVE_STDINT_H 1\r
-\r
-/* Define to 1 if you have the <stdlib.h> header file. */\r
-#define HAVE_STDLIB_H 1\r
-\r
-/* Define to 1 if you have the `strcasestr' function. */\r
-#define HAVE_STRCASESTR 1\r
-\r
-/* Define to 1 if you have the `strerror' function. */\r
-#define HAVE_STRERROR 1\r
-\r
-/* Define to 1 if you have the <strings.h> header file. */\r
-#define HAVE_STRINGS_H 1\r
-\r
-/* Define to 1 if you have the <string.h> header file. */\r
-#define HAVE_STRING_H 1\r
-\r
-/* Define to 1 if you have the `strtoull' function. */\r
-/* #undef HAVE_STRTOULL */\r
-\r
-/* Define to 1 if your CC supports C99 struct initialization */\r
-#define HAVE_STRUCT_KEYWORDS 1\r
-\r
-/* Define to 1 if you have the <sys/epoll.h> header file. */\r
-/* #undef HAVE_SYS_EPOLL_H */\r
-\r
-/* Define to 1 if you have the <sys/event.h> header file. */\r
-#define HAVE_SYS_EVENT_H 1\r
-\r
-/* Define to 1 if you have the <sys/filio.h> header file. */\r
-/* #undef HAVE_SYS_FILIO_H */\r
-\r
-/* Define to 1 if you have the <sys/ioctl.h> header file. */\r
-#define HAVE_SYS_IOCTL_H 1\r
-\r
-/* Define to 1 if you have the <sys/select.h> header file. */\r
-#define HAVE_SYS_SELECT_H 1\r
-\r
-/* Define to 1 if you have the <sys/socket.h> header file. */\r
-#define HAVE_SYS_SOCKET_H 1\r
-\r
-/* Define to 1 if you have the <sys/sockio.h> header file. */\r
-#define HAVE_SYS_SOCKIO_H 1\r
-\r
-/* Define to 1 if you have the <sys/stat.h> header file. */\r
-#define HAVE_SYS_STAT_H 1\r
-\r
-/* Define to 1 if you have the <sys/time.h> header file. */\r
-#define HAVE_SYS_TIME_H 1\r
-\r
-/* Define to 1 if you have the <sys/types.h> header file. */\r
-#define HAVE_SYS_TYPES_H 1\r
-\r
-/* Define to 1 if you have the `tcsetattr' function. */\r
-#define HAVE_TCSETATTR 1\r
-\r
-/* Define to 1 if you have TLS */\r
-/* #undef HAVE_TLS */\r
-\r
-/* Define to 1 if you have the <unistd.h> header file. */\r
-#define HAVE_UNISTD_H 1\r
-\r
-/* Define to 1 if we use UPnP */\r
-#define HAVE_UPNP 0\r
-\r
-/* Define to 1 you have WIN32 */\r
-/* #undef HAVE_WIN32 */\r
-\r
-/* Define to 1 if you have the <windef.h> header file. */\r
-/* #undef HAVE_WINDEF_H */\r
-\r
-/* Define to 1 if you have the <winsock2.h> header file. */\r
-/* #undef HAVE_WINSOCK2_H */\r
-\r
-/* Define to 1 if you have the <ws2tcpip.h> header file. */\r
-/* #undef HAVE_WS2TCPIP_H */\r
-\r
-/* Define to format (%lli) for long long */\r
-#define LLI "%lli"\r
-\r
-/* Define to format (%llu) for unsigned long long */\r
-#define LLU "%llu"\r
-\r
-/* Define to format (%llx) for long long hex */\r
-#define LLX "%llx"\r
-\r
-/* Define printf() modifier for ssize_t */\r
-#define MOD_ZD "%zd"\r
-\r
-/* Define printf() modifier for size_t */\r
-#define MOD_ZU "%zu"\r
-\r
-/* Name of package */\r
-#define PACKAGE "sofia-sip"\r
-\r
-/* Define to the address where bug reports for this package should be sent. */\r
-#define PACKAGE_BUGREPORT ""\r
-\r
-/* Define to the full name of this package. */\r
-#define PACKAGE_NAME "sofia-sip"\r
-\r
-/* Define to the full name and version of this package. */\r
-#define PACKAGE_STRING "sofia-sip 1.12.5work"\r
-\r
-/* Define to the one symbol short name of this package. */\r
-#define PACKAGE_TARNAME "sofia-sip"\r
-\r
-/* Define to the version of this package. */\r
-#define PACKAGE_VERSION "1.12.5work"\r
-\r
-/* Define as the return type of signal handlers (`int' or `void'). */\r
-#define RETSIGTYPE void\r
-\r
-/* If using the C implementation of alloca, define if you know the\r
-   direction of stack growth for your system; otherwise it will be\r
-   automatically deduced at run-time.\r
-       STACK_DIRECTION > 0 => grows toward higher addresses\r
-       STACK_DIRECTION < 0 => grows toward lower addresses\r
-       STACK_DIRECTION = 0 => direction of growth unknown */\r
-/* #undef STACK_DIRECTION */\r
-\r
-/* Define to 1 if you have the ANSI C header files. */\r
-#define STDC_HEADERS 1\r
-\r
-/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */\r
-#define TIME_WITH_SYS_TIME 1\r
-\r
-/* Version number of package */\r
-#define VERSION "1.12.5work"\r
-\r
-/* Define to 1 if your processor stores words with the most significant byte\r
-   first (like Motorola and SPARC, unlike Intel and VAX). */\r
-/* #undef WORDS_BIGENDIAN */\r
-\r
-/* Enable GNU extensions on systems that have them.  */\r
-#ifndef _GNU_SOURCE\r
-# define _GNU_SOURCE 1\r
-#endif\r
-\r
-/* Define to empty if `const' does not conform to ANSI C. */\r
-/* #undef const */\r
-\r
-/* Define to `__inline__' or `__inline' if that's what the C compiler\r
-   calls it, or to nothing if 'inline' is not supported under any name.  */\r
-#ifndef __cplusplus\r
-/* #undef inline */\r
-#endif\r
-\r
-/* Define to a at least 64-bit int type */\r
-#define longlong long long\r
-\r
-/* Define to `unsigned' if <sys/types.h> does not define. */\r
-/* #undef size_t */\r
-\r
-/* Define to 1 if compiling on Open C environment */\r
-#define HAVE_OPEN_C 1\r
+/* config.h.in.  Template for Open C  */
+
+/* Define to 1 if using `alloca.c'. */
+/* #undef C_ALLOCA */
+
+/* Define to the random number source name. */
+/* #undef DEV_URANDOM */
+
+/* Define to 1 if you have addrinfo structure. */
+#define HAVE_ADDRINFO 1
+
+/* Define to 1 if you have the `alarm' function. */
+/* #undef HAVE_ALARM */
+
+/* Define to 1 if you have `alloca', as a function or macro. */
+/* #undef HAVE_ALLOCA */
+
+/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
+   */
+/* #undef HAVE_ALLOCA_H 1 */
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#define HAVE_ARPA_INET_H 1
+
+/* Define to 1 if you have the `clock_getcpuclockid' function. */
+/* #undef HAVE_CLOCK_GETCPUCLOCKID */
+
+/* Define to 1 if you have the `clock_gettime' function. */
+/* #undef HAVE_CLOCK_GETTIME */
+
+/* Define to 1 if you have /dev/urandom. */
+/* #undef HAVE_DEV_URANDOM */
+
+/* Define to 1 if you have the <dirent.h> header file. */
+#define HAVE_DIRENT_H 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have epoll interface. */
+/* #undef HAVE_EPOLL */
+
+/* Define to 1 if you have the `epoll_create' function. */
+/* #undef HAVE_EPOLL_CREATE */
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have WIN32 FILETIME type and GetSystemTimeAsFileTime().
+   */
+/* #undef HAVE_FILETIME */
+
+/* Define to 1 if you have the `flock' function. */
+/* #undef HAVE_FLOCK */
+
+/* Define to 1 if you have the `freeaddrinfo' function. */
+#define HAVE_FREEADDRINFO 1
+
+/* Define to 1 if the C compiler supports __func__ */
+#define HAVE_FUNC 1
+
+/* Define to 1 if the C compiler supports __FUNCTION__ */
+#define HAVE_FUNCTION 1
+
+/* Define to 1 if you have the `gai_strerror' function. */
+#define HAVE_GAI_STRERROR 1
+
+/* Define to 1 if you have the `getaddrinfo' function. */
+#define HAVE_GETADDRINFO 1
+
+/* Define to 1 if you have the `getdelim' function. */
+/* #undef HAVE_GETDELIM */
+
+/* Define to 1 if you have the `gethostbyname' function. */
+#define HAVE_GETHOSTBYNAME 1
+
+/* Define to 1 if you have the `gethostname' function. */
+#define HAVE_GETHOSTNAME 1
+
+/* Define to 1 if you have the `getifaddrs' function. */
+/* #undef HAVE_GETIFADDRS 1 */
+
+/* Define to 1 if you have the `getipnodebyname' function. */
+#define HAVE_GETIPNODEBYNAME 1
+
+/* Define to 1 if you have the `getline' function. */
+/* #undef HAVE_GETLINE */
+
+/* Define to 1 if you have the `getnameinfo' function. */
+#define HAVE_GETNAMEINFO 1
+
+/* Define to 1 if you have the `getpass' function. */
+#define HAVE_GETPASS 1
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#define HAVE_GETTIMEOFDAY 1
+
+/* Define to 1 if you have the <ifaddr.h> header file. */
+/* #undef HAVE_IFADDR_H */
+
+/* Define to 1 if you have SIOCGIFCONF */
+#define HAVE_IFCONF 1
+
+/* Define to 1 if you have SIOCGIFNUM ioctl */
+/* #undef HAVE_IFNUM */
+
+/* Define to 1 if you have ifr_ifindex in <net/if.h> */
+/* #undef HAVE_IFR_IFINDEX */
+
+/* Define to 1 if you have ifr_index in <net/if.h> */
+#define HAVE_IFR_INDEX 1
+
+/* Define to 1 if you have the `if_nameindex' function. */
+#define HAVE_IF_NAMEINDEX 1
+
+/* Define to 1 if you have the `inet_ntop' function. */
+#define HAVE_INET_NTOP 1
+
+/* Define to 1 if you have the `inet_pton' function. */
+#define HAVE_INET_PTON 1
+
+/* Define to 1 if you have the `initstate' function. */
+#define HAVE_INITSTATE 1
+
+/* Define to 1 if you have inlining compiler */
+#define HAVE_INLINE 1
+
+/* Define to 1 if you have WIN32 INTERFACE_INFO_EX type. */
+/* #undef HAVE_INTERFACE_INFO_EX */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <iphlpapi.h> header file. */
+/* #undef HAVE_IPHLPAPI_H */
+
+/* Define to 1 if you have IPV6_RECVERR in <netinet/in6.h> */
+/* #undef HAVE_IPV6_RECVERR */
+
+/* Define to 1 if you have IP_RECVERR in <netinet/in.h> */
+/* #undef HAVE_IP_RECVERR */
+
+/* Define to 1 if you have the `kqueue' function. */
+/* #undef HAVE_KQUEUE 1 */
+
+/* Define to 1 if you use kqueue in su_port. */
+/* #undef HAVE_KQUEUE_PORT 1 */
+
+/* Define to 1 if you have the `crypto' library (-lcrypto). */
+#define HAVE_LIBCRYPTO 1
+
+/* Define to 1 if you have the `pthread' library (-lpthread). */
+#define HAVE_LIBPTHREAD 1
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Define to 1 if you have the `ssl' library (-lssl). */
+#define HAVE_LIBSSL 1
+
+/* Define to 1 if you have the `memccpy' function. */
+#define HAVE_MEMCCPY 1
+
+/* Define to 1 if you have the `memcspn' function. */
+/* #undef HAVE_MEMCSPN */
+
+/* Define to 1 if you have the `memmem' function. */
+/* #undef HAVE_MEMMEM */
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `memspn' function. */
+/* #undef HAVE_MEMSPN */
+
+/* Define to 1 if you are compiling in MinGW environment */
+/* #undef HAVE_MINGW */
+
+/* Define to 1 if you have MSG_TRUNC flag */
+#define HAVE_MSG_TRUNC 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#define HAVE_NETDB_H 1
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#define HAVE_NETINET_IN_H 1
+
+/* Define to 1 if you have the <netinet/sctp.h> header file. */
+/* #undef HAVE_NETINET_SCTP_H */
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+/* #undef HAVE_NETINET_TCP_H */
+
+/* Define to 1 if you have the <netpacket/packet.h> header file. */
+/* #undef HAVE_NETPACKET_PACKET_H */
+
+/* Define to 1 if you have the <net/if.h> header file. */
+#define HAVE_NET_IF_H 1
+
+/* Define to 1 if you have the <net/if_types.h> header file. */
+/* #undef HAVE_NET_IF_TYPES_H 1 */
+
+/* Define to 1 if you have OpenSSL */
+#define HAVE_OPENSSL 1
+
+/* Define to 1 if you have the <openssl/tls1.h> header file. */
+#define HAVE_OPENSSL_TLS1_H 1
+
+/* Define to 1 if you have the `poll' function. */
+/* #undef HAVE_POLL 1 */
+
+/* Define to 1 if you use poll in su_port. */
+#define HAVE_POLL_PORT 1
+
+/* Define to 1 if you have /proc/net/if_inet6 control file */
+/* #undef HAVE_PROC_NET_IF_INET6 */
+
+/* Define to 1 if you have working pthread_rwlock_t implementation. A thread
+   may hold multiple concurrent read locks on rwlock - that is, successfully
+   call the pthread_rwlock_rdlock() function n times. If so, the application
+   shall ensure that the thread performs matching unlocks - that is, it calls
+   the pthread_rwlock_unlock() function n times. */
+#define HAVE_PTHREAD_RWLOCK 1
+
+/* Define to 1 if you have the `random' function. */
+#define HAVE_RANDOM 1
+
+/* Define to 1 if you have sa_len in struct sockaddr */
+/* #undef HAVE_SA_LEN */
+
+/* Define to 1 if you have SCTP */
+/* #undef HAVE_SCTP */
+
+/* Define to 1 if you have the `select' function. */
+#define HAVE_SELECT 1
+
+/* Define to 1 if you have Sofia sigcomp >= 2.5 */
+/* #undef HAVE_SIGCOMP */
+
+/* Define to 1 if you have the <sigcomp.h> header file. */
+/* #undef HAVE_SIGCOMP_H */
+
+/* Define to 1 if you have the `signal' function. */
+/* #undef HAVE_SIGNAL */
+
+/* Define to 1 if you have SIGPIPE */
+/* #undef HAVE_SIGPIPE */
+
+/* Define to 1 if you have IPv6 structures and constants */
+/* #undef HAVE_SIN6 */
+
+/* Define to 1 if you have WIN32 WSAIoctl SIO_ADDRESS_LIST_QUERY. */
+/* #undef HAVE_SIO_ADDRESS_LIST_QUERY */
+
+/* Define to 1 if you have the `socketpair' function. */
+/* #undef HAVE_SOCKETPAIR */
+
+/* Define to 1 if we use NTH library */
+/* #undef HAVE_SOFIA_NTH */
+
+/* Define to 1 if we use NTLM library */
+/* #undef HAVE_SOFIA_NTLM */
+
+/* Define to 1 if you have Sofia sigcomp >= 2.5 */
+/* #undef HAVE_SOFIA_SIGCOMP */
+
+/* Define to 1 always */
+#define HAVE_SOFIA_SIP 1
+
+/* Define to 1 if we use S/MIME library */
+#define HAVE_SOFIA_SMIME 0
+
+/* Define to 1 if we use DNS library */
+#define HAVE_SOFIA_SRESOLV 1
+
+/* Define to 1 if we use STUN library */
+#define HAVE_SOFIA_STUN 1
+
+/* Define to 1 if we use SRTP */
+#define HAVE_SRTP 0
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strcasestr' function. */
+#define HAVE_STRCASESTR 1
+
+/* Define to 1 if you have the `strerror' function. */
+#define HAVE_STRERROR 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strtoull' function. */
+/* #undef HAVE_STRTOULL */
+
+/* Define to 1 if your CC supports C99 struct initialization */
+#define HAVE_STRUCT_KEYWORDS 1
+
+/* Define to 1 if you have the <sys/epoll.h> header file. */
+/* #undef HAVE_SYS_EPOLL_H */
+
+/* Define to 1 if you have the <sys/event.h> header file. */
+#define HAVE_SYS_EVENT_H 1
+
+/* Define to 1 if you have the <sys/filio.h> header file. */
+/* #undef HAVE_SYS_FILIO_H */
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#define HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+#define HAVE_SYS_SELECT_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/sockio.h> header file. */
+#define HAVE_SYS_SOCKIO_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the `tcsetattr' function. */
+#define HAVE_TCSETATTR 1
+
+/* Define to 1 if you have TLS */
+/* #undef HAVE_TLS */
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if we use UPnP */
+#define HAVE_UPNP 0
+
+/* Define to 1 you have WIN32 */
+/* #undef HAVE_WIN32 */
+
+/* Define to 1 if you have the <windef.h> header file. */
+/* #undef HAVE_WINDEF_H */
+
+/* Define to 1 if you have the <winsock2.h> header file. */
+/* #undef HAVE_WINSOCK2_H */
+
+/* Define to 1 if you have the <ws2tcpip.h> header file. */
+/* #undef HAVE_WS2TCPIP_H */
+
+/* Define to format (%lli) for long long */
+#define LLI "%lli"
+
+/* Define to format (%llu) for unsigned long long */
+#define LLU "%llu"
+
+/* Define to format (%llx) for long long hex */
+#define LLX "%llx"
+
+/* Define printf() modifier for ssize_t */
+#define MOD_ZD "%zd"
+
+/* Define printf() modifier for size_t */
+#define MOD_ZU "%zu"
+
+/* Name of package */
+#define PACKAGE "sofia-sip"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "sofia-sip"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "sofia-sip 1.12.5work"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "sofia-sip"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "1.12.5work"
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#define RETSIGTYPE void
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at run-time.
+       STACK_DIRECTION > 0 => grows toward higher addresses
+       STACK_DIRECTION < 0 => grows toward lower addresses
+       STACK_DIRECTION = 0 => direction of growth unknown */
+/* #undef STACK_DIRECTION */
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#define TIME_WITH_SYS_TIME 1
+
+/* Version number of package */
+#define VERSION "1.12.5work"
+
+/* Define to 1 if your processor stores words with the most significant byte
+   first (like Motorola and SPARC, unlike Intel and VAX). */
+/* #undef WORDS_BIGENDIAN */
+
+/* Enable GNU extensions on systems that have them.  */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+/* #undef inline */
+#endif
+
+/* Define to a at least 64-bit int type */
+#define longlong long long
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* Define to 1 if compiling on Open C environment */
+#define HAVE_OPEN_C 1
index adc0f6bc40ce5e16fbbbdd990aca73e34e25f1a7..8f354870f88c57ac4b6630b921c4a5f43e94a12e 100644 (file)
@@ -1,35 +1,35 @@
-/* This is a build of CELT */\r
-#define CELT_BUILD \r
-\r
-/* Version extra */\r
-#define CELT_EXTRA_VERSION "-1"\r
-\r
-/* Version major */\r
-#define CELT_MAJOR_VERSION 0\r
-\r
-/* Version micro */\r
-#define CELT_MICRO_VERSION 0\r
-\r
-/* Version minor */\r
-#define CELT_MINOR_VERSION 7\r
-\r
-/* Complete version string */\r
-#define CELT_VERSION "0.7.0-1"\r
-\r
-/* Compile as fixed-point */\r
-/* #undef FIXED_POINT */\r
-\r
-/* Compile as floating-point */\r
-#define FLOATING_POINT \r
-\r
-/* Make use of alloca */\r
-/* #undef USE_ALLOCA */\r
-#define USE_ALLOCA 1 /* disable this when using SSE */\r
-\r
-/* Define to equivalent of C99 restrict keyword, or to nothing if this is not\r
-   supported. Do not define if restrict is supported directly. */\r
-#define restrict /* __restrict */\r
-\r
-// Microsoft version of 'inline'\r
-#define inline __inline\r
-\r
+/* This is a build of CELT */
+#define CELT_BUILD 
+
+/* Version extra */
+#define CELT_EXTRA_VERSION "-1"
+
+/* Version major */
+#define CELT_MAJOR_VERSION 0
+
+/* Version micro */
+#define CELT_MICRO_VERSION 0
+
+/* Version minor */
+#define CELT_MINOR_VERSION 7
+
+/* Complete version string */
+#define CELT_VERSION "0.7.0-1"
+
+/* Compile as fixed-point */
+/* #undef FIXED_POINT */
+
+/* Compile as floating-point */
+#define FLOATING_POINT 
+
+/* Make use of alloca */
+/* #undef USE_ALLOCA */
+#define USE_ALLOCA 1 /* disable this when using SSE */
+
+/* Define to equivalent of C99 restrict keyword, or to nothing if this is not
+   supported. Do not define if restrict is supported directly. */
+#define restrict /* __restrict */
+
+// Microsoft version of 'inline'
+#define inline __inline
+
index a8c1eaab88d5d99c061f4ceffa9aaca59c9c2515..483082e5933d599d814f87f6a9975e56129d2ede 100644 (file)
@@ -92,9 +92,9 @@
                        
                return intgr ;
        }
-#else               \r
-#define float2int   \r
-#endif            \r
+#else               
+#define float2int   
+#endif            
   
 
 #else
index 6a694ad701ec0d5d795236051597004ef5dedef6..d0d814ebbac387aa996325bb66acc1fdf5731d17 100644 (file)
@@ -1 +1 @@
-#include <os.h>\r
+#include <os.h>
index 208f55535af459440342ca3b15ebaf6d8dd12b8e..84c56423c74df9ce9bda7a4891669962a8bea304 100644 (file)
-/*  shout.h\r
- *\r
- *  API for libshout, the streaming library for icecast\r
- *\r
- *  Copyright (C) 2002-2003 the Icecast team <team@icecast.org>\r
- *\r
- *  This library is free software; you can redistribute it and/or\r
- *  modify it under the terms of the GNU Library General Public\r
- *  License as published by the Free Software Foundation; either\r
- *  version 2 of the License, or (at your option) any later version.\r
- *\r
- *  This library is distributed in the hope that it will be useful,\r
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
- *  Library General Public License for more details.\r
- *\r
- *  You should have received a copy of the GNU Library General Public\r
- *  License along with this library; if not, write to the Free\r
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- */\r
-#ifndef __LIBSHOUT_SHOUT_H__\r
-#define __LIBSHOUT_SHOUT_H__\r
-\r
-#include <sys/types.h>\r
-#ifdef WIN32\r
-#include <os.h>\r
-# ifdef _MSC_VER\r
-#  undef inline\r
-#  define inline __inline\r
-#if (_MSC_VER >= 1400)                 // VC8+\r
-#ifndef _CRT_SECURE_NO_DEPRECATE\r
-#define _CRT_SECURE_NO_DEPRECATE\r
-#endif\r
-#ifndef _CRT_NONSTDC_NO_DEPRECATE\r
-#define _CRT_NONSTDC_NO_DEPRECATE\r
-#endif\r
-#endif // VC8+\r
-# endif\r
-#ifndef __MINGW32__\r
-#define va_copy(ap1, ap2) memcpy(&ap1, &ap2, sizeof(va_list))\r
-#endif\r
-\r
-#endif\r
-\r
-#define SHOUTERR_SUCCESS       (0)\r
-#define SHOUTERR_INSANE                (-1)\r
-#define SHOUTERR_NOCONNECT     (-2)\r
-#define SHOUTERR_NOLOGIN       (-3)\r
-#define SHOUTERR_SOCKET                (-4)\r
-#define SHOUTERR_MALLOC                (-5)\r
-#define SHOUTERR_METADATA      (-6)\r
-#define SHOUTERR_CONNECTED     (-7)\r
-#define SHOUTERR_UNCONNECTED   (-8)\r
-#define SHOUTERR_UNSUPPORTED   (-9)\r
-\r
-#define SHOUTERR_BUSY          (-10)\r
-\r
-#define SHOUT_FORMAT_OGG       (0)\r
-#define SHOUT_FORMAT_MP3       (1)\r
-/* backward-compatibility alias */\r
-#define SHOUT_FORMAT_VORBIS    SHOUT_FORMAT_OGG\r
-\r
-#define SHOUT_PROTOCOL_HTTP            (0)\r
-#define SHOUT_PROTOCOL_XAUDIOCAST      (1)\r
-#define SHOUT_PROTOCOL_ICY             (2)\r
-\r
-#define SHOUT_AI_BITRATE       "bitrate"\r
-#define SHOUT_AI_SAMPLERATE    "samplerate"\r
-#define SHOUT_AI_CHANNELS      "channels"\r
-#define SHOUT_AI_QUALITY       "quality"\r
-\r
-typedef struct shout shout_t;\r
-typedef struct _util_dict shout_metadata_t;\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-/* initializes the shout library. Must be called before anything else */\r
-void shout_init(void);\r
-\r
-/* shuts down the shout library, deallocating any global storage. Don't call\r
- * anything afterwards */\r
-void shout_shutdown(void);\r
-\r
-/* returns a static version string.  Non-null parameters will be set to the\r
- * value of the library major, minor, and patch levels, respectively */\r
-const char *shout_version(int *major, int *minor, int *patch);\r
-\r
-/* Allocates and sets up a new shout_t.  Returns NULL if it can't get enough\r
- * memory.  The returns shout_t must be disposed of with shout_free. */\r
-shout_t *shout_new(void);\r
-\r
-/* Free all memory allocated by a shout_t */\r
-void shout_free(shout_t *self);\r
-\r
-/* Returns a statically allocated string describing the last shout error\r
- * to occur.  Only valid until the next libshout call on this shout_t */\r
-const char *shout_get_error(shout_t *self);\r
-\r
-/* Return the error code (e.g. SHOUTERR_SOCKET) for this shout instance */\r
-int shout_get_errno(shout_t *self);\r
-\r
-/* returns SHOUTERR_CONNECTED or SHOUTERR_UNCONNECTED */\r
-int shout_get_connected(shout_t *self);\r
-\r
-/* Parameter manipulation functions.  libshout makes copies of all parameters,\r
- * the caller may free its copies after giving them to libshout.  May return\r
- * SHOUTERR_MALLOC */\r
-\r
-int shout_set_host(shout_t *self, const char *host);\r
-const char *shout_get_host(shout_t *self);\r
-\r
-int shout_set_port(shout_t *self, unsigned short port);\r
-unsigned short shout_get_port(shout_t *self);\r
-\r
-int shout_set_password(shout_t *, const char *password);\r
-const char *shout_get_password(shout_t *self);\r
-\r
-int shout_set_mount(shout_t *self, const char *mount);\r
-const char *shout_get_mount(shout_t *self);\r
-\r
-int shout_set_name(shout_t *self, const char *name);\r
-const char *shout_get_name(shout_t *self);\r
-\r
-int shout_set_url(shout_t *self, const char *url);\r
-const char *shout_get_url(shout_t *self);\r
-\r
-int shout_set_genre(shout_t *self, const char *genre);\r
-const char *shout_get_genre(shout_t *self);\r
-\r
-int shout_set_user(shout_t *self, const char *username);\r
-const char *shout_get_user(shout_t *self);\r
-\r
-int shout_set_agent(shout_t *self, const char *username);\r
-const char *shout_get_agent(shout_t *self);\r
-\r
-int shout_set_description(shout_t *self, const char *description);\r
-const char *shout_get_description(shout_t *self);\r
-\r
-int shout_set_dumpfile(shout_t *self, const char *dumpfile);\r
-const char *shout_get_dumpfile(shout_t *self);\r
-\r
-int shout_set_audio_info(shout_t *self, const char *name, const char *value);\r
-const char *shout_get_audio_info(shout_t *self, const char *name);\r
-\r
-int shout_set_public(shout_t *self, unsigned int make_public);\r
-unsigned int shout_get_public(shout_t *self);\r
-\r
-/* takes a SHOUT_FORMAT_xxxx argument */\r
-int shout_set_format(shout_t *self, unsigned int format);\r
-unsigned int shout_get_format(shout_t *self);\r
-\r
-/* takes a SHOUT_PROTOCOL_xxxxx argument */\r
-int shout_set_protocol(shout_t *self, unsigned int protocol);\r
-unsigned int shout_get_protocol(shout_t *self);\r
-\r
-/* Instructs libshout to use nonblocking I/O. Must be called before\r
- * shout_open (no switching back and forth midstream at the moment). */\r
-int shout_set_nonblocking(shout_t* self, unsigned int nonblocking);\r
-unsigned int shout_get_nonblocking(shout_t *self);\r
-\r
-/* Opens a connection to the server.  All parameters must already be set */\r
-int shout_open(shout_t *self);\r
-\r
-/* Closes a connection to the server */\r
-int shout_close(shout_t *self);\r
-\r
-/* Send data to the server, parsing it for format specific timing info */\r
-int shout_send(shout_t *self, const unsigned char *data, size_t len);\r
-\r
-/* Send unparsed data to the server.  Do not use this unless you know\r
- * what you are doing. \r
- * Returns the number of bytes written, or < 0 on error.\r
- */\r
-ssize_t shout_send_raw(shout_t *self, const unsigned char *data, size_t len);\r
-\r
-/* return the number of bytes currently on the write queue (only makes sense in\r
- * nonblocking mode). */\r
-ssize_t shout_queuelen(shout_t *self);\r
-  \r
-/* Puts caller to sleep until it is time to send more data to the server */\r
-void shout_sync(shout_t *self);\r
-\r
-/* Amount of time in ms caller should wait before sending again */\r
-int shout_delay(shout_t *self);\r
-\r
-/* Sets MP3 metadata.\r
- * Returns:\r
- *   SHOUTERR_SUCCESS\r
- *   SHOUTERR_UNSUPPORTED if format isn't MP3\r
- *   SHOUTERR_MALLOC\r
- *   SHOUTERR_INSANE\r
- *   SHOUTERR_NOCONNECT\r
- *   SHOUTERR_SOCKET\r
- */\r
-int shout_set_metadata(shout_t *self, shout_metadata_t *metadata);\r
-\r
-/* Allocates a new metadata structure.  Must be freed by shout_metadata_free. */\r
-shout_metadata_t *shout_metadata_new(void);\r
-\r
-/* Free resources allocated by shout_metadata_t */\r
-void shout_metadata_free(shout_metadata_t *self);\r
-\r
-/* Add a parameter to the metadata structure.\r
- * Returns:\r
- *   SHOUTERR_SUCCESS on success\r
- *   SHOUTERR_INSANE if self isn't a valid shout_metadata_t* or name is null\r
- *   SHOUTERR_MALLOC if memory can't be allocated */\r
-int shout_metadata_add(shout_metadata_t *self, const char *name, const char *value);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-/* --- Compiled features --- */\r
-\r
-#define SHOUT_THREADSAFE @SHOUT_THREADSAFE@\r
-\r
-#endif /* __LIBSHOUT_SHOUT_H__ */\r
+/*  shout.h
+ *
+ *  API for libshout, the streaming library for icecast
+ *
+ *  Copyright (C) 2002-2003 the Icecast team <team@icecast.org>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#ifndef __LIBSHOUT_SHOUT_H__
+#define __LIBSHOUT_SHOUT_H__
+
+#include <sys/types.h>
+#ifdef WIN32
+#include <os.h>
+# ifdef _MSC_VER
+#  undef inline
+#  define inline __inline
+#if (_MSC_VER >= 1400)                 // VC8+
+#ifndef _CRT_SECURE_NO_DEPRECATE
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+#ifndef _CRT_NONSTDC_NO_DEPRECATE
+#define _CRT_NONSTDC_NO_DEPRECATE
+#endif
+#endif // VC8+
+# endif
+#ifndef __MINGW32__
+#define va_copy(ap1, ap2) memcpy(&ap1, &ap2, sizeof(va_list))
+#endif
+
+#endif
+
+#define SHOUTERR_SUCCESS       (0)
+#define SHOUTERR_INSANE                (-1)
+#define SHOUTERR_NOCONNECT     (-2)
+#define SHOUTERR_NOLOGIN       (-3)
+#define SHOUTERR_SOCKET                (-4)
+#define SHOUTERR_MALLOC                (-5)
+#define SHOUTERR_METADATA      (-6)
+#define SHOUTERR_CONNECTED     (-7)
+#define SHOUTERR_UNCONNECTED   (-8)
+#define SHOUTERR_UNSUPPORTED   (-9)
+
+#define SHOUTERR_BUSY          (-10)
+
+#define SHOUT_FORMAT_OGG       (0)
+#define SHOUT_FORMAT_MP3       (1)
+/* backward-compatibility alias */
+#define SHOUT_FORMAT_VORBIS    SHOUT_FORMAT_OGG
+
+#define SHOUT_PROTOCOL_HTTP            (0)
+#define SHOUT_PROTOCOL_XAUDIOCAST      (1)
+#define SHOUT_PROTOCOL_ICY             (2)
+
+#define SHOUT_AI_BITRATE       "bitrate"
+#define SHOUT_AI_SAMPLERATE    "samplerate"
+#define SHOUT_AI_CHANNELS      "channels"
+#define SHOUT_AI_QUALITY       "quality"
+
+typedef struct shout shout_t;
+typedef struct _util_dict shout_metadata_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* initializes the shout library. Must be called before anything else */
+void shout_init(void);
+
+/* shuts down the shout library, deallocating any global storage. Don't call
+ * anything afterwards */
+void shout_shutdown(void);
+
+/* returns a static version string.  Non-null parameters will be set to the
+ * value of the library major, minor, and patch levels, respectively */
+const char *shout_version(int *major, int *minor, int *patch);
+
+/* Allocates and sets up a new shout_t.  Returns NULL if it can't get enough
+ * memory.  The returns shout_t must be disposed of with shout_free. */
+shout_t *shout_new(void);
+
+/* Free all memory allocated by a shout_t */
+void shout_free(shout_t *self);
+
+/* Returns a statically allocated string describing the last shout error
+ * to occur.  Only valid until the next libshout call on this shout_t */
+const char *shout_get_error(shout_t *self);
+
+/* Return the error code (e.g. SHOUTERR_SOCKET) for this shout instance */
+int shout_get_errno(shout_t *self);
+
+/* returns SHOUTERR_CONNECTED or SHOUTERR_UNCONNECTED */
+int shout_get_connected(shout_t *self);
+
+/* Parameter manipulation functions.  libshout makes copies of all parameters,
+ * the caller may free its copies after giving them to libshout.  May return
+ * SHOUTERR_MALLOC */
+
+int shout_set_host(shout_t *self, const char *host);
+const char *shout_get_host(shout_t *self);
+
+int shout_set_port(shout_t *self, unsigned short port);
+unsigned short shout_get_port(shout_t *self);
+
+int shout_set_password(shout_t *, const char *password);
+const char *shout_get_password(shout_t *self);
+
+int shout_set_mount(shout_t *self, const char *mount);
+const char *shout_get_mount(shout_t *self);
+
+int shout_set_name(shout_t *self, const char *name);
+const char *shout_get_name(shout_t *self);
+
+int shout_set_url(shout_t *self, const char *url);
+const char *shout_get_url(shout_t *self);
+
+int shout_set_genre(shout_t *self, const char *genre);
+const char *shout_get_genre(shout_t *self);
+
+int shout_set_user(shout_t *self, const char *username);
+const char *shout_get_user(shout_t *self);
+
+int shout_set_agent(shout_t *self, const char *username);
+const char *shout_get_agent(shout_t *self);
+
+int shout_set_description(shout_t *self, const char *description);
+const char *shout_get_description(shout_t *self);
+
+int shout_set_dumpfile(shout_t *self, const char *dumpfile);
+const char *shout_get_dumpfile(shout_t *self);
+
+int shout_set_audio_info(shout_t *self, const char *name, const char *value);
+const char *shout_get_audio_info(shout_t *self, const char *name);
+
+int shout_set_public(shout_t *self, unsigned int make_public);
+unsigned int shout_get_public(shout_t *self);
+
+/* takes a SHOUT_FORMAT_xxxx argument */
+int shout_set_format(shout_t *self, unsigned int format);
+unsigned int shout_get_format(shout_t *self);
+
+/* takes a SHOUT_PROTOCOL_xxxxx argument */
+int shout_set_protocol(shout_t *self, unsigned int protocol);
+unsigned int shout_get_protocol(shout_t *self);
+
+/* Instructs libshout to use nonblocking I/O. Must be called before
+ * shout_open (no switching back and forth midstream at the moment). */
+int shout_set_nonblocking(shout_t* self, unsigned int nonblocking);
+unsigned int shout_get_nonblocking(shout_t *self);
+
+/* Opens a connection to the server.  All parameters must already be set */
+int shout_open(shout_t *self);
+
+/* Closes a connection to the server */
+int shout_close(shout_t *self);
+
+/* Send data to the server, parsing it for format specific timing info */
+int shout_send(shout_t *self, const unsigned char *data, size_t len);
+
+/* Send unparsed data to the server.  Do not use this unless you know
+ * what you are doing. 
+ * Returns the number of bytes written, or < 0 on error.
+ */
+ssize_t shout_send_raw(shout_t *self, const unsigned char *data, size_t len);
+
+/* return the number of bytes currently on the write queue (only makes sense in
+ * nonblocking mode). */
+ssize_t shout_queuelen(shout_t *self);
+  
+/* Puts caller to sleep until it is time to send more data to the server */
+void shout_sync(shout_t *self);
+
+/* Amount of time in ms caller should wait before sending again */
+int shout_delay(shout_t *self);
+
+/* Sets MP3 metadata.
+ * Returns:
+ *   SHOUTERR_SUCCESS
+ *   SHOUTERR_UNSUPPORTED if format isn't MP3
+ *   SHOUTERR_MALLOC
+ *   SHOUTERR_INSANE
+ *   SHOUTERR_NOCONNECT
+ *   SHOUTERR_SOCKET
+ */
+int shout_set_metadata(shout_t *self, shout_metadata_t *metadata);
+
+/* Allocates a new metadata structure.  Must be freed by shout_metadata_free. */
+shout_metadata_t *shout_metadata_new(void);
+
+/* Free resources allocated by shout_metadata_t */
+void shout_metadata_free(shout_metadata_t *self);
+
+/* Add a parameter to the metadata structure.
+ * Returns:
+ *   SHOUTERR_SUCCESS on success
+ *   SHOUTERR_INSANE if self isn't a valid shout_metadata_t* or name is null
+ *   SHOUTERR_MALLOC if memory can't be allocated */
+int shout_metadata_add(shout_metadata_t *self, const char *name, const char *value);
+
+#ifdef __cplusplus
+}
+#endif
+
+/* --- Compiled features --- */
+
+#define SHOUT_THREADSAFE @SHOUT_THREADSAFE@
+
+#endif /* __LIBSHOUT_SHOUT_H__ */
index fce8d9e8a75cf9eeceadb8f47f150aa7ac69d6e5..40b0d2fe76918afcc5c647e032d39f61154585ad 100644 (file)
@@ -1,13 +1,13 @@
-#ifndef MK1MF_BUILD\r
-  /* auto-generated by Configure for crypto/cversion.c:\r
-   * for Unix builds, crypto/Makefile.ssl generates functional definitions;\r
-   * Windows builds (and other mk1mf builds) compile cversion.c with\r
-   * -DMK1MF_BUILD and use definitions added to this file by util/mk1mf.pl. */\r
-  #error "Windows builds (PLATFORM=VC-WIN32) use mk1mf.pl-created Makefiles"\r
-#endif\r
-#ifdef MK1MF_PLATFORM_VC_WIN32\r
-  /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */\r
-  #define CFLAGS "cl  /MD /Ox /O2 /Ob2 -DOPENSSL_THREADS  -DDSO_WIN32 -W3 -WX -Gs0 -GF -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -DOPENSSL_USE_APPLINK -I. /Fdout32dll -DOPENSSL_NO_RC5 -DOPENSSL_NO_MD2 -DOPENSSL_NO_KRB5 -DOPENSSL_NO_JPAKE -DOPENSSL_NO_STATIC_ENGINE    "\r
-  #define PLATFORM "VC-WIN32"\r
-  #define DATE "Sun Jun  6 23:40:23 2010"\r
-#endif\r
+#ifndef MK1MF_BUILD
+  /* auto-generated by Configure for crypto/cversion.c:
+   * for Unix builds, crypto/Makefile.ssl generates functional definitions;
+   * Windows builds (and other mk1mf builds) compile cversion.c with
+   * -DMK1MF_BUILD and use definitions added to this file by util/mk1mf.pl. */
+  #error "Windows builds (PLATFORM=VC-WIN32) use mk1mf.pl-created Makefiles"
+#endif
+#ifdef MK1MF_PLATFORM_VC_WIN32
+  /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
+  #define CFLAGS "cl  /MD /Ox /O2 /Ob2 -DOPENSSL_THREADS  -DDSO_WIN32 -W3 -WX -Gs0 -GF -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -DOPENSSL_USE_APPLINK -I. /Fdout32dll -DOPENSSL_NO_RC5 -DOPENSSL_NO_MD2 -DOPENSSL_NO_KRB5 -DOPENSSL_NO_JPAKE -DOPENSSL_NO_STATIC_ENGINE    "
+  #define PLATFORM "VC-WIN32"
+  #define DATE "Sun Jun  6 23:40:23 2010"
+#endif
index 1ebd3efe4ed12c91ac704aacf661a1753a77d980..9a4d26baa81b056479d245f2335b385f5ee95543 100644 (file)
-/* opensslconf.h */\r
-/* WARNING: Generated automatically from opensslconf.h.in by Configure. */\r
-\r
-/* OpenSSL was configured with the following options: */\r
-#ifndef OPENSSL_SYSNAME_WIN32\r
-# define OPENSSL_SYSNAME_WIN32\r
-#endif\r
-#ifndef OPENSSL_DOING_MAKEDEPEND\r
-\r
-\r
-#ifndef OPENSSL_NO_GMP\r
-# define OPENSSL_NO_GMP\r
-#endif\r
-#ifndef OPENSSL_NO_JPAKE\r
-# define OPENSSL_NO_JPAKE\r
-#endif\r
-#ifndef OPENSSL_NO_KRB5\r
-# define OPENSSL_NO_KRB5\r
-#endif\r
-#ifndef OPENSSL_NO_MD2\r
-# define OPENSSL_NO_MD2\r
-#endif\r
-#ifndef OPENSSL_NO_RC5\r
-# define OPENSSL_NO_RC5\r
-#endif\r
-#ifndef OPENSSL_NO_RFC3779\r
-# define OPENSSL_NO_RFC3779\r
-#endif\r
-#ifndef OPENSSL_NO_STORE\r
-# define OPENSSL_NO_STORE\r
-#endif\r
-\r
-#endif /* OPENSSL_DOING_MAKEDEPEND */\r
-\r
-#ifndef OPENSSL_THREADS\r
-# define OPENSSL_THREADS\r
-#endif\r
-#ifndef OPENSSL_NO_ASM\r
-# define OPENSSL_NO_ASM\r
-#endif\r
-\r
-/* The OPENSSL_NO_* macros are also defined as NO_* if the application\r
-   asks for it.  This is a transient feature that is provided for those\r
-   who haven't had the time to do the appropriate changes in their\r
-   applications.  */\r
-#ifdef OPENSSL_ALGORITHM_DEFINES\r
-# if defined(OPENSSL_NO_GMP) && !defined(NO_GMP)\r
-#  define NO_GMP\r
-# endif\r
-# if defined(OPENSSL_NO_JPAKE) && !defined(NO_JPAKE)\r
-#  define NO_JPAKE\r
-# endif\r
-# if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5)\r
-#  define NO_KRB5\r
-# endif\r
-# if defined(OPENSSL_NO_MD2) && !defined(NO_MD2)\r
-#  define NO_MD2\r
-# endif\r
-# if defined(OPENSSL_NO_RC5) && !defined(NO_RC5)\r
-#  define NO_RC5\r
-# endif\r
-# if defined(OPENSSL_NO_RFC3779) && !defined(NO_RFC3779)\r
-#  define NO_RFC3779\r
-# endif\r
-# if defined(OPENSSL_NO_STORE) && !defined(NO_STORE)\r
-#  define NO_STORE\r
-# endif\r
-#endif\r
-\r
-/* crypto/opensslconf.h.in */\r
-\r
-/* Generate 80386 code? */\r
-#undef I386_ONLY\r
-\r
-#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */\r
-#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)\r
-#define ENGINESDIR "/usr/local/ssl/lib/engines"\r
-#define OPENSSLDIR "/usr/local/ssl"\r
-#endif\r
-#endif\r
-\r
-#undef OPENSSL_UNISTD\r
-#define OPENSSL_UNISTD <unistd.h>\r
-\r
-#undef OPENSSL_EXPORT_VAR_AS_FUNCTION\r
-#define OPENSSL_EXPORT_VAR_AS_FUNCTION\r
-\r
-#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)\r
-#define IDEA_INT unsigned int\r
-#endif\r
-\r
-#if defined(HEADER_MD2_H) && !defined(MD2_INT)\r
-#define MD2_INT unsigned int\r
-#endif\r
-\r
-#if defined(HEADER_RC2_H) && !defined(RC2_INT)\r
-/* I need to put in a mod for the alpha - eay */\r
-#define RC2_INT unsigned int\r
-#endif\r
-\r
-#if defined(HEADER_RC4_H)\r
-#if !defined(RC4_INT)\r
-/* using int types make the structure larger but make the code faster\r
- * on most boxes I have tested - up to %20 faster. */\r
-/*\r
- * I don't know what does "most" mean, but declaring "int" is a must on:\r
- * - Intel P6 because partial register stalls are very expensive;\r
- * - elder Alpha because it lacks byte load/store instructions;\r
- */\r
-#define RC4_INT unsigned int\r
-#endif\r
-#if !defined(RC4_CHUNK)\r
-/*\r
- * This enables code handling data aligned at natural CPU word\r
- * boundary. See crypto/rc4/rc4_enc.c for further details.\r
- */\r
-#undef RC4_CHUNK\r
-#endif\r
-#endif\r
-\r
-#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)\r
-/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a\r
- * %20 speed up (longs are 8 bytes, int's are 4). */\r
-#ifndef DES_LONG\r
-#define DES_LONG unsigned long\r
-#endif\r
-#endif\r
-\r
-#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)\r
-#define CONFIG_HEADER_BN_H\r
-#define BN_LLONG\r
-\r
-/* Should we define BN_DIV2W here? */\r
-\r
-/* Only one for the following should be defined */\r
-#undef SIXTY_FOUR_BIT_LONG\r
-#undef SIXTY_FOUR_BIT\r
-#define THIRTY_TWO_BIT\r
-#endif\r
-\r
-#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)\r
-#define CONFIG_HEADER_RC4_LOCL_H\r
-/* if this is defined data[i] is used instead of *data, this is a %20\r
- * speedup on x86 */\r
-#define RC4_INDEX\r
-#endif\r
-\r
-#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)\r
-#define CONFIG_HEADER_BF_LOCL_H\r
-#undef BF_PTR\r
-#endif /* HEADER_BF_LOCL_H */\r
-\r
-#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)\r
-#define CONFIG_HEADER_DES_LOCL_H\r
-#ifndef DES_DEFAULT_OPTIONS\r
-/* the following is tweaked from a config script, that is why it is a\r
- * protected undef/define */\r
-#ifndef DES_PTR\r
-#undef DES_PTR\r
-#endif\r
-\r
-/* This helps C compiler generate the correct code for multiple functional\r
- * units.  It reduces register dependancies at the expense of 2 more\r
- * registers */\r
-#ifndef DES_RISC1\r
-#undef DES_RISC1\r
-#endif\r
-\r
-#ifndef DES_RISC2\r
-#undef DES_RISC2\r
-#endif\r
-\r
-#if defined(DES_RISC1) && defined(DES_RISC2)\r
-YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!\r
-#endif\r
-\r
-/* Unroll the inner loop, this sometimes helps, sometimes hinders.\r
- * Very mucy CPU dependant */\r
-#ifndef DES_UNROLL\r
-#undef DES_UNROLL\r
-#endif\r
-\r
-/* These default values were supplied by\r
- * Peter Gutman <pgut001@cs.auckland.ac.nz>\r
- * They are only used if nothing else has been defined */\r
-#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)\r
-/* Special defines which change the way the code is built depending on the\r
-   CPU and OS.  For SGI machines you can use _MIPS_SZLONG (32 or 64) to find\r
-   even newer MIPS CPU's, but at the moment one size fits all for\r
-   optimization options.  Older Sparc's work better with only UNROLL, but\r
-   there's no way to tell at compile time what it is you're running on */\r
\r
-#if defined( sun )             /* Newer Sparc's */\r
-#  define DES_PTR\r
-#  define DES_RISC1\r
-#  define DES_UNROLL\r
-#elif defined( __ultrix )      /* Older MIPS */\r
-#  define DES_PTR\r
-#  define DES_RISC2\r
-#  define DES_UNROLL\r
-#elif defined( __osf1__ )      /* Alpha */\r
-#  define DES_PTR\r
-#  define DES_RISC2\r
-#elif defined ( _AIX )         /* RS6000 */\r
-  /* Unknown */\r
-#elif defined( __hpux )                /* HP-PA */\r
-  /* Unknown */\r
-#elif defined( __aux )         /* 68K */\r
-  /* Unknown */\r
-#elif defined( __dgux )                /* 88K (but P6 in latest boxes) */\r
-#  define DES_UNROLL\r
-#elif defined( __sgi )         /* Newer MIPS */\r
-#  define DES_PTR\r
-#  define DES_RISC2\r
-#  define DES_UNROLL\r
-#elif defined(i386) || defined(__i386__)       /* x86 boxes, should be gcc */\r
-#  define DES_PTR\r
-#  define DES_RISC1\r
-#  define DES_UNROLL\r
-#endif /* Systems-specific speed defines */\r
-#endif\r
-\r
-#endif /* DES_DEFAULT_OPTIONS */\r
-#endif /* HEADER_DES_LOCL_H */\r
+/* opensslconf.h */
+/* WARNING: Generated automatically from opensslconf.h.in by Configure. */
+
+/* OpenSSL was configured with the following options: */
+#ifndef OPENSSL_SYSNAME_WIN32
+# define OPENSSL_SYSNAME_WIN32
+#endif
+#ifndef OPENSSL_DOING_MAKEDEPEND
+
+
+#ifndef OPENSSL_NO_GMP
+# define OPENSSL_NO_GMP
+#endif
+#ifndef OPENSSL_NO_JPAKE
+# define OPENSSL_NO_JPAKE
+#endif
+#ifndef OPENSSL_NO_KRB5
+# define OPENSSL_NO_KRB5
+#endif
+#ifndef OPENSSL_NO_MD2
+# define OPENSSL_NO_MD2
+#endif
+#ifndef OPENSSL_NO_RC5
+# define OPENSSL_NO_RC5
+#endif
+#ifndef OPENSSL_NO_RFC3779
+# define OPENSSL_NO_RFC3779
+#endif
+#ifndef OPENSSL_NO_STORE
+# define OPENSSL_NO_STORE
+#endif
+
+#endif /* OPENSSL_DOING_MAKEDEPEND */
+
+#ifndef OPENSSL_THREADS
+# define OPENSSL_THREADS
+#endif
+#ifndef OPENSSL_NO_ASM
+# define OPENSSL_NO_ASM
+#endif
+
+/* The OPENSSL_NO_* macros are also defined as NO_* if the application
+   asks for it.  This is a transient feature that is provided for those
+   who haven't had the time to do the appropriate changes in their
+   applications.  */
+#ifdef OPENSSL_ALGORITHM_DEFINES
+# if defined(OPENSSL_NO_GMP) && !defined(NO_GMP)
+#  define NO_GMP
+# endif
+# if defined(OPENSSL_NO_JPAKE) && !defined(NO_JPAKE)
+#  define NO_JPAKE
+# endif
+# if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5)
+#  define NO_KRB5
+# endif
+# if defined(OPENSSL_NO_MD2) && !defined(NO_MD2)
+#  define NO_MD2
+# endif
+# if defined(OPENSSL_NO_RC5) && !defined(NO_RC5)
+#  define NO_RC5
+# endif
+# if defined(OPENSSL_NO_RFC3779) && !defined(NO_RFC3779)
+#  define NO_RFC3779
+# endif
+# if defined(OPENSSL_NO_STORE) && !defined(NO_STORE)
+#  define NO_STORE
+# endif
+#endif
+
+/* crypto/opensslconf.h.in */
+
+/* Generate 80386 code? */
+#undef I386_ONLY
+
+#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
+#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
+#define ENGINESDIR "/usr/local/ssl/lib/engines"
+#define OPENSSLDIR "/usr/local/ssl"
+#endif
+#endif
+
+#undef OPENSSL_UNISTD
+#define OPENSSL_UNISTD <unistd.h>
+
+#undef OPENSSL_EXPORT_VAR_AS_FUNCTION
+#define OPENSSL_EXPORT_VAR_AS_FUNCTION
+
+#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
+#define IDEA_INT unsigned int
+#endif
+
+#if defined(HEADER_MD2_H) && !defined(MD2_INT)
+#define MD2_INT unsigned int
+#endif
+
+#if defined(HEADER_RC2_H) && !defined(RC2_INT)
+/* I need to put in a mod for the alpha - eay */
+#define RC2_INT unsigned int
+#endif
+
+#if defined(HEADER_RC4_H)
+#if !defined(RC4_INT)
+/* using int types make the structure larger but make the code faster
+ * on most boxes I have tested - up to %20 faster. */
+/*
+ * I don't know what does "most" mean, but declaring "int" is a must on:
+ * - Intel P6 because partial register stalls are very expensive;
+ * - elder Alpha because it lacks byte load/store instructions;
+ */
+#define RC4_INT unsigned int
+#endif
+#if !defined(RC4_CHUNK)
+/*
+ * This enables code handling data aligned at natural CPU word
+ * boundary. See crypto/rc4/rc4_enc.c for further details.
+ */
+#undef RC4_CHUNK
+#endif
+#endif
+
+#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)
+/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
+ * %20 speed up (longs are 8 bytes, int's are 4). */
+#ifndef DES_LONG
+#define DES_LONG unsigned long
+#endif
+#endif
+
+#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
+#define CONFIG_HEADER_BN_H
+#define BN_LLONG
+
+/* Should we define BN_DIV2W here? */
+
+/* Only one for the following should be defined */
+#undef SIXTY_FOUR_BIT_LONG
+#undef SIXTY_FOUR_BIT
+#define THIRTY_TWO_BIT
+#endif
+
+#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
+#define CONFIG_HEADER_RC4_LOCL_H
+/* if this is defined data[i] is used instead of *data, this is a %20
+ * speedup on x86 */
+#define RC4_INDEX
+#endif
+
+#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
+#define CONFIG_HEADER_BF_LOCL_H
+#undef BF_PTR
+#endif /* HEADER_BF_LOCL_H */
+
+#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
+#define CONFIG_HEADER_DES_LOCL_H
+#ifndef DES_DEFAULT_OPTIONS
+/* the following is tweaked from a config script, that is why it is a
+ * protected undef/define */
+#ifndef DES_PTR
+#undef DES_PTR
+#endif
+
+/* This helps C compiler generate the correct code for multiple functional
+ * units.  It reduces register dependancies at the expense of 2 more
+ * registers */
+#ifndef DES_RISC1
+#undef DES_RISC1
+#endif
+
+#ifndef DES_RISC2
+#undef DES_RISC2
+#endif
+
+#if defined(DES_RISC1) && defined(DES_RISC2)
+YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
+#endif
+
+/* Unroll the inner loop, this sometimes helps, sometimes hinders.
+ * Very mucy CPU dependant */
+#ifndef DES_UNROLL
+#undef DES_UNROLL
+#endif
+
+/* These default values were supplied by
+ * Peter Gutman <pgut001@cs.auckland.ac.nz>
+ * They are only used if nothing else has been defined */
+#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
+/* Special defines which change the way the code is built depending on the
+   CPU and OS.  For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
+   even newer MIPS CPU's, but at the moment one size fits all for
+   optimization options.  Older Sparc's work better with only UNROLL, but
+   there's no way to tell at compile time what it is you're running on */
+#if defined( sun )             /* Newer Sparc's */
+#  define DES_PTR
+#  define DES_RISC1
+#  define DES_UNROLL
+#elif defined( __ultrix )      /* Older MIPS */
+#  define DES_PTR
+#  define DES_RISC2
+#  define DES_UNROLL
+#elif defined( __osf1__ )      /* Alpha */
+#  define DES_PTR
+#  define DES_RISC2
+#elif defined ( _AIX )         /* RS6000 */
+  /* Unknown */
+#elif defined( __hpux )                /* HP-PA */
+  /* Unknown */
+#elif defined( __aux )         /* 68K */
+  /* Unknown */
+#elif defined( __dgux )                /* 88K (but P6 in latest boxes) */
+#  define DES_UNROLL
+#elif defined( __sgi )         /* Newer MIPS */
+#  define DES_PTR
+#  define DES_RISC2
+#  define DES_UNROLL
+#elif defined(i386) || defined(__i386__)       /* x86 boxes, should be gcc */
+#  define DES_PTR
+#  define DES_RISC1
+#  define DES_UNROLL
+#endif /* Systems-specific speed defines */
+#endif
+
+#endif /* DES_DEFAULT_OPTIONS */
+#endif /* HEADER_DES_LOCL_H */
index 6808215c43b23a21f2c2641b204d5f0add27624d..b976b2a734514f5512409ceac7e01a1df1502fc4 100644 (file)
-Current information is in ReadMeWin32.txt.\r
-\r
-What follows is previous contents of that file.\r
-\r
-\r
-\r
-Markus Hoffrogge:\r
-\r
-Compilation for WIN32 is possible now again for version 1.6.10 - non\r
-CPP parts only.  Project files have been tested under VicualStudio\r
-6.0.  Build project all - this will build all other projects.  CPP\r
-code is not compiled and adopted right now.\r
-\r
-This release excludes the option to compile an "http.sys" version of\r
-an XML-RPC server. If you do wish to build in the http.sys server, set\r
-the MUST_BUILD_HTTP_SYS_SERVER to 1 in the transport_config_win32.h\r
-and/or the transport_config.h file.  Successful conpilation requires\r
-installation of the Microsoft Platform SDK for Windows XP SP2 (or\r
-later) to get the latest header and link libraries required to support\r
-this functionality.  After installation, be sure to properly register\r
-the directories as documented in the Platform SDK help file topic\r
-"Installing the Platform SDK with Visual Studio".  Download the\r
-Platform SDK from:\r
-http://www.microsoft.com/msdownload/platformsdk/sdkupdate/\r
-\r
-To create the three headers required for Win32 WinInet compilation,\r
-run the ConfigureWin32.bat found in the Windows directory.  If you\r
-wish to alter the transports that are built to include curl or libwww,\r
-adjust the preprocessor definitions at the top of the\r
-transport_config_win32.h and/or the transport_config.h files.  See the\r
-file UsingCURLinWin32.txt for more information on using the curl\r
-transport.\r
-\r
-To compile, open the xmlrpc.dsw file in Visual Studio 6 or greater.\r
-The project will convert and work fine in Visual Studio 2003 as well -\r
-other versions of Visual Studio were not tested.\r
-\r
-NOTE: If you get an error while opening or converting the project\r
-files, it is likely due to using WinRar or similar to decompress the\r
-distribution tarball.  You can use WinZip or another utility to\r
-correctly decompress the .tgz file.\r
-\r
-Suggested testing for evaluation of the library involves a few\r
-projects.  Here is a quick getting started guide:\r
-\r
-1) Set the Active Project to query_meerkat and build it in release or\r
-   debug modes.  The dependent projects will be built automatically.\r
-   In the project settings dialog, add the argument for what you wish\r
-   to query meerkat for - "Windows" is a good query.  Run the project.\r
-   This will query the meerkat server for articles related to windows\r
-   and output the results to the console.\r
-\r
-2) Set the Active Project to xmlrpc_sample_add_server and build it in\r
-   release or debug modes.  The dependent projects will be built\r
-   automatically.  In the project settings dialog, add the argument\r
-   for the port to 8080.  This will run the server sample which adds\r
-   two numbers and returns a result.  You should run this from a\r
-   command prompt instead of through Visual Studio so you may run the\r
-   sample client as well.\r
-\r
-3) Set the Active Project to xmlrpc_sample_add_sync_client or\r
-   xmlrpc_sample_add_async_client and build it in release or debug\r
-   modes.  The dependent projects will be built automatically.  This\r
-   will run the client sample which submits two numbers to be added to\r
-   the server application as described above and displays the result.\r
-   Note that the client example comes in the sync and async varieties.\r
-\r
-Steven Bone\r
-July 27, 2005\r
-sbone@pobox.com\r
-\r
-WIN32 CHANGES\r
-\r
-Changes from the 1.02 release for Win32:\r
-\r
-1) Option to easily disable the http.sys server for those who do not\r
-   need it or wish to download the Platform SDK.\r
-\r
-Changes from the 1.01 -> 1.02 release for Win32:\r
-\r
-1) Project files for gennmtab, xmlparse, and xmltok updated to include the\r
-   path to the xmlrpc_config.h file.\r
-\r
-2) Bugfix for WinInet authentication.\r
-\r
-3) Supports xmlrpc_xportparms, xmlrpc_wininet_xportparms added\r
-   *potential breaking change* - now by default we fail on invalid\r
-   SSL certs, use the xmlrpc_wininet_xportparms option to enable old\r
-   behavior.\r
-\r
-4) Added project file for xmlrpc_sample_auth_client\r
-\r
-5) Added project and src for a http.sys based xmlrpc-c server.  See comments\r
-   in the source files.  This supports Windows XP SP2 and Windows Server\r
-   2003 and allows other http.sys based applications to bind to the same\r
-   port.  In Server 2003, IIS uses http.sys and thus the XML-RPC server\r
-   can be run on the standard port 80 along with IIS.  The sample also\r
-   supports https and basic authentication.  It tested OK with\r
-   http://validator.xmlrpc.com/  Note that the Platform SDK headers and\r
-   link libraries for Windows XP SP2 or newer are required to compile\r
-   xmlrpc-c for this module.  If you are not using this server, it is\r
-   safe to exclude the xmlrpc_server_w32httpsys.c file from the xmlrpc\r
-   project and these dependencies will not be required.  You can get the\r
-   latest platform SDK at\r
-   http://www.microsoft.com/msdownload/platformsdk/sdkupdate/\r
-   Be sure after installation to choose the program to "register the PSDK\r
-   directories with Visual Studio" so the newer headers are found.\r
-\r
-6) Better support for libcurl.  Updated project files,\r
-   transport_config_win32.h, added documentation UsingCURLinWin32.txt.\r
-\r
-Changes from the 1.00 -> 1.01 release for Win32:\r
-\r
-1) Project files now reflect static linking for the expat XML library.\r
-\r
-2) Example projects were created/updated to keep them in sync with the\r
-   distribution.  The project files were moved into the Windows\r
-   directory\r
-\r
-3) Projects for the rpc and cpp tests were created.  The\r
-   xmlrpc_win32_config.h defines the directory for the test files relative\r
-   to the output directory\r
-\r
-4) Major refactoring of the Wininet Transport.\r
-\r
+Current information is in ReadMeWin32.txt.
+
+What follows is previous contents of that file.
+
+
+
+Markus Hoffrogge:
+
+Compilation for WIN32 is possible now again for version 1.6.10 - non
+CPP parts only.  Project files have been tested under VicualStudio
+6.0.  Build project all - this will build all other projects.  CPP
+code is not compiled and adopted right now.
+
+This release excludes the option to compile an "http.sys" version of
+an XML-RPC server. If you do wish to build in the http.sys server, set
+the MUST_BUILD_HTTP_SYS_SERVER to 1 in the transport_config_win32.h
+and/or the transport_config.h file.  Successful conpilation requires
+installation of the Microsoft Platform SDK for Windows XP SP2 (or
+later) to get the latest header and link libraries required to support
+this functionality.  After installation, be sure to properly register
+the directories as documented in the Platform SDK help file topic
+"Installing the Platform SDK with Visual Studio".  Download the
+Platform SDK from:
+http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
+
+To create the three headers required for Win32 WinInet compilation,
+run the ConfigureWin32.bat found in the Windows directory.  If you
+wish to alter the transports that are built to include curl or libwww,
+adjust the preprocessor definitions at the top of the
+transport_config_win32.h and/or the transport_config.h files.  See the
+file UsingCURLinWin32.txt for more information on using the curl
+transport.
+
+To compile, open the xmlrpc.dsw file in Visual Studio 6 or greater.
+The project will convert and work fine in Visual Studio 2003 as well -
+other versions of Visual Studio were not tested.
+
+NOTE: If you get an error while opening or converting the project
+files, it is likely due to using WinRar or similar to decompress the
+distribution tarball.  You can use WinZip or another utility to
+correctly decompress the .tgz file.
+
+Suggested testing for evaluation of the library involves a few
+projects.  Here is a quick getting started guide:
+
+1) Set the Active Project to query_meerkat and build it in release or
+   debug modes.  The dependent projects will be built automatically.
+   In the project settings dialog, add the argument for what you wish
+   to query meerkat for - "Windows" is a good query.  Run the project.
+   This will query the meerkat server for articles related to windows
+   and output the results to the console.
+
+2) Set the Active Project to xmlrpc_sample_add_server and build it in
+   release or debug modes.  The dependent projects will be built
+   automatically.  In the project settings dialog, add the argument
+   for the port to 8080.  This will run the server sample which adds
+   two numbers and returns a result.  You should run this from a
+   command prompt instead of through Visual Studio so you may run the
+   sample client as well.
+
+3) Set the Active Project to xmlrpc_sample_add_sync_client or
+   xmlrpc_sample_add_async_client and build it in release or debug
+   modes.  The dependent projects will be built automatically.  This
+   will run the client sample which submits two numbers to be added to
+   the server application as described above and displays the result.
+   Note that the client example comes in the sync and async varieties.
+
+Steven Bone
+July 27, 2005
+sbone@pobox.com
+
+WIN32 CHANGES
+
+Changes from the 1.02 release for Win32:
+
+1) Option to easily disable the http.sys server for those who do not
+   need it or wish to download the Platform SDK.
+
+Changes from the 1.01 -> 1.02 release for Win32:
+
+1) Project files for gennmtab, xmlparse, and xmltok updated to include the
+   path to the xmlrpc_config.h file.
+
+2) Bugfix for WinInet authentication.
+
+3) Supports xmlrpc_xportparms, xmlrpc_wininet_xportparms added
+   *potential breaking change* - now by default we fail on invalid
+   SSL certs, use the xmlrpc_wininet_xportparms option to enable old
+   behavior.
+
+4) Added project file for xmlrpc_sample_auth_client
+
+5) Added project and src for a http.sys based xmlrpc-c server.  See comments
+   in the source files.  This supports Windows XP SP2 and Windows Server
+   2003 and allows other http.sys based applications to bind to the same
+   port.  In Server 2003, IIS uses http.sys and thus the XML-RPC server
+   can be run on the standard port 80 along with IIS.  The sample also
+   supports https and basic authentication.  It tested OK with
+   http://validator.xmlrpc.com/  Note that the Platform SDK headers and
+   link libraries for Windows XP SP2 or newer are required to compile
+   xmlrpc-c for this module.  If you are not using this server, it is
+   safe to exclude the xmlrpc_server_w32httpsys.c file from the xmlrpc
+   project and these dependencies will not be required.  You can get the
+   latest platform SDK at
+   http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
+   Be sure after installation to choose the program to "register the PSDK
+   directories with Visual Studio" so the newer headers are found.
+
+6) Better support for libcurl.  Updated project files,
+   transport_config_win32.h, added documentation UsingCURLinWin32.txt.
+
+Changes from the 1.00 -> 1.01 release for Win32:
+
+1) Project files now reflect static linking for the expat XML library.
+
+2) Example projects were created/updated to keep them in sync with the
+   distribution.  The project files were moved into the Windows
+   directory
+
+3) Projects for the rpc and cpp tests were created.  The
+   xmlrpc_win32_config.h defines the directory for the test files relative
+   to the output directory
+
+4) Major refactoring of the Wininet Transport.
+
index 4ee1259f41a9246a4791af7c33a5a24155882965..4c1c47af6d6aa0f676d09f77bad3f13d603ee681 100644 (file)
-Background:\r
-\r
-Let\92s say you need to have a Xmlrpc-c client running as a service.\r
-In this situation you cannot use WinInet.  Details of the restriction\r
-can be found on the libcurl website or various Microsoft KB articles.\r
-The alternative is to use libcurl.  This document describes the steps\r
-required to use libcurl as your client XML transport mechanism.\r
-\r
-Overview:\r
-\r
-The default projects in Xmlrpc-c create standalone executables that do\r
-not require other DLL\92s (release mode).  While the case can be made\r
-for this behavior pro and con, it is beyond this document to justify\r
-it.  Therefore, we need to create static link libraries for libcurl\r
-that mimics this behavior.  Once the link libraries are created, we\r
-can then add them (plus the requisite curl headers) into the Xmlrpc-c\r
-project.  Finally, we enable the compilation of the curl transport\r
-file and tell Xmlrpc-c that we will be using curl.  Lastly, we build\r
-and test the project.\r
-\r
-Steps to use CURL with Win32 Xmlrpc-c:\r
-\r
-1. Download the CURL source.  In the \93include\94 folder of the\r
-CURL distribution, copy the curl directory to the \93lib\94\r
-directory of xmlrpc-c.  When you are done with this step, you should\r
-have a curl.h file located in the directory xmlrpc-c\lib\curl\.  The\r
-xmlrpc project looks in this relative path for the necessary headers.\r
-\r
-2. In the CURL distribution, lib directory, is a file called\r
-Makefile.vc6.  Edit this file.  The line starting with CCNODBG should\r
-be changed to:\r
-\r
-CCNODBG    = cl.exe /MT /O2 /DNDEBUG\r
-\r
-The /MT option links with the Multithreaded non-dll version of the c\r
-runtime.  If this change is not made, the project will not link, as\r
-this is the default setting for the Xmlrpc-c projects.\r
-\r
-3. Open a command prompt window and run the vcvars32.bat file in your\r
-Visual C++ distribution.  If you are using Studio 2002 or 2003, use\r
-the \93Visual Studio Command Prompt\94 from the Start menu to open\r
-the console.\r
-\r
-4. Compile release and debug mode libraries.  For the purposes of this\r
-tutorial, we are going to build only the curl library without ssl or\r
-zlib compression capability.  In the command prompt, navigate to the\r
-curl\lib directory and execute the following commands:\r
-\r
-nmake -f Makefile.vc6 CFG=debug RTLIBCFG=static\r
-nmake -f Makefile.vc6 CFG=release RTLIBCFG=static\r
-\r
-5. The above step should have generated two static link libraries in\r
-the curl\lib directory: libcurl.lib and libcurld.lib.  Copy these\r
-files into the root of the xmlrpc-c\lib\ directory.  This step ends\r
-our involvement with the actual CURL distribution.  The remainder of\r
-the steps are for Xmlrpc-c.\r
-\r
-6. Open the Xmlrpc-c Visual Studio workspace (Instructions for VC++ 6,\r
-other versions are slightly different).  In File View, expand the\r
-xmlrpc project.  Under "Source Files" there is an entry for\r
-xmlrpc_curl_transport.c This is not included in any build paths by\r
-default.  To enable it for compilation, right click the file to change\r
-the settings.  In the dropdown, select "All Configurations."  Pick the\r
-General tab and uncheck the "Exclude File From Build" setting.  Press\r
-OK to save your changes to the project.\r
-\r
-7.  In the "Header Files" section of the xmlrpc project is a file\r
-called "transport_config.h".  Edit this file to set the\r
-MUST_BUILD_CURL_CLIENT to 1, and if you wish to change the default\r
-transport to curl, change the XMLRPC_DEFAULT_TRANSPORT to "curl".\r
-\r
-8. Compile and test one or more of the sample client projects.\r
-\r
-USING MSVC8 - 2007/11/25\r
-========================\r
-\r
-This is for MSVC8, but most will apply to all version of Microsoft\r
-Visual Studio.\r
-\r
-Download the CURL source. Run the buildconf.bat to generate some\r
-additional files. This builds a 'dummy' hugehelp.c, but it can also\r
-be built using the src\mkhelp.pl Perl script. You may have to build\r
-you own VCPROJ file for CURL, if you want to use MSVC. It does\r
-provide a Makefile.vc6 as mentioned above.\r
-\r
-To build all the CURL library variations, use\r
-> nmake /nologo vc-all \r
-but note this will use the /MD[d] DLL runtime. Only by adding\r
-RTCFGLIB=static to each of the makefile commands will /MT[d] be\r
-used.\r
-\r
-Essentially, for building the static Debug or Release CURL libraries,\r
-it is all the sources in the curl\lib folder. Make sure you choose /MT\r
-and /MTd for the runtime, and build both using say the name libcurl.lib.\r
-\r
-When you have Debug\libcurl.lib and Release\libcurl.lib built, you\r
-are ready to build and link them with Xmlrpc-c.\r
-\r
-After running xmlrpc-c\Windows\configurewin32.bat, loading xmlrpc.dsw\r
-will convert all the projects to VCPROJ files. In the File View, in\r
-the xmlrpc project, in the properties of xmlrpc_curl_transport.c,\r
-change 'Exclude file from build' from 'yes' to 'no', for Debug\r
-and Release.\r
-\r
-In the 'Header Files' section, open the "transport_config.h" file,\r
-and change MUST_BUILD_CURL_CLIENT to 1, and the XMLRPC_DEFAULT_TRANSPORT\r
-to "curl", if desired.\r
-\r
-As usual, for each of the 'client' projects, and rpctest, in the properties,\r
-Linker section, you can add the library libcurl.lib on the Input tab, and\r
-the relative path to the library in the General tab to something like -\r
-..\..\curl\Debug and ..\..\curl\Release, or where ever you built or\r
-copied these static libraries too.\r
-\r
-Or you can adjust the Windows/curlink.h, to directly point to your\r
-respective Debug and Release static CURL libraries, either where you\r
-built them, or where you copied them too.\r
-\r
-Now, Xmlrpc-c should build using the CURL transport.\r
-\r
-Note, for the final linking, all RUNTIME libraries MUST be the SAME.\r
-A mixture of /MD and /MT will give big linkage problems. Any one project\r
-built with the alterate RUNTIME will show many items defined more than\r
-once. And of course, you can also NOT mix Debug with Release. That is\r
-/MDd with /MD, nor /MTd with /MT, or else there will be unresolved\r
-debug items.\r
-\r
-EOF\r
+Background:
+
+Let\92s say you need to have a Xmlrpc-c client running as a service.
+In this situation you cannot use WinInet.  Details of the restriction
+can be found on the libcurl website or various Microsoft KB articles.
+The alternative is to use libcurl.  This document describes the steps
+required to use libcurl as your client XML transport mechanism.
+
+Overview:
+
+The default projects in Xmlrpc-c create standalone executables that do
+not require other DLL\92s (release mode).  While the case can be made
+for this behavior pro and con, it is beyond this document to justify
+it.  Therefore, we need to create static link libraries for libcurl
+that mimics this behavior.  Once the link libraries are created, we
+can then add them (plus the requisite curl headers) into the Xmlrpc-c
+project.  Finally, we enable the compilation of the curl transport
+file and tell Xmlrpc-c that we will be using curl.  Lastly, we build
+and test the project.
+
+Steps to use CURL with Win32 Xmlrpc-c:
+
+1. Download the CURL source.  In the \93include\94 folder of the
+CURL distribution, copy the curl directory to the \93lib\94
+directory of xmlrpc-c.  When you are done with this step, you should
+have a curl.h file located in the directory xmlrpc-c\lib\curl\.  The
+xmlrpc project looks in this relative path for the necessary headers.
+
+2. In the CURL distribution, lib directory, is a file called
+Makefile.vc6.  Edit this file.  The line starting with CCNODBG should
+be changed to:
+
+CCNODBG    = cl.exe /MT /O2 /DNDEBUG
+
+The /MT option links with the Multithreaded non-dll version of the c
+runtime.  If this change is not made, the project will not link, as
+this is the default setting for the Xmlrpc-c projects.
+
+3. Open a command prompt window and run the vcvars32.bat file in your
+Visual C++ distribution.  If you are using Studio 2002 or 2003, use
+the \93Visual Studio Command Prompt\94 from the Start menu to open
+the console.
+
+4. Compile release and debug mode libraries.  For the purposes of this
+tutorial, we are going to build only the curl library without ssl or
+zlib compression capability.  In the command prompt, navigate to the
+curl\lib directory and execute the following commands:
+
+nmake -f Makefile.vc6 CFG=debug RTLIBCFG=static
+nmake -f Makefile.vc6 CFG=release RTLIBCFG=static
+
+5. The above step should have generated two static link libraries in
+the curl\lib directory: libcurl.lib and libcurld.lib.  Copy these
+files into the root of the xmlrpc-c\lib\ directory.  This step ends
+our involvement with the actual CURL distribution.  The remainder of
+the steps are for Xmlrpc-c.
+
+6. Open the Xmlrpc-c Visual Studio workspace (Instructions for VC++ 6,
+other versions are slightly different).  In File View, expand the
+xmlrpc project.  Under "Source Files" there is an entry for
+xmlrpc_curl_transport.c This is not included in any build paths by
+default.  To enable it for compilation, right click the file to change
+the settings.  In the dropdown, select "All Configurations."  Pick the
+General tab and uncheck the "Exclude File From Build" setting.  Press
+OK to save your changes to the project.
+
+7.  In the "Header Files" section of the xmlrpc project is a file
+called "transport_config.h".  Edit this file to set the
+MUST_BUILD_CURL_CLIENT to 1, and if you wish to change the default
+transport to curl, change the XMLRPC_DEFAULT_TRANSPORT to "curl".
+
+8. Compile and test one or more of the sample client projects.
+
+USING MSVC8 - 2007/11/25
+========================
+
+This is for MSVC8, but most will apply to all version of Microsoft
+Visual Studio.
+
+Download the CURL source. Run the buildconf.bat to generate some
+additional files. This builds a 'dummy' hugehelp.c, but it can also
+be built using the src\mkhelp.pl Perl script. You may have to build
+you own VCPROJ file for CURL, if you want to use MSVC. It does
+provide a Makefile.vc6 as mentioned above.
+
+To build all the CURL library variations, use
+> nmake /nologo vc-all 
+but note this will use the /MD[d] DLL runtime. Only by adding
+RTCFGLIB=static to each of the makefile commands will /MT[d] be
+used.
+
+Essentially, for building the static Debug or Release CURL libraries,
+it is all the sources in the curl\lib folder. Make sure you choose /MT
+and /MTd for the runtime, and build both using say the name libcurl.lib.
+
+When you have Debug\libcurl.lib and Release\libcurl.lib built, you
+are ready to build and link them with Xmlrpc-c.
+
+After running xmlrpc-c\Windows\configurewin32.bat, loading xmlrpc.dsw
+will convert all the projects to VCPROJ files. In the File View, in
+the xmlrpc project, in the properties of xmlrpc_curl_transport.c,
+change 'Exclude file from build' from 'yes' to 'no', for Debug
+and Release.
+
+In the 'Header Files' section, open the "transport_config.h" file,
+and change MUST_BUILD_CURL_CLIENT to 1, and the XMLRPC_DEFAULT_TRANSPORT
+to "curl", if desired.
+
+As usual, for each of the 'client' projects, and rpctest, in the properties,
+Linker section, you can add the library libcurl.lib on the Input tab, and
+the relative path to the library in the General tab to something like -
+..\..\curl\Debug and ..\..\curl\Release, or where ever you built or
+copied these static libraries too.
+
+Or you can adjust the Windows/curlink.h, to directly point to your
+respective Debug and Release static CURL libraries, either where you
+built them, or where you copied them too.
+
+Now, Xmlrpc-c should build using the CURL transport.
+
+Note, for the final linking, all RUNTIME libraries MUST be the SAME.
+A mixture of /MD and /MT will give big linkage problems. Any one project
+built with the alterate RUNTIME will show many items defined more than
+once. And of course, you can also NOT mix Debug with Release. That is
+/MDd with /MD, nor /MTd with /MT, or else there will be unresolved
+debug items.
+
+EOF
index 515f73d1d6c3f2f77ca80fcf971d8bc0d9e3e344..25e93ef811db11dd863785cff97d4676d8e1e810 100644 (file)
@@ -1,51 +1,51 @@
-\r
-Using xmlrpc_cpp_proxy.dsp\r
-\r
-While not included in the main xmlrpc.dsw file, this\r
-xmlrpc_cpp_proxy.dsp, if added as a project to the xmlrpc solution,\r
-will build bin\xmlrpc_cpp_proxy.exe and xmlrpc_cpp_proxyD.exe, for\r
-testing using the default WinINET transport.\r
-\r
-After you have loaded the xmlrpc_cpp_proxy.dsp, which adds an \r
-xmlrpc_cpp_proxy project, it is necessary to ADD a dependance on\r
-the xmlrpc library, to complete the link.\r
-\r
-To do this in say MSVC8, select the xmlrpc_cpp_proxy project, and right\r
-mouse click, and in the context menu, select 'Project Dependancies...'.\r
-And in the Project Dependancies dialog, check the xmlrpc proejct,\r
-then [Ok] ...\r
-\r
-To test your xmlrpc_cpp_proxy[D].exe -\r
-\r
-\r
-1. In a console start the server, like -\r
-\r
-bin/xmlrpc_sample_add_serverD 8080\r
-\r
-Note, since this server opens a socket, you may have to enable it on some\r
-anti-virus software that detects the socket being established, and\r
-'Unblock' it in the Windows Security Alert system dialog that appears.\r
-\r
-You can later remove this program from the Firewall exceptions, through\r
-Control Panel -> Windows Firewall, selecting the 'Exceptions' tab, where\r
-you can also disable this 'blocking' notification, but not recommended.\r
-\r
-The server should start, and report -\r
-Running XML-RPC server...\r
-\r
-\r
-2. In another console run the cpp proxy client, with say -\r
-\r
-bin>xmlrpc_cpp_proxyD http://localhost:8080/RPC2 null null\r
-\r
-The client should connect to the server, and output a 'null' header,\r
-and implementation file. If this functions, for a bigger example, try -\r
-\r
-bin>xmlrpc_cpp_proxyD http://localhost:8080/RPC2 system systemProxy\r
-\r
-and you should see a better example of a class header, and the \r
-implementation code ...\r
-\r
-20 December, 2007\r
-\r
-EOF\r
+
+Using xmlrpc_cpp_proxy.dsp
+
+While not included in the main xmlrpc.dsw file, this
+xmlrpc_cpp_proxy.dsp, if added as a project to the xmlrpc solution,
+will build bin\xmlrpc_cpp_proxy.exe and xmlrpc_cpp_proxyD.exe, for
+testing using the default WinINET transport.
+
+After you have loaded the xmlrpc_cpp_proxy.dsp, which adds an 
+xmlrpc_cpp_proxy project, it is necessary to ADD a dependance on
+the xmlrpc library, to complete the link.
+
+To do this in say MSVC8, select the xmlrpc_cpp_proxy project, and right
+mouse click, and in the context menu, select 'Project Dependancies...'.
+And in the Project Dependancies dialog, check the xmlrpc proejct,
+then [Ok] ...
+
+To test your xmlrpc_cpp_proxy[D].exe -
+
+
+1. In a console start the server, like -
+
+bin/xmlrpc_sample_add_serverD 8080
+
+Note, since this server opens a socket, you may have to enable it on some
+anti-virus software that detects the socket being established, and
+'Unblock' it in the Windows Security Alert system dialog that appears.
+
+You can later remove this program from the Firewall exceptions, through
+Control Panel -> Windows Firewall, selecting the 'Exceptions' tab, where
+you can also disable this 'blocking' notification, but not recommended.
+
+The server should start, and report -
+Running XML-RPC server...
+
+
+2. In another console run the cpp proxy client, with say -
+
+bin>xmlrpc_cpp_proxyD http://localhost:8080/RPC2 null null
+
+The client should connect to the server, and output a 'null' header,
+and implementation file. If this functions, for a bigger example, try -
+
+bin>xmlrpc_cpp_proxyD http://localhost:8080/RPC2 system systemProxy
+
+and you should see a better example of a class header, and the 
+implementation code ...
+
+20 December, 2007
+
+EOF
index 00db6a0a0e1d67061a804ab0578b7b03fd879824..4a287e542dc125a17327858c0ac2163c16d0e8ee 100644 (file)
@@ -1,11 +1,11 @@
-POST /cgi-bin/sample-cgi.cgi 1.0\r
-Host: localhost\r
-Content-Type: text/xml\r
-Content-Length: 141\r
-\r
-<?xml version="1.0" encoding="UTF-8"?>\r
-<methodCall>\r
-  <methodName>system.listMethods</methodName>\r
-  <params>\r
-  </params>\r
-</methodCall>\r
+POST /cgi-bin/sample-cgi.cgi 1.0
+Host: localhost
+Content-Type: text/xml
+Content-Length: 141
+
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+  <methodName>system.listMethods</methodName>
+  <params>
+  </params>
+</methodCall>
index a7298108dfd24d7893723d54a195771f86550048..4d73d07018a7dda05e63f8461a210d52b0c9244f 100644 (file)
@@ -1,21 +1,21 @@
-ExprEval - Expression Evaluation Library\r
-Version 2.0\r
-\r
-Copyright (C) 2004 Brian Allen Vanderburg II\r
-\r
-This software is provided 'as-is', without any express or implied\r
-warranty.  In no event will the authors be held liable for any damages\r
-arising from the use of this software.\r
-\r
-Permission is granted to anyone to use this software for any purpose,\r
-including commercial applications, and to alter it and redistribute it\r
-freely, subject to the following restrictions:\r
-\r
-1. The origin of this software must not be misrepresented; you must not\r
-   claim that you wrote the original software. If you use this software\r
-   in a product, an acknowledgment in the product documentation would be\r
-   appreciated but is not required.\r
-2. Altered source versions must be plainly marked as such, and must not be\r
-   misrepresented as being the original software.\r
-3. This notice may not be removed or altered from any source distribution.\r
-\r
+ExprEval - Expression Evaluation Library
+Version 2.0
+
+Copyright (C) 2004 Brian Allen Vanderburg II
+
+This software is provided 'as-is', without any express or implied
+warranty.  In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+   claim that you wrote the original software. If you use this software
+   in a product, an acknowledgment in the product documentation would be
+   appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be
+   misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+
index 8aefb3574680df8ec4a2b40515f6d343e0d004aa..50047e7643e5c3739ce97e6669e59bb59eeaa324 100644 (file)
-ExprEval - A C/C++ based expression evaluation library\r
-Written by: Brian Allen Vanderburg II\r
-Licensed under the ExprEval License\r
-------------------------------------------------------\r
-ExprEval is a mostly a C based expression evaluation\r
-library.  The only C++ part is the C++ Wrapper which\r
-encapsulates the complexity of the library usage.\r
-\r
-ExprEval supports the parsing of multiple expressions\r
-in a single expression string.  Each sub-expression\r
-must end with a semicolon.  It also supports the use\r
-of variables, constants, and functions.  Functions\r
-can take multiple arguments.  These arguments can\r
-also be expressions.\r
-\r
-ExprEval is very fast.  It first parses the expression\r
-string into a tree of actions to take.  After it has\r
-been parsed, an expression can be evaluated many times\r
-over an over.\r
-\r
-Functions, variables, and constants are stored in\r
-their own seperate lists.  This makes is where the\r
-lists can be shared among multiple expression objects.\r
-A function list can add all the functions needed, and\r
-then be added to each expression object, instead of\r
-added each needed function to each object.  The same\r
-goes for constant lists.  Variable lists make it where\r
-one expression can depend on a variable set in another.\r
-\r
-\r
-Saturday, July 1, 2006\r
-----------------------\r
-Version 2.6\r
-\r
-* Added a new value list function 'exprValListGetNext' that can be used to\r
-  enumerate the items in a value list.  Any of the items not needed (name,\r
-  value, or address) can be NULL.  For example:\r
-  \r
-  char *name;\r
-  EXPRTYPE val;\r
-  void *cookie;\r
-  \r
-  cookie = exprValListGetNext(vlist, &name, &value, NULL, NULL);\r
-  while(cookie)\r
-    {\r
-    /* Do something with name and value */\r
-    cookie = exprValListGetNext(vlist, &name, &value, NULL, cookie);\r
-    }\r
-    \r
-  You must make sure not to actually edit the returned name, because it is a\r
-  pointer into the value list to the name.  This can also be used to have one\r
-  value list store globals.  Global variables can be added to a value list, then\r
-  additional lists can be created, and before any variables are added\r
-  or the expression is parsed, the global list can be enumerated for name and\r
-  address and the exprValListAddAddress can be used to add them.  This way,\r
-  expressions can have their own private list, but some variables may be shared\r
-  on each expression through the global list.  This is useful especially if the\r
-  globals are not known at compile time, but can be adjusted by the user.\r
-  For example:\r
-  \r
-  exprValList *globals;\r
-  exprValList *v1;\r
-  exprValList *v2;\r
-  char *name;\r
-  EXPRTYPE *addr;\r
-  void *cookie;\r
-  \r
-  exprValListCreate(&globals);\r
-  /* Add variables to the list, perhaps read from a user file or something */\r
-  \r
-  exprValListCreate(&v1);\r
-  cookie = exprValListGetNext(globals, &name, NULL, &addr, NULL);\r
-  while(cookie)\r
-    {\r
-    exprValListAddAddress(v1, name, addr);\r
-    cookie = exprValListGetNext(globals, &name, NULL, &addr, cookie);\r
-    }\r
-  \r
-\r
-Friday, June 30, 2006\r
----------------------\r
-Version 2.5\r
-\r
-* Added a new value list function 'exprValListAddAddress'.  This function adds\r
-  a named value to the list, but uses the addresss of a stack variable.  The\r
-  stack variable is then used to set/get the value instead of the internal list\r
-  value.  You must ensure that the stack variable exists as long as it is used\r
-  by the expression.  This can permit, for example, a value name to be shared\r
-  with two different value lists like such:\r
-  \r
-  EXPRTYPE global_value;\r
-  exprValListAddAddress(vlist, "global", &global_value);\r
-  exprValListAddAddress(vlist2, "global", &global_value);\r
-  \r
-  Like this, the value can be directly accessed by the application, and each\r
-  value list will share it.  This can also be used to replace code from this:\r
-  \r
-  EXPRTYPE *a;\r
-  exprValListAdd(vlist, "var", 0.0);\r
-  exprValListGetAddress(vlist, "var", &a);\r
-  \r
-  To look like this:\r
-  \r
-  EXPRTYPE a;\r
-  exprValListAddAddress(vlist, "var", &a);\r
-* Added a value list function exprValListSet to set the value of a variable\r
-  (using the slow search method).  This is because the add functions now return\r
-  and error if the item (function/value) already exists instead of setting the\r
-  value of the item.  You can still use the fast direct access method.\r
-* Changed internal lists for function and value lists from binary trees to\r
-  linked lists.\r
-  \r
-  \r
-\r
-\r
-Thursday, May 4, 2006\r
----------------------\r
-Version 2.0\r
-\r
-* All internal functions are evaluated directly in the exprEvalNode call.\r
-  This gives some speed increase.\r
-* Removed parameter and reference count macros as well as functin creation\r
-  macro.  Parameter and reference count information can be set when adding\r
-  a function solver.\r
-* Removed exprMsgFuncType, since it is unused by the library.\r
-* Changed much of the internal names from one-letter variable names to\r
-  more meaningful names.\r
-\r
-Thursday, December 1, 2005\r
---------------------------\r
-Version 1.8\r
-\r
-* Added support for the ^ operator to raise to a power.\r
-  The pow function can still be used.\r
-* Moved basic math code (add,subtract,multiply,divide,negate,exponent)\r
-  and multiple expression support from function solvers to the exprEvalNode\r
-  function.\r
-\r
-Tuesday, November 22, 2005\r
---------------------------\r
-I still haven't been keeping up with history much.\r
-\r
-* Removed < and > as comments.  Instead use # as a \r
-  comment to the end of the line\r
-* Added function exprGetErrorPosition to get start and\r
-  end position of parse error.\r
-\r
-Monday, May 3, 2004:  Version 1.0\r
----------------------------------\r
-This is a pretty bad time to start the history part since\r
-ExprEval is pretty much up and running and very operational.\r
-\r
-* Added macro EXPR_MAJORVERSION\r
-* Added macro EXPR_MINORVERSION\r
-* Added function exprGetVersion\r
-* Added macro to make declaring functions easy:\r
-  EXPR_FUNCTIONSOLVER(func_name)\r
-* Added support for passing variable references to functions\r
-  with the ampersand.  Example: minmax(1,2,3,&min,&max)\r
-* Added macros for reference support:\r
-  EXPR_REQUIREREFCOUNT\r
-  EXPR_REQUIREREFCOUNTMIN\r
-  EXPR_REQUIREREFCOUNTMAX\r
-  EXPR_REQUIREREFCOUNTRANGE\r
-* Added feature to disable assigning to a variable with the\r
-  same name as a constant.\r
-* Added feature to enable applications to change the value of\r
-  a constant while the expression can not.  You must add\r
-  any constants to the constant list BEFORE you parse the\r
-  expression.\r
+ExprEval - A C/C++ based expression evaluation library
+Written by: Brian Allen Vanderburg II
+Licensed under the ExprEval License
+------------------------------------------------------
+ExprEval is a mostly a C based expression evaluation
+library.  The only C++ part is the C++ Wrapper which
+encapsulates the complexity of the library usage.
+
+ExprEval supports the parsing of multiple expressions
+in a single expression string.  Each sub-expression
+must end with a semicolon.  It also supports the use
+of variables, constants, and functions.  Functions
+can take multiple arguments.  These arguments can
+also be expressions.
+
+ExprEval is very fast.  It first parses the expression
+string into a tree of actions to take.  After it has
+been parsed, an expression can be evaluated many times
+over an over.
+
+Functions, variables, and constants are stored in
+their own seperate lists.  This makes is where the
+lists can be shared among multiple expression objects.
+A function list can add all the functions needed, and
+then be added to each expression object, instead of
+added each needed function to each object.  The same
+goes for constant lists.  Variable lists make it where
+one expression can depend on a variable set in another.
+
+
+Saturday, July 1, 2006
+----------------------
+Version 2.6
+
+* Added a new value list function 'exprValListGetNext' that can be used to
+  enumerate the items in a value list.  Any of the items not needed (name,
+  value, or address) can be NULL.  For example:
+  
+  char *name;
+  EXPRTYPE val;
+  void *cookie;
+  
+  cookie = exprValListGetNext(vlist, &name, &value, NULL, NULL);
+  while(cookie)
+    {
+    /* Do something with name and value */
+    cookie = exprValListGetNext(vlist, &name, &value, NULL, cookie);
+    }
+    
+  You must make sure not to actually edit the returned name, because it is a
+  pointer into the value list to the name.  This can also be used to have one
+  value list store globals.  Global variables can be added to a value list, then
+  additional lists can be created, and before any variables are added
+  or the expression is parsed, the global list can be enumerated for name and
+  address and the exprValListAddAddress can be used to add them.  This way,
+  expressions can have their own private list, but some variables may be shared
+  on each expression through the global list.  This is useful especially if the
+  globals are not known at compile time, but can be adjusted by the user.
+  For example:
+  
+  exprValList *globals;
+  exprValList *v1;
+  exprValList *v2;
+  char *name;
+  EXPRTYPE *addr;
+  void *cookie;
+  
+  exprValListCreate(&globals);
+  /* Add variables to the list, perhaps read from a user file or something */
+  
+  exprValListCreate(&v1);
+  cookie = exprValListGetNext(globals, &name, NULL, &addr, NULL);
+  while(cookie)
+    {
+    exprValListAddAddress(v1, name, addr);
+    cookie = exprValListGetNext(globals, &name, NULL, &addr, cookie);
+    }
+  
+
+Friday, June 30, 2006
+---------------------
+Version 2.5
+
+* Added a new value list function 'exprValListAddAddress'.  This function adds
+  a named value to the list, but uses the addresss of a stack variable.  The
+  stack variable is then used to set/get the value instead of the internal list
+  value.  You must ensure that the stack variable exists as long as it is used
+  by the expression.  This can permit, for example, a value name to be shared
+  with two different value lists like such:
+  
+  EXPRTYPE global_value;
+  exprValListAddAddress(vlist, "global", &global_value);
+  exprValListAddAddress(vlist2, "global", &global_value);
+  
+  Like this, the value can be directly accessed by the application, and each
+  value list will share it.  This can also be used to replace code from this:
+  
+  EXPRTYPE *a;
+  exprValListAdd(vlist, "var", 0.0);
+  exprValListGetAddress(vlist, "var", &a);
+  
+  To look like this:
+  
+  EXPRTYPE a;
+  exprValListAddAddress(vlist, "var", &a);
+* Added a value list function exprValListSet to set the value of a variable
+  (using the slow search method).  This is because the add functions now return
+  and error if the item (function/value) already exists instead of setting the
+  value of the item.  You can still use the fast direct access method.
+* Changed internal lists for function and value lists from binary trees to
+  linked lists.
+  
+  
+
+
+Thursday, May 4, 2006
+---------------------
+Version 2.0
+
+* All internal functions are evaluated directly in the exprEvalNode call.
+  This gives some speed increase.
+* Removed parameter and reference count macros as well as functin creation
+  macro.  Parameter and reference count information can be set when adding
+  a function solver.
+* Removed exprMsgFuncType, since it is unused by the library.
+* Changed much of the internal names from one-letter variable names to
+  more meaningful names.
+
+Thursday, December 1, 2005
+--------------------------
+Version 1.8
+
+* Added support for the ^ operator to raise to a power.
+  The pow function can still be used.
+* Moved basic math code (add,subtract,multiply,divide,negate,exponent)
+  and multiple expression support from function solvers to the exprEvalNode
+  function.
+
+Tuesday, November 22, 2005
+--------------------------
+I still haven't been keeping up with history much.
+
+* Removed < and > as comments.  Instead use # as a 
+  comment to the end of the line
+* Added function exprGetErrorPosition to get start and
+  end position of parse error.
+
+Monday, May 3, 2004:  Version 1.0
+---------------------------------
+This is a pretty bad time to start the history part since
+ExprEval is pretty much up and running and very operational.
+
+* Added macro EXPR_MAJORVERSION
+* Added macro EXPR_MINORVERSION
+* Added function exprGetVersion
+* Added macro to make declaring functions easy:
+  EXPR_FUNCTIONSOLVER(func_name)
+* Added support for passing variable references to functions
+  with the ampersand.  Example: minmax(1,2,3,&min,&max)
+* Added macros for reference support:
+  EXPR_REQUIREREFCOUNT
+  EXPR_REQUIREREFCOUNTMIN
+  EXPR_REQUIREREFCOUNTMAX
+  EXPR_REQUIREREFCOUNTRANGE
+* Added feature to disable assigning to a variable with the
+  same name as a constant.
+* Added feature to enable applications to change the value of
+  a constant while the expression can not.  You must add
+  any constants to the constant list BEFORE you parse the
+  expression.